deleteArticle -> Autorisierungsprüfung

This commit is contained in:
2026-06-05 10:31:09 +02:00
parent 793d9632b2
commit 4cd0383322
2 changed files with 27 additions and 18 deletions
+11 -12
View File
@@ -20,8 +20,7 @@ interface ArticleManagerDAO
* @param $category string Kategorie des Beitrages * @param $category string Kategorie des Beitrages
* @param $tags string optionale Schlagworte für eine bessere Suche * @param $tags string optionale Schlagworte für eine bessere Suche
* *
* Mögliche Exceptions: * @throws InternalServerErrorException
* TODO: Exceptions implementieren.
*/ */
public function addArticle($title, $content, $author, $category, $tags); public function addArticle($title, $content, $author, $category, $tags);
@@ -37,34 +36,33 @@ interface ArticleManagerDAO
* @throws InternalServerErrorException * @throws InternalServerErrorException
* @throws NotFoundException * @throws NotFoundException
* @throws UnauthorizedAccessException * @throws UnauthorizedAccessException
* /
*/ */
public function updateArticle($id, $article, $author); 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 $id
* @param $author
* @return void * @return void
* * @throws InternalServerErrorException
* TODO: Exceptions implementieren. * @throws NotFoundException
* @throws UnauthorizedAccessException
*/ */
public function deleteArticle($id); public function deleteArticle($id, $author);
/** /**
* Beitrag aufrufen. * Beitrag aufrufen.
* $id ID des Beitrags * $id ID des Beitrags
* *
* @return Article * @return Article
* Mögliche Exceptions: * @throws InternalServerErrorException
* TODO: Exceptions implementieren.
*/ */
public function getArticle($id); public function getArticle($id);
/** /**
* Alle Beiträge aufrufen. * Alle Beiträge aufrufen.
* *
* Mögliche Exceptions: * @throws InternalServerErrorException
* TODO: Exceptions implementieren.
*/ */
public function getAllArticles(); public function getAllArticles();
@@ -72,7 +70,7 @@ interface ArticleManagerDAO
* Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus. * Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus.
* @param $author * @param $author
* @return Article[] * @return Article[]
* TODO: Exceptions implementieren. * @throws InternalServerErrorException
*/ */
public function getArticlesByAuthor($author); public function getArticlesByAuthor($author);
@@ -89,6 +87,7 @@ interface ArticleManagerDAO
* Gibt alle Beiträge einer gegebenen Kategorie aus. * Gibt alle Beiträge einer gegebenen Kategorie aus.
* @param $category * @param $category
* @return mixed * @return mixed
* @throws InternalServerErrorException
*/ */
public function getArticlesByCategory($category); public function getArticlesByCategory($category);
+12 -2
View File
@@ -66,7 +66,7 @@ class LocalArticleManager implements ArticleManagerDAO {
public function updateArticle($id, $article, $author) public function updateArticle($id, $article, $author)
{ {
if (empty($article)) { if (empty($article)) {
throw new InternalServerErrorException("internal_error"); throw new NotFoundException("not_found_article");
} }
// Berechtigungsprüfung: // 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(); $articles = $this->getAllArticles();
$articleFound = false; $articleFound = false;