deleteArticle -> Autorisierungsprüfung

This commit is contained in:
2026-06-05 11:27:43 +02:00
parent 11da418f60
commit d42dff1165
3 changed files with 25 additions and 7 deletions
+3 -3
View File
@@ -40,15 +40,15 @@ interface ArticleManagerDAO
public function updateArticle($id, $article, $author);
/**
* Löscht einen Beitrag aus übergebener ID.
* TODO: sollte auch die Autorisierung prüfen...
* Löscht einen Beitrag aus übergebener ID und dem Nutzer, der die Löschung ausführt.
* @param $id
* @param $author
* @return void
* @throws InternalServerErrorException
* @throws NotFoundException
* @throws UnauthorizedAccessException
*/
public function deleteArticle($id);
public function deleteArticle($id, $author);
/**
* Beitrag aufrufen.
+11 -2
View File
@@ -147,9 +147,18 @@ class DatabaseArticleManager implements ArticleManagerDAO {
}
}
public function deleteArticle($id)
public function deleteArticle($id, $author)
{
// TODO: Sollte auch die Autorisierung prüfen...
$article = getArticle($id);
if (empty($article)) {
throw new NotFoundException("not_found_article");
}
// Berechtigungsprüfung:
if ($article->getAuthor() !== $author) {
throw new UnauthorizedAccessException("unauthorized_access");
}
try {
$db = $this->getConnection();
$sql = "DELETE FROM articles WHERE id = :id;";
+11 -2
View File
@@ -102,9 +102,18 @@ class LocalArticleManager implements ArticleManagerDAO {
}
}
public function deleteArticle($id)
public function deleteArticle($id, $author)
{
// TODO: Sollte auch die Autorisierung prüfen...
$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;