From: joshuaruesweg Date: Mon, 13 Sep 2021 08:35:40 +0000 (+0200) Subject: Add `$user` parameter to `canRead()` for articles X-Git-Tag: 5.5.0_Alpha_1~447^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2785147e21eb68185598cc1d10b011f5ab9cd22c;p=GitHub%2FWoltLab%2FWCF.git Add `$user` parameter to `canRead()` for articles --- diff --git a/wcfsetup/install/files/lib/data/article/Article.class.php b/wcfsetup/install/files/lib/data/article/Article.class.php index d956daec94..5d9d0b149f 100644 --- a/wcfsetup/install/files/lib/data/article/Article.class.php +++ b/wcfsetup/install/files/lib/data/article/Article.class.php @@ -8,6 +8,8 @@ use wcf\data\DatabaseObject; use wcf\data\ILinkableObject; use wcf\data\IUserContent; use wcf\data\object\type\ObjectTypeCache; +use wcf\data\user\User; +use wcf\data\user\UserProfile; use wcf\system\article\discussion\CommentArticleDiscussionProvider; use wcf\system\article\discussion\IArticleDiscussionProvider; use wcf\system\article\discussion\VoidArticleDiscussionProvider; @@ -97,27 +99,35 @@ class Article extends DatabaseObject implements ILinkableObject, IUserContent } /** - * Returns true if the active user has access to this article. + * Returns true if the given user has access to this article. If the given $user is null, + * the function uses the current user. * + * Attention: The `$user` parameter was introduced with version 5.5. + * + * @param UserProfile|null $user * @return bool */ - public function canRead() + public function canRead(?UserProfile $user = null) { - if ($this->isDeleted && !WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { + if ($user === null) { + $user = new UserProfile(WCF::getUser()); + } + + if ($this->isDeleted && !$user->getPermission('admin.content.article.canManageArticle')) { return false; } if ($this->publicationStatus != self::PUBLISHED) { - if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle') && (!WCF::getSession()->getPermission('admin.content.article.canContributeArticle') || $this->userID != WCF::getUser()->userID)) { + if (!$user->getPermission('admin.content.article.canManageArticle') && (!$user->getPermission('admin.content.article.canContributeArticle') || $this->userID != $user->userID)) { return false; } } if ($this->getCategory()) { - return $this->getCategory()->isAccessible(); + return $this->getCategory()->isAccessible($user->getDecoratedObject()); } - return WCF::getSession()->getPermission('user.article.canRead'); + return $user->getPermission('user.article.canRead'); } /**