Add permission to manage own articles
authorJoshua Rüsweg <josh@bastelstu.be>
Tue, 28 Aug 2018 10:40:33 +0000 (12:40 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Tue, 28 Aug 2018 10:40:33 +0000 (12:40 +0200)
See #2677

com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/userGroupOption.xml
wcfsetup/install/files/acp/templates/articleAdd.tpl
wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php
wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php
wcfsetup/install/files/lib/acp/page/ArticleListPage.class.php
wcfsetup/install/files/lib/data/article/Article.class.php
wcfsetup/install/files/lib/data/article/ArticleAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/ArticleClipboardAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 20eb88b0b4f96a6d62fa5feefecce2826a99d628..923599072adcfb33a77e8cf6359fd5ef80313dae 100644 (file)
@@ -93,7 +93,7 @@
                                                        </li>
                                                {/if}
                                        
-                                               {if $__wcf->getSession()->getPermission('admin.content.article.canManageArticle')}<li><a href="{link controller='ArticleEdit' id=$article->articleID isACP=true}{/link}" class="button"><span class="icon icon16 fa-pencil"></span> <span>{lang}wcf.acp.article.edit{/lang}</span></a></li>{/if}
+                                               {if $article->canEdit()}<li><a href="{link controller='ArticleEdit' id=$article->articleID isACP=true}{/link}" class="button"><span class="icon icon16 fa-pencil"></span> <span>{lang}wcf.acp.article.edit{/lang}</span></a></li>{/if}
                                                {event name='contentHeaderNavigation'}
                                        {/content}
                                </ul>
index 0bdf43c7686b5ec8edcc285ba5b8f34d8d2e001b..010e457f0e8356d8baf111e1f76e39bc6655c5db 100644 (file)
                                <usersonly>1</usersonly>
                                <options>module_article</options>
                        </option>
+                       <option name="admin.content.article.canManageOwnArticles">
+                               <categoryname>admin.content</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>0</defaultvalue>
+                               <admindefaultvalue>1</admindefaultvalue>
+                               <usersonly>1</usersonly>
+                               <options>module_article</options>
+                       </option>
                        <option name="admin.content.article.canManageCategory">
                                <categoryname>admin.content</categoryname>
                                <optiontype>boolean</optiontype>
index 0047dea966f7d413b3db577c8575b7e86d084053..10c4cb13fa0b3e83a82eb9a855f97fbce66febee 100644 (file)
                        </dd>
                </dl>
                
-               {if $__wcf->session->getPermission('admin.content.article.canManageArticle')}
+               {if $__wcf->session->getPermission('admin.content.article.canManageArticle') || $__wcf->session->getPermission('admin.content.article.canManageOwnArticles')}
                        <dl>
                                <dt><label for="categoryID">{lang}wcf.acp.article.publicationStatus{/lang}</label></dt>
                                <dd class="floated">
index 461e052c1fc146afbbc040b9ebd3547e8a6dc7bb..72988440cad167d566b7711d53ee222c077cd778 100644 (file)
@@ -231,7 +231,7 @@ class ArticleAddForm extends AbstractForm {
                }
                if (!empty($_POST['enableComments'])) $this->enableComments = 1;
                
-               if (WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
+               if (WCF::getSession()->getPermission('admin.content.article.canManageArticle') || WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles')) {
                        if (isset($_POST['publicationStatus'])) $this->publicationStatus = intval($_POST['publicationStatus']);
                }
                else {
index 672c2817ab830359acef342f5a57cc13770c7c0c..cd11a102eb7810266f8ee409bdc65e93638a8e1b 100644 (file)
@@ -52,10 +52,8 @@ class ArticleEditForm extends ArticleAddForm {
                }
                if ($this->article->isMultilingual) $this->isMultilingual = 1;
                
-               if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
-                       if ($this->article->userID != WCF::getUser()->userID || $this->article->publicationStatus != Article::UNPUBLISHED) {
-                               throw new PermissionDeniedException();
-                       }
+               if (!$this->article->canEdit()) {
+                       throw new PermissionDeniedException();
                }
        }
        
index 5dc7b4c19f78a5c050f9e301241f0d80a21bf814..5888d31bdfe57f2339ac7be166a8065c23448938 100644 (file)
@@ -136,7 +136,11 @@ class ArticleListPage extends SortablePage {
                if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
                        // only show own articles
                        $this->objectList->getConditionBuilder()->add('article.userID = ?', [WCF::getUser()->userID]);
-                       $this->objectList->getConditionBuilder()->add('article.publicationStatus = ?', [Article::UNPUBLISHED]);
+                       
+                       if (!WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles')) {
+                               // only show unpublished articles
+                               $this->objectList->getConditionBuilder()->add('article.publicationStatus = ?', [Article::UNPUBLISHED]);
+                       }
                }
                
                $this->objectList->sqlSelects = "(SELECT title FROM wcf".WCF_N."_article_content WHERE articleID = article.articleID AND (languageID IS NULL OR languageID = ".WCF::getLanguage()->languageID.") LIMIT 1) AS title";
index 9ce4ee39164ba5a2285170190b508c086d109337..64ba21bb81e482ef8d859eb7dbb325cd5a52f4d8 100644 (file)
@@ -84,6 +84,10 @@ class Article extends DatabaseObject implements ILinkableObject {
                        return true;
                }
                
+               if (WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles') && $this->userID == WCF::getUser()->userID) {
+                       return true;
+               }
+               
                return false;
        }
        
@@ -110,6 +114,48 @@ class Article extends DatabaseObject implements ILinkableObject {
                return WCF::getSession()->getPermission('user.article.canRead');
        }
        
+       /**
+        * Returns true if the current user can edit these article.
+        * 
+        * @return      boolean
+        * @since       3.2
+        */
+       public function canEdit() {
+               if (WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
+                       return true; 
+               }
+               
+               if (WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles') && $this->userID == WCF::getUser()->userID) {
+                       return true;
+               }
+               
+               if ($this->publicationStatus != self::PUBLISHED) {
+                       if (WCF::getSession()->getPermission('admin.content.article.canContributeArticle') && $this->userID == WCF::getUser()->userID) {
+                               return false;
+                       }
+               }
+               
+               return false; 
+       }
+       
+       /**
+        * Returns true if the current user can publish these article. 
+        * 
+        * @return      boolean
+        * @since       3.2
+        */
+       public function canPublish() {
+               if (WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
+                       return true;
+               }
+               
+               if (WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles') && $this->userID == WCF::getUser()->userID) {
+                       return true;
+               }
+               
+               return false;
+       }
+       
        /**
         * @inheritDoc
         */
index 1b4054f5b189d46bf6e697dbb7e73f93840847ea..bd76ed3fef5207734529c7489ca7e6acc25f53d4 100644 (file)
@@ -8,6 +8,7 @@ use wcf\data\language\Language;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\system\clipboard\ClipboardHandler;
 use wcf\system\comment\CommentHandler;
+use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\LanguageFactory;
 use wcf\system\like\LikeHandler;
@@ -274,8 +275,6 @@ class ArticleAction extends AbstractDatabaseObjectAction {
         * @throws      UserInputException
         */
        public function validateDelete() {
-               WCF::getSession()->checkPermissions(['admin.content.article.canManageArticle']);
-               
                if (empty($this->objects)) {
                        $this->readObjects();
                        
@@ -285,6 +284,10 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                }
                
                foreach ($this->getObjects() as $article) {
+                       if (!$article->canDelete()) {
+                               throw new PermissionDeniedException();
+                       }
+                       
                        if (!$article->isDeleted) {
                                throw new UserInputException('objectIDs');
                        }
@@ -331,8 +334,6 @@ class ArticleAction extends AbstractDatabaseObjectAction {
         * @throws      UserInputException
         */
        public function validateTrash() {
-               WCF::getSession()->checkPermissions(['admin.content.article.canManageArticle']);
-               
                if (empty($this->objects)) {
                        $this->readObjects();
                        
@@ -342,6 +343,10 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                }
                
                foreach ($this->getObjects() as $article) {
+                       if (!$article->canDelete()) {
+                               throw new PermissionDeniedException();
+                       }
+                       
                        if ($article->isDeleted) {
                                throw new UserInputException('objectIDs');
                        }
@@ -556,8 +561,6 @@ class ArticleAction extends AbstractDatabaseObjectAction {
         * @throws      UserInputException
         */
        public function validatePublish() {
-               WCF::getSession()->checkPermissions(['admin.content.article.canManageArticle']);
-               
                if (empty($this->objects)) {
                        $this->readObjects();
                        
@@ -567,6 +570,10 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                }
                
                foreach ($this->getObjects() as $article) {
+                       if (!$article->canPublish()) {
+                               throw new PermissionDeniedException();  
+                       }
+                       
                        if ($article->publicationStatus == Article::PUBLISHED) {
                                throw new UserInputException('objectIDs');
                        }
@@ -603,8 +610,6 @@ class ArticleAction extends AbstractDatabaseObjectAction {
         * @throws      UserInputException
         */
        public function validateUnpublish() {
-               WCF::getSession()->checkPermissions(['admin.content.article.canManageArticle']);
-               
                if (empty($this->objects)) {
                        $this->readObjects();
                        
@@ -614,6 +619,10 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                }
                
                foreach ($this->getObjects() as $article) {
+                       if (!$article->canPublish()) {
+                               throw new PermissionDeniedException();
+                       }
+                       
                        if ($article->publicationStatus != Article::PUBLISHED) {
                                throw new UserInputException('objectIDs');
                        }
index 1518d54776e6bcf145bea31f609df1a00bc203bc..6ff5ddfc5ebc2e243c0c5e49a8d694f38b6dcb69 100644 (file)
@@ -93,15 +93,11 @@ class ArticleClipboardAction extends AbstractClipboardAction {
         * @return      integer[]
         */
        public function validateDelete() {
-               if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
-                       return [];
-               }
-               
                $objectIDs = [];
                
                /** @var Article $article */
                foreach ($this->objects as $article) {
-                       if ($article->isDeleted) {
+                       if ($article->canDelete() && $article->isDeleted) {
                                $objectIDs[] = $article->articleID;
                        }
                }
@@ -115,15 +111,11 @@ class ArticleClipboardAction extends AbstractClipboardAction {
         * @return      integer[]
         */
        public function validatePublish() {
-               if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
-                       return [];
-               }
-               
                $objectIDs = [];
                
                /** @var Article $article */
                foreach ($this->objects as $article) {
-                       if ($article->publicationStatus == Article::UNPUBLISHED) {
+                       if ($article->canPublish() && $article->publicationStatus == Article::UNPUBLISHED) {
                                $objectIDs[] = $article->articleID;
                        }
                }
@@ -159,15 +151,11 @@ class ArticleClipboardAction extends AbstractClipboardAction {
         * @return      integer[]
         */
        public function validateTrash() {
-               if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
-                       return [];
-               }
-               
                $objectIDs = [];
                
                /** @var Article $article */
                foreach ($this->objects as $article) {
-                       if (!$article->isDeleted) {
+                       if ($article->canDelete() && !$article->isDeleted) {
                                $objectIDs[] = $article->articleID;
                        }
                }
@@ -181,15 +169,11 @@ class ArticleClipboardAction extends AbstractClipboardAction {
         * @return      integer[]
         */
        public function validateUnpublish() {
-               if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
-                       return [];
-               }
-               
                $objectIDs = [];
                
                /** @var Article $article */
                foreach ($this->objects as $article) {
-                       if ($article->publicationStatus == Article::PUBLISHED) {
+                       if ($article->canPublish() && $article->publicationStatus == Article::PUBLISHED) {
                                $objectIDs[] = $article->articleID;
                        }
                }
index f329e367079337749a4a1909f780c2706b6602f4..967e4a7cd116e17e7df85158179af43e458f1386 100644 (file)
                <item name="wcf.acp.group.option.user.tag.canViewTag"><![CDATA[Kann Tag sehen]]></item>
                <item name="wcf.acp.group.option.category.user.cms"><![CDATA[CMS]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canManageArticle"><![CDATA[Kann Artikel verwalten]]></item>
+               <item name="wcf.acp.group.option.admin.content.article.canManageOwnArticles"><![CDATA[Kann eigene Artikel verwalten]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canContributeArticle"><![CDATA[Kann Artikel einreichen]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canManageCategory"><![CDATA[Kann Artikel-Kategorien verwalten]]></item>
                <item name="wcf.acp.group.option.admin.content.cms.canManageBox"><![CDATA[Kann Boxen verwalten]]></item>
index c9e67029fb6aeb6d5d162ac1e4aa861a85b674a5..847298c6eb863db6c98f72819928a27ff8877d54 100644 (file)
                <item name="wcf.acp.group.option.user.tag.canViewTag"><![CDATA[Can view tags]]></item>
                <item name="wcf.acp.group.option.category.user.cms"><![CDATA[CMS]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canManageArticle"><![CDATA[Can manage articles]]></item>
+               <item name="wcf.acp.group.option.admin.content.article.canManageOwnArticles"><![CDATA[Can manage own articles]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canContributeArticle"><![CDATA[Can contribute articles]]></item>
                <item name="wcf.acp.group.option.admin.content.article.canManageCategory"><![CDATA[Can manage article categories]]></item>
                <item name="wcf.acp.group.option.admin.content.cms.canManageBox"><![CDATA[Can manage boxes]]></item>