diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 022b01d5e7..99748cb6ce 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -61,6 +61,30 @@ class Users implements ControllerProviderInterface } ); + $controllers->post('/rights/reset/', function(Application $app, Request $request) + { + try + { + $core = $app['Core']; + $datas = array('error' => false); + + $helper = new UserHelper\Edit($core, $request); + $helper->resetRights(); + } + catch (\Exception $e) + { + $datas['error'] = true; + $datas['message'] = $e->getMessage(); + } + + return new Response( + $core->getSerializer()->serialize($datas, 'json') + , 200 + , array('Content-Type' => 'application/json') + ); + } + ); + $controllers->post('/delete/', function(Application $app) { $module = new UserHelper\Edit($app['Core'], $app['request']); diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 08874ae68f..4161fcfade 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -671,4 +671,41 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper } } + public function resetRights() + { + $authUser = $this->core->getAuthenticatedUser(); + $adminACL = $authUser->ACL(); + $base_ids = array_keys($adminACL->get_granted_base(array('canadmin'))); + + foreach ($this->users as $usr_id) + { + $user = \User_Adapter::getInstance($usr_id, \appbox::get_instance($this->core)); + $ACL = $user->ACL(); + + if ($user->is_template()) + { + $template = $user; + + if ($template->get_template_owner()->get_id() !== $authUser->get_id()) + { + continue; + } + } + + foreach ($base_ids as $base_id) + { + if (!$ACL->has_access_to_base($base_id)) + { + continue; + } + + $ACL->set_limits($base_id, false); + $ACL->set_masks_on_base($base_id, 0, 0, 0, 0); + $ACL->remove_quotas_on_base($base_id); + } + $ACL->revoke_access_from_bases($base_ids); + $ACL->revoke_unused_sbas_rights(); + } + } + } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php index d70e43c6e3..4e752c4920 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php @@ -303,5 +303,54 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition")); } + + public function testResetRights() + { + $appbox = \appbox::get_instance(self::$core); + $username = uniqid('user_'); + $user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false); + + $user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes())); + + foreach ($appbox->get_databoxes() as $databox) + { + + $rights = array( + 'bas_manage' => '1' + , 'bas_modify_struct' => '1' + , 'bas_modif_th' => '1' + , 'bas_chupub' => '1' + ); + + $user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights); + + foreach ($databox->get_collections() as $collection) + { + $base_id = $collection->get_base_id(); + $user->ACL()->give_access_to_base(array($base_id)); + + $rights = array( + 'canputinalbum' => '1' + , 'candwnldhd' => '1' + , 'candwnldsubdef' => '1' + , 'nowatermark' => '1' + ); + + $user->ACL()->update_rights_to_base($collection->get_base_id(), $rights); + break; + } + } +// + + $this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id())); + $response = $this->client->getResponse(); + $this->assertTrue($response->isOK()); + $this->assertEquals("application/json", $response->headers->get("content-type")); + $datas = json_decode($response->getContent()); + $this->assertTrue(is_object($datas)); + $this->assertFalse($datas->error); + $this->assertFalse($user->ACL()->has_access_to_base($base_id)); + $user->delete(); + } } diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index abfb7b61e6..98cecc7068 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -453,7 +453,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase //init core if (null === self::$core) { - self::$core = bootstrap::getCore(); + self::$core = \bootstrap::getCore(); } } diff --git a/templates/web/admin/editusers.twig b/templates/web/admin/editusers.twig index aaaedf4007..33a2ffa4f1 100644 --- a/templates/web/admin/editusers.twig +++ b/templates/web/admin/editusers.twig @@ -152,6 +152,7 @@ {% endfor %} + @@ -572,3 +573,50 @@ {% trans 'boutton::retour' %} + + \ No newline at end of file diff --git a/templates/web/admin/users.html b/templates/web/admin/users.html index bfe234b122..4e754e193f 100644 --- a/templates/web/admin/users.html +++ b/templates/web/admin/users.html @@ -34,7 +34,7 @@ - + {% trans 'Reglages:: reglages d inscitpition automatisee' %} @@ -59,7 +59,7 @@

-
+

{% trans 'Apply a template' %} - - - - {% trans 'admin::compte-utilisateur identifiant' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur nom/prenom' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur societe' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur email' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur pays' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur dernier modele applique' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - {% trans 'admin::compte-utilisateur date de creation' %} - - - {{ parm.ord == 'asc' ? '▼' : '▲' }} - - - - - - - {% for usr in users.get_results %} - - - {% if usr.is_template() %} + + + +

+ + + + + + + + + + + + + + + + {% for usr in users.get_results %} + + - - - - - - - - - {% endfor %} - -
+ {% trans 'admin::compte-utilisateur id utilisateur' %} + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur identifiant' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur nom/prenom' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur societe' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur email' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur pays' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur dernier modele applique' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + + + + {% trans 'admin::compte-utilisateur date de creation' %} + + + {{ parm.ord == 'asc' ? '▼' : '▲' }} + + +
+ {% if usr.is_template() %} - {% else %} + {% else %} {% if usr.ACL().is_phantom() %} {% endif %} {{usr.get_id()}} - {% endif %} - - {{usr.get_login()}} - - {{usr.get_firstname()}} {{usr.get_lastname()}} - - {{usr.get_company()}} - - {{usr.get_email()}} - - {{usr.get_country()}} - - {{usr.get_applied_template()}} - - {{usr.get_creation_date()|getDate}} -
- - -
- - - {% for sbas_id in parm.sbas_id %} - - {% endfor %} - {% for base_id in parm.base_id %} - - {% endfor %} - {% if parm['usr_ids'] is defined %} - - {% endif %} - - - -
- -
- {{users.get_total}} resultats - - {% set pages = users.get_total() / parm['per_page'] %} - {% set modulo = users.get_total() % parm['per_page'] %} - - {% if modulo > 0 %}{% set pages = pages + 1 %}{% endif %} - {{pages|floor}} pages - {% if users.get_page > 2 %} - - {% endif %} - {% if users.get_page > 1 %} - - {% endif %} - - {% if users.get_page < pages -1 %} - - {% endif %} - {% if users.get_page < pages - 2 %} - - {% endif %} - - - + {% endif %} + + + {{usr.get_login()}} + + + {{usr.get_firstname()}} {{usr.get_lastname()}} + + + {{usr.get_company()}} + + + {{usr.get_email()}} + + + {{usr.get_country()}} + + + {{usr.get_applied_template()}} + + + {{usr.get_creation_date()|getDate}} + + + {% endfor %} + + - - - - - {% if parm['act'] is defined %} - - {% endif %} - {% for sbas_id in parm.sbas_id %} - - {% endfor %} - {% for base_id in parm.base_id %} - - {% endfor %} - {% if parm['usr_ids'] is defined %} - - {% endif %} - - - - - -
-
- {% if parm.base_id is not empty %} - {% for base_id in parm.base_id %} - - {% endfor %} - {% endif %} - {% if parm.sbas_id is not empty %} + + + {% for sbas_id in parm.sbas_id %} {% endfor %} - {% endif %} - - - -
- - + + {% endblock %} \ No newline at end of file diff --git a/www/admin/editusers.js b/www/admin/editusers.js index 5e7dfdaa35..9234de7f1c 100644 --- a/www/admin/editusers.js +++ b/www/admin/editusers.js @@ -74,13 +74,13 @@ function ini_edit_usrs(){ $('#users_rights_form div.switch_right').bind('click', function(event){ user_click_box(event, $(this)); }); - $('#right-ajax button.users_rights_valid').bind('click', function(){ +$('#right-ajax button.users_rights_valid').bind('click', function(){ var datas = { users:$('#users_rights_form input[name="users"]').val(), values:$('#users_rights_form').serialize(), template:$('#users_rights_form select[name="template"]').val(), user_infos:$('#user_infos_form').serialize() - }; + }; $.ajax({ type: 'POST', url: '/admin/users/rights/apply/',