diff --git a/VERSIONS_HOTLINE/64605 b/VERSIONS_HOTLINE/64605 new file mode 100644 index 0000000000000000000000000000000000000000..41bf75a19558f97cc2512b08be8ad4f5f0a61f6b --- /dev/null +++ b/VERSIONS_HOTLINE/64605 @@ -0,0 +1 @@ + - ticket #64605 : Avis sur les notices : Correction de l'affichage des avis en attente de modération \ No newline at end of file diff --git a/library/Trait/Avis.php b/library/Trait/Avis.php index 9cce4a6f6a7cbadd79d12a4672f3579c59a8aaae..f486694fab43e5b570a24823a6c4baa4e9ba8092 100644 --- a/library/Trait/Avis.php +++ b/library/Trait/Avis.php @@ -57,21 +57,30 @@ trait Trait_Avis { public function isWaitingForModeration() { - if ($this->isWrittenByAbonne() && Class_AdminVar::get('MODO_AVIS') == 1) - return $this->isModerationOK() == false; + return $this->shouldBeModerated() + ? $this->isModerationNOK() + : false; + } - if ($this->isWrittenByBibliothecaire() && Class_AdminVar::get('MODO_AVIS_BIBLIO') == 1) - return $this->isModerationOK() == false; - return false; + public function shouldBeModerated() { + return ($this->isWrittenByAbonne() && Class_AdminVar::get('MODO_AVIS') == 1) + || ($this->isWrittenByBibliothecaire() && Class_AdminVar::get('MODO_AVIS_BIBLIO') == 1); } public function isVisibleForUser($user) { - if ($this->getUser() == null || ($user && ($this->getIdUser() == $user->ID_USER))) - return true; + if (!$this->getUser()) + return $this->hasBeenModerated(); - return $this->isWaitingForModeration() == false; + return ($user && ($this->getIdUser() == $user->ID_USER)) + ? true + : $this->hasBeenModerated(); + } + + + public function hasBeenModerated() { + return !$this->isWaitingForModeration(); } @@ -79,14 +88,17 @@ trait Trait_Avis { return $this->getAbonOuBib() == self::$AVIS_ABONNE; } + public function isOrphan() { return $this->getFlags() == self::ORPHAN_FLAG ; } + public function isArchived() { return $this->getFlags() == self::ARCHIVED_FLAG ; } + public function beWrittenByAbonne() { return $this->setAbonOuBib(self::$AVIS_ABONNE); } @@ -112,6 +124,11 @@ trait Trait_Avis { } + public function isModerationNOK() { + return $this->getStatut() == self::$STATUT_NOK; + } + + public function setModerationNOK() { return $this->setStatut(self::$STATUT_NOK); } @@ -121,4 +138,3 @@ trait Trait_Avis { return 'notices_avis' == $this->_table_name; } } -?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 1fea64ff4d35754f7468f19533577e151f0718c0..b69eb4b43f9ecbc6553a2dc55688cef74a4261d9 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1419,56 +1419,127 @@ class NoticeAjaxControllerDisponibiliteNoticeTest extends AbstractControllerTest -abstract class NoticeAjaxControllerNoticeWithAvisTestCase extends AbstractControllerTestCase { +abstract class NoticeAjaxControllerNoticeWithAvisTestCase + extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; public function setup() { parent::setup(); - Class_AdminVar::newInstanceWithId('AVIS_BIB_SEULEMENT')->setValeur(0); + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); - $avis_de_paul = Class_AvisNotice::newInstanceWithId(23,['entete'=>'Tres Bien', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'polo'])->beAbonneSIGB(), - 'avis'=>'de la balle', - 'date_avis'=>'15/03/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'0']) - ->setModerationOk(); + $paul = $this->fixture('Class_Users', + ['id' => 15, + 'login' => 'polo', + 'password' => 'secret']) + ->beAbonneSIGB(); - $avis_de_francois = Class_AvisNotice::newInstanceWithId(24,['entete'=>'Cool', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), - 'avis'=>'tres bien', - 'date_avis'=>'16/02/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'1']) + $avis_de_paul = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'user' => $paul, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 1, + ]); + + $avis_de_francois = Class_AvisNotice::newInstanceWithId(24, + ['entete'=>'Cool', + 'note'=>'4', + 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), + 'avis'=>'tres bien', + 'date_avis'=>'16/02/2013', + 'clef_oeuvre'=>'potter', + 'abon_ou_bib'=>'1']) ->setModerationOk(); - Class_Notice::newInstanceWithId(34,['titre_principal'=>'Potter', - 'clef_oeuvre'=>'potter', - 'avis' => [$avis_de_paul, $avis_de_francois]]); + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_de_paul, + $avis_de_francois]]); } } -class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { +class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest + extends NoticeAjaxControllerNoticeWithAvisTestCase { /** * parent::_login setup an admin account by default -> do not log at all in this test */ protected function _login() {} + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + /** @test */ public function editLinkShouldNotBePresent() { - $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); $this->assertNotXPath('//a[contains(@href, "abonne/editavisnotice")]'); } } +/** @see http://forge.afi-sa.fr/issues/64605 */ +class NoticeAjaxControllerNoticeWithAvisWithModerationAndAuthorLostNotLoggedTest + extends AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + /** + * parent::_login setup an admin account by default -> do not log at all in this test + */ + protected function _login() {} + + public function setup() { + parent::setup(); + + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); + Class_AdminVar::set('MODO_AVIS', 1); + + $avis_orphelin = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'id_user' => 24, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 0, + ]); + + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_orphelin]]); + + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + + /** @test */ + public function notValidatedShouldNotBePresent() { + $this->assertNotXPathContentContains('//a[contains(@href, "/viewavis/")][contains(@href, "/id/23")]', + 'Tres Bien', + $this->_response->getBody()); + } +} + + class NoticeAjaxControllerNoticeWithAvisEditLinkGuestLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { protected function _loginHook($account) {