Fix ignoring the disable state of an article category
authorjoshuaruesweg <ruesweg@woltlab.com>
Tue, 11 May 2021 10:52:07 +0000 (12:52 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Tue, 11 May 2021 10:52:07 +0000 (12:52 +0200)
Deactivated categories are currently only hidden in the overview of categories in the frontend. However, articles in these categories (and the category itself, via the direct link) were still accessible. This patch solves the problem by hiding the category for all users and making articles and the category itself no longer accessible for any user.

wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php

index 3bdb56124a9e0457d05266497ac03fcc2396987e..2a127d6626e5e104a79c6f1473ae4f6bf76eeb78 100644 (file)
@@ -48,6 +48,8 @@ class ArticleCategory extends AbstractDecoratedCategory implements IAccessibleOb
        public function isAccessible(User $user = null) {
                if ($this->getObjectType()->objectType != self::OBJECT_TYPE_NAME) return false;
                
+               if ($this->isDisabled) return false;
+               
                // check permissions
                return $this->getPermission('canReadArticle', $user);
        }
@@ -108,14 +110,17 @@ class ArticleCategory extends AbstractDecoratedCategory implements IAccessibleOb
        public static function getAccessibleCategoryIDs(array $permissions = ['canReadArticle']) {
                $categoryIDs = [];
                foreach (CategoryHandler::getInstance()->getCategories(self::OBJECT_TYPE_NAME) as $category) {
-                       $result = true;
                        $category = new ArticleCategory($category);
-                       foreach ($permissions as $permission) {
-                               $result = $result && $category->getPermission($permission);
-                       }
                        
-                       if ($result) {
-                               $categoryIDs[] = $category->categoryID;
+                       if (!$category->isDisabled) {
+                               $result = true;
+                               foreach ($permissions as $permission) {
+                                       $result = $result && $category->getPermission($permission);
+                               }
+                               
+                               if ($result) {
+                                       $categoryIDs[] = $category->categoryID;
+                               }
                        }
                }