diff --git a/CHANGELOG.md b/CHANGELOG.md index b121090f0f..622a294e5c 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. 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 0000000000..08e6476cc9 Binary files /dev/null and b/www/skins/icons/user_details_gray.png differ