From 4b5d10151dd5644efe577861bd76b19a4246ca38 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 13 Jun 2013 16:39:16 +0200 Subject: [PATCH 1/2] Apply time limits on template application --- lib/classes/ACL.php | 16 +++++++++- tests/classes/ACLTest.php | 42 ++++++++++++++++++++++++++ www/skins/icons/user_details_gray.png | Bin 0 -> 1369 bytes 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 www/skins/icons/user_details_gray.png diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index daf2fd6094..48f226d3a5 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -389,11 +389,25 @@ class ACL implements cache_cacheableInterface $this->update_rights_to_base($base_id, $rights); } + $this->apply_template_time_limits($template_user, $base_ids); + $this->user->set_last_template($template_user); return $this; } + private function apply_template_time_limits(User_Interface $template_user, Array $base_ids) + { + foreach ($base_ids as $base_id) { + $limited = $template_user->ACL()->get_limits($base_id); + if (null !== $limited) { + $this->set_limits($base_id, '1', $limited['dmin'], $limited['dmax']); + } else { + $this->set_limits($base_id, '0', $limited['dmin'], $limited['dmax']); + } + } + } + /** * * @return boolean @@ -1555,7 +1569,7 @@ class ACL implements cache_cacheableInterface return null; } - return ($this->_limited[$base_id]); + return $this->_limited[$base_id]; } public function set_limits($base_id, $limit, DateTime $limit_from = null, DateTime $limit_to = null) diff --git a/tests/classes/ACLTest.php b/tests/classes/ACLTest.php index f48cc1f90e..69dde56d8d 100644 --- a/tests/classes/ACLTest.php +++ b/tests/classes/ACLTest.php @@ -81,6 +81,48 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract } } + foreach ($base_ids as $base_id) { + $this->assertNull($cobaye->ACL()->get_limits($base_id)); + } + + $template->delete(); + $cobaye->delete(); + } + + public function testApply_model_with_time_limit() + { + $template = User_Adapter::create(self::$DI['app'], 'test_phpunit2', 'blabla2', 'test2@example.com', false); + $template->set_template(self::$DI['user']); + + $base_ids = array(); + foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) { + foreach ($databox->get_collections() as $collection) { + $base_id = $collection->get_base_id(); + $base_ids[] = $base_id; + } + } + $template->ACL()->give_access_to_base($base_ids); + + $limit_from = new \DateTime('-1 day'); + $limit_to = new \DateTime('+1 day'); + + foreach ($base_ids as $base_id) { + $template->ACL()->set_limits($base_id, 1, $limit_from, $limit_to); + } + + $cobaye = User_Adapter::create(self::$DI['app'], 'test_phpunit3', 'blabla3', 'test3@example.com', false); + $cobaye->ACL()->apply_model($template, $base_ids); + foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) { + foreach ($databox->get_collections() as $collection) { + $base_id = $collection->get_base_id(); + $this->assertTrue($cobaye->ACL()->has_access_to_base($base_id)); + } + } + + foreach ($base_ids as $base_id) { + $this->assertEquals(array('dmin' => $limit_from, 'dmax' => $limit_to), $cobaye->ACL()->get_limits($base_id)); + } + $template->delete(); $cobaye->delete(); } diff --git a/www/skins/icons/user_details_gray.png b/www/skins/icons/user_details_gray.png new file mode 100644 index 0000000000000000000000000000000000000000..08e6476cc99f1c1b027f8fa78371b9a3a8177369 GIT binary patch literal 1369 zcmeAS@N?(olHy`uVBq!ia0vp^d>}Rl8<3oNC%zs?NtU=qlmzFem6RtIr7}3C)9WTXpJp<7&;SCUwvn^&w1Gr=XbIJqdZpd>RtPXT0NVp4u- ziLDaQr4TRV7Ql_oD~1LWFu?RH5)1SV^$b8>f+_U%#ji9s7p}UvBq$Z(UaSTehg24% z>IbD3=a&{G10ya?8Dv#~m2**QVo82cNPd0}EEEGW@=NlIGx7@*oP$jjd=ry1^FVyC zdS72F&%EN2#JuEGPZwJypb2`JnJHH0PR{0LZmy=z&SoZthOS0VZcgTwP8N>F7KUyH z7EY!xy)OC5rManjB{01y2)$-F^@5T@ZUN9{m(-%nveXo}qWoM1u$Qeeal6GBr+HAl zDY)HYf>W90C9lR^oy}d%GEE8IJ61UJIX;SL$QusEi+`!3(c2p%0V?v%}u9%_>pTz{=N(W4=1ZCZ}m?Me-iq}F3` z>&u&GA9`qTcirWe0vv43j52)ecjbEB5_jJ<3S0fP(QMJWmnEyd{H$rZb}+#qGbwC! zXq>jiTtAsr(@#I$Eu=KZb*@K0{}t8ACmRwaX85Qbvh<475j#;dKghMgqCjBY!`L^w zc1+U{>9P{@@Za!j_sj1G%69kOvOl?--_t;%=30iyYpcAQ_J|9Je?sI|9Kj2KUEy72ycqS@@mn>lT1 zn>~58#k%#sR^9!*SWsE0^GRoMd&*(H^^+s~XD$m`x%**3#i!$%g_HaXpM3v4-$w4d ja;2T}&fn6XRSz&6`}lR;-1NUIK!u&BtDnm{r-UW|@H+nl literal 0 HcmV?d00001 From 41217b8f371037fc9ecee0683020452a0d24efee Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 13 Jun 2013 16:39:28 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcef5265e5..b2ae015a8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - BC Break : Removed `bin/console check:system` command, replaced by `bin/setup check:system`. - BC Break : Removed `bin/console system:upgrade` command, replaced by `bin/setup system:upgrade`. - BC break : Configuration simplification, optimized for performances. + - BC Break : Time limits are now applied on templates application. - SwiftMailer integration (replaces PHPMailer). - Emails now include an HTML view.