deleteArticle -> Autorisierungsprüfung
This commit is contained in:
@@ -20,8 +20,7 @@ interface ArticleManagerDAO
|
||||
* @param $category string Kategorie des Beitrages
|
||||
* @param $tags string optionale Schlagworte für eine bessere Suche
|
||||
*
|
||||
* Mögliche Exceptions:
|
||||
* TODO: Exceptions implementieren.
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function addArticle($title, $content, $author, $category, $tags);
|
||||
|
||||
@@ -37,34 +36,33 @@ interface ArticleManagerDAO
|
||||
* @throws InternalServerErrorException
|
||||
* @throws NotFoundException
|
||||
* @throws UnauthorizedAccessException
|
||||
* /
|
||||
*/
|
||||
public function updateArticle($id, $article, $author);
|
||||
|
||||
/**
|
||||
* Löscht einen Beitrag aus übergebener ID.
|
||||
* Löscht einen Beitrag aus übergebener ID und dem Nutzer, der die Löschung ausführt.
|
||||
* @param $id
|
||||
* @param $author
|
||||
* @return void
|
||||
*
|
||||
* TODO: Exceptions implementieren.
|
||||
* @throws InternalServerErrorException
|
||||
* @throws NotFoundException
|
||||
* @throws UnauthorizedAccessException
|
||||
*/
|
||||
public function deleteArticle($id);
|
||||
public function deleteArticle($id, $author);
|
||||
|
||||
/**
|
||||
* Beitrag aufrufen.
|
||||
* $id ID des Beitrags
|
||||
*
|
||||
* @return Article
|
||||
* Mögliche Exceptions:
|
||||
* TODO: Exceptions implementieren.
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function getArticle($id);
|
||||
|
||||
/**
|
||||
* Alle Beiträge aufrufen.
|
||||
*
|
||||
* Mögliche Exceptions:
|
||||
* TODO: Exceptions implementieren.
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function getAllArticles();
|
||||
|
||||
@@ -72,7 +70,7 @@ interface ArticleManagerDAO
|
||||
* Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus.
|
||||
* @param $author
|
||||
* @return Article[]
|
||||
* TODO: Exceptions implementieren.
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function getArticlesByAuthor($author);
|
||||
|
||||
@@ -89,6 +87,7 @@ interface ArticleManagerDAO
|
||||
* Gibt alle Beiträge einer gegebenen Kategorie aus.
|
||||
* @param $category
|
||||
* @return mixed
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function getArticlesByCategory($category);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
public function updateArticle($id, $article, $author)
|
||||
{
|
||||
if (empty($article)) {
|
||||
throw new InternalServerErrorException("internal_error");
|
||||
throw new NotFoundException("not_found_article");
|
||||
}
|
||||
|
||||
// Berechtigungsprüfung:
|
||||
@@ -102,8 +102,18 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteArticle($id)
|
||||
public function deleteArticle($id, $author)
|
||||
{
|
||||
$article = getArticle($id);
|
||||
if (empty($article)) {
|
||||
throw new NotFoundException("not_found_article");
|
||||
}
|
||||
|
||||
// Berechtigungsprüfung:
|
||||
if ($article->getAuthor() !== $author) {
|
||||
throw new UnauthorizedAccessException("unauthorized_access");
|
||||
}
|
||||
|
||||
$articles = $this->getAllArticles();
|
||||
$articleFound = false;
|
||||
|
||||
@@ -198,7 +208,7 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
}
|
||||
}
|
||||
|
||||
return $filteredArticles;
|
||||
return $filteredArticles;
|
||||
}
|
||||
|
||||
public function getArticlesByCategory($category)
|
||||
|
||||
Reference in New Issue
Block a user