mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
add reset user rights from admin panel
This commit is contained in:
@@ -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']);
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -304,4 +304,53 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -453,7 +453,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
//init core
|
||||
if (null === self::$core)
|
||||
{
|
||||
self::$core = bootstrap::getCore();
|
||||
self::$core = \bootstrap::getCore();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -152,6 +152,7 @@
|
||||
<option value="{{ template.get_id() }}">{{ template.get_display_name() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type='button' id='reset_rights'>{% trans 'reset users rights' %}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -572,3 +573,50 @@
|
||||
<a href="/admin/users/search/" class="users_rights_cancel">{% trans 'boutton::retour' %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type='text/javascript'>
|
||||
$('#users_rights_form button#reset_rights').bind('click', function(){
|
||||
if(confirm("{% trans'are you sure you want reset rights ?' %}"))
|
||||
{
|
||||
var users = $('#users_rights_form input[name="users"]').val();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/admin/users/rights/reset/',
|
||||
dataType:'json',
|
||||
data: {
|
||||
users : users
|
||||
},
|
||||
success: function(data){
|
||||
|
||||
if(!data.error)
|
||||
{
|
||||
if(users === '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#right-ajax').empty().addClass('loading');
|
||||
p4.users.sel = [];
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/admin/users/rights/',
|
||||
data: {
|
||||
users : users
|
||||
},
|
||||
success: function(data){
|
||||
$('#right-ajax').removeClass('loading').html(data);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
@@ -59,7 +59,7 @@
|
||||
<button type="submit">{% trans 'boutton::chercher' %}</button>
|
||||
</p>
|
||||
</form>
|
||||
<form id="users_apply_template" method="post" action="/admin/users/apply_template/" target="_self">
|
||||
<form id="users_apply_template" method="post" action="/admin/users/apply_template/" target="_self" style="float:left">
|
||||
<p class="admin_head_opts">
|
||||
{% trans 'Apply a template' %}
|
||||
<select name="template_chooser">
|
||||
@@ -72,6 +72,11 @@
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<form id="users_reset_rights" method="post" action="/admin/users/rights/reset/" target="_self" style="float:right">
|
||||
<input type="hidden" value="" name="users">
|
||||
<button type='button'>{% trans 'reset users rights' %}</button>
|
||||
</form>
|
||||
|
||||
<table id="users" cellspacing="0" cellpadding="0" border="0" class="admintable">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -287,6 +292,45 @@
|
||||
$(this).closest('form').submit();
|
||||
});
|
||||
|
||||
$('#users_reset_rights button').bind('click', function(){
|
||||
var selectedUsers = $("#users tr.selected");
|
||||
|
||||
if(selectedUsers.length === 0)
|
||||
{
|
||||
alert("{% trans 'select at least one user' %}");
|
||||
return;
|
||||
}
|
||||
|
||||
var users = '';
|
||||
$.each(selectedUsers, function(i,n){
|
||||
users += $(n).attr("id").split("_").pop() + ';';
|
||||
});
|
||||
|
||||
if(confirm("{% trans 'are you sure you want reset rights ?' %}"))
|
||||
{
|
||||
$("#users_reset_rights input[name='users']").val(users);
|
||||
|
||||
var form = $(this).closest('form');
|
||||
|
||||
$.ajax({
|
||||
url: form.attr("action"),
|
||||
dataType: 'json',
|
||||
type : form.attr('method'),
|
||||
data: form.serializeArray(),
|
||||
success: function(data){
|
||||
if(data.error)
|
||||
{
|
||||
alert("{% trans 'an error occured' %}");
|
||||
}
|
||||
else
|
||||
{
|
||||
alert("{% trans 'users rights have been reseted' %}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function importlist()
|
||||
|
Reference in New Issue
Block a user