From bff736de523c0c46f67af3af7d8772474977450d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ANDRE=20s=C3=A9bastien?= <sandre@afi-sa.fr> Date: Mon, 21 Jun 2021 15:09:11 +0200 Subject: [PATCH] hotline: #136610 : Activity, modoportail can edit article --- VERSIONS_HOTLINE/136610 | 1 + library/Class/SessionActivity.php | 5 +++ library/Class/UserGroup.php | 5 ++- .../Controller/Plugin/Manager/Article.php | 11 ++++-- .../controllers/ActivityControllerTest.php | 37 +++++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 VERSIONS_HOTLINE/136610 diff --git a/VERSIONS_HOTLINE/136610 b/VERSIONS_HOTLINE/136610 new file mode 100644 index 00000000000..5df728610db --- /dev/null +++ b/VERSIONS_HOTLINE/136610 @@ -0,0 +1 @@ + - ticket #136610 : Activités : Les redacteurs portail avec le droit de diriger une activité doivent avoir la possibilité d'editer un article lié à une activitée \ No newline at end of file diff --git a/library/Class/SessionActivity.php b/library/Class/SessionActivity.php index ce75f2a5c23..da6b2474248 100644 --- a/library/Class/SessionActivity.php +++ b/library/Class/SessionActivity.php @@ -90,6 +90,11 @@ class SessionActivityLoader extends Storm_Model_Loader { } + public function countByArticle($article) { + return Class_SessionActivity::countBy(['article_id' => $article->getId()]); + } + + public function findAllNotifiable() { if (!$delay = (int)Class_AdminVar::get('ACTIVITY_NOTIFICATION_DELAY')) return []; diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index 7c429edc64a..ff319f82e9f 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -626,6 +626,9 @@ class Class_UserGroup extends Storm_Model_Abstract { public function hasParentPermissionOn($permission, $model) { + if (!$model) + return false; + if ($parent = $model->getPermissionsParent()) return $this->hasPermissionOn($permission, $parent); @@ -725,4 +728,4 @@ class Class_UserGroup extends Storm_Model_Abstract { return $this->_criteria_cache; return $this->_criteria_cache = (new Class_UserGroup_Filter($this->getFiltersAsArray())); } -} \ No newline at end of file +} diff --git a/library/ZendAfi/Controller/Plugin/Manager/Article.php b/library/ZendAfi/Controller/Plugin/Manager/Article.php index 97475c779eb..f4459b7f25a 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Article.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Article.php @@ -206,8 +206,13 @@ class ZendAfi_Controller_Plugin_Manager_Article extends ZendAfi_Controller_Plugi protected function _canEdit($model) { - $this->_setParam('id_cat',null); - return $this->_canModify($model->getCategorie()); + $this->_setParam('id_cat', null); + + if ($this->_canModify($model->getCategorie())) + return true; + + return Class_SessionActivity::countByArticle($model) > 0 + && Class_Users::getIdentity()->hasRightDirigerActivity(); } @@ -431,4 +436,4 @@ class ZendAfi_Controller_Plugin_Manager_Article extends ZendAfi_Controller_Plugi }] ]; } -} \ No newline at end of file +} diff --git a/tests/application/modules/admin/controllers/ActivityControllerTest.php b/tests/application/modules/admin/controllers/ActivityControllerTest.php index 6807e82e301..a12a496576e 100644 --- a/tests/application/modules/admin/controllers/ActivityControllerTest.php +++ b/tests/application/modules/admin/controllers/ActivityControllerTest.php @@ -2263,6 +2263,43 @@ class Admin_ActivityControllerLinkedArticleWithoutArticleAndAllDayActionTest +/* hotline: #136610 */ +class Admin_ActivityControllerLinkedArticleWithModoPortailTest + extends Admin_ActivityControllerTestCase { + + public function setUp() { + parent::setUp(); + $this->_session_java_mars->getArticle()->delete(); + Class_SessionActivity::clearCache(); + Class_Article::clearCache(); + $this->_session_java_mars->save(); + $linked_article = $this->_session_java_mars->getArticle(); + + $logged_user = $this->fixture(Class_Users::class, + ['id' => 6, + 'login' => 'totoro', + 'password' => '123456']) + ->beModoPortail() + ->setUserGroups([$this->fixture(Class_UserGroup::class, + ['id' => 20, + 'libelle' => 'Redacteur portail']) + ->addRightDirigerActivity() + ]); + ZendAfi_Auth::getInstance()->logUser($logged_user); + + $this->dispatch('/admin/cms/edit/id/' . $linked_article->getId()); + } + + + /** @test */ + public function modoPortailShouldHaveRightToEditAcitvityArticle() { + $this->assertXPath('//input[@id="titre"][@value="Learn Java"]'); + } +} + + + + class Admin_ActivityControllerLinkedArticleRegenerateActionTest extends Admin_ActivityControllerTestCase { -- GitLab