diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-07-15 16:31:28 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-07-15 16:31:28 +0200 |
commit | e707e948577b927a28b86545d345e7b6c8606352 (patch) | |
tree | df7f5a1705e1ee4815f28f0d864b97026a32f849 /settings | |
parent | 0cb9f5e159b1588550830dda4b21010a0412bae9 (diff) | |
download | nextcloud-server-e707e948577b927a28b86545d345e7b6c8606352.tar.gz nextcloud-server-e707e948577b927a28b86545d345e7b6c8606352.zip |
subadmins can now add users
Diffstat (limited to 'settings')
-rw-r--r-- | settings/ajax/createuser.php | 29 | ||||
-rw-r--r-- | settings/js/users.js | 89 | ||||
-rw-r--r-- | settings/templates/users.php | 20 | ||||
-rw-r--r-- | settings/users.php | 12 |
4 files changed, 110 insertions, 40 deletions
diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index c56df4bc15a..41bf31a05f6 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -4,15 +4,36 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ +if( !OC_User::isLoggedIn() || (!OC_Group::inGroup( OC_User::getUser(), 'admin' ) && !OC_SubAdmin::isSubAdmin(OC_User::getUser()))){ OC_JSON::error(array("data" => array( "message" => "Authentication error" ))); exit(); } OCP\JSON::callCheck(); -$groups = array(); -if( isset( $_POST["groups"] )){ - $groups = $_POST["groups"]; +$isadmin = OC_Group::inGroup(OC_User::getUser(),'admin')?true:false; + +if($isadmin){ + $groups = array(); + if( isset( $_POST["groups"] )){ + $groups = $_POST["groups"]; + } +}else{ + $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); + $accessiblegroups = array_flip($accessiblegroups); + if(isset( $_POST["groups"] )){ + $unauditedgroups = $_POST["groups"]; + $groups = array(); + foreach($unauditedgroups as $group){ + if(array_key_exists($group, $accessiblegroups)){ + $groups[] = $group; + } + } + if(count($groups) == 0){ + $groups = array_flip($accessiblegroups); + } + }else{ + $groups = array_flip($accessiblegroups); + } } $username = $_POST["username"]; $password = $_POST["password"]; diff --git a/settings/js/users.js b/settings/js/users.js index dfa28e4c4cb..c86949db384 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -84,18 +84,56 @@ $(document).ready(function(){ } function applyMultiplySelect(element){ + console.log(element); var checked=[]; var user=element.data('username'); - if(element.data('userGroups')){ - checked=element.data('userGroups').split(', '); + if($(element).attr('class') == 'groupsselect'){ + if(element.data('userGroups')){ + checked=element.data('userGroups').split(', '); + } + if(user){ + var checkHandeler=function(group){ + if(user==OC.currentUser && group=='admin'){ + return false; + } + $.post( + OC.filePath('settings','ajax','togglegroups.php'), + { + username:user, + group:group + }, + function(){} + ); + }; + }else{ + checkHandeler=false; + } + var addGroup = function(group) { + $('select[multiple]').each(function(index, element) { + if ($(element).find('option[value="'+group +'"]').length == 0) { + $(element).append('<option value="'+group+'">'+group+'</option>'); + } + }) + }; + element.multiSelect({ + createCallback:addGroup, + createText:'add group', + checked:checked, + oncheck:checkHandeler, + onuncheck:checkHandeler, + minWidth: 100, + }); } - if(user){ + if($(element).attr('class') == 'subadminsselect'){ + if(element.data('subadmin')){ + checked=element.data('subadmin').split(', '); + } var checkHandeler=function(group){ - if(user==OC.currentUser && group=='admin'){ + if(group=='admin'){ return false; } $.post( - OC.filePath('settings','ajax','togglegroups.php'), + OC.filePath('settings','ajax','togglesubadmins.php'), { username:user, group:group @@ -103,24 +141,25 @@ $(document).ready(function(){ function(){} ); }; - }else{ - checkHandeler=false; + + var addSubAdmin = function(group) { + console.log('addSubAdmin called'); + console.log(group); + $('select[multiple]').each(function(index, element) { + if ($(element).find('option[value="'+group +'"]').length == 0) { + $(element).append('<option value="'+group+'">'+group+'</option>'); + } + }) + }; + element.multiSelect({ + createCallback:addSubAdmin, + createText:null, + checked:checked, + oncheck:checkHandeler, + onuncheck:checkHandeler, + minWidth: 100, + }); } - var addGroup = function(group) { - $('select[multiple]').each(function(index, element) { - if ($(element).find('option[value="'+group +'"]').length == 0) { - $(element).append('<option value="'+group+'">'+group+'</option>'); - } - }) - }; - element.multiSelect({ - createCallback:addGroup, - createText:'add group', - checked:checked, - oncheck:checkHandeler, - onuncheck:checkHandeler, - minWidth: 100, - }); } $('select[multiple]').each(function(index,element){ applyMultiplySelect($(element)); @@ -255,12 +294,14 @@ $(document).ready(function(){ OC.dialogs.alert(result.data.message, 'Error creating user'); } else { + groups = result.data.groups; + console.log(groups); var tr=$('#content table tbody tr').first().clone(); tr.attr('data-uid',username); tr.find('td.name').text(username); - var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">'); + var select=$('<select multiple="multiple" class="groupsselect" data-placehoder="Groups" title="Groups">'); select.data('username',username); - select.data('userGroups',groups.join(', ')); + select.data('userGroups',groups); tr.find('td.groups').empty(); var allGroups=$('#content table').data('groups').split(', '); for(var i=0;i<groups.length;i++){ diff --git a/settings/templates/users.php b/settings/templates/users.php index b16aa1ae16c..649fce107db 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -6,9 +6,12 @@ */ $allGroups=array(); foreach($_["groups"] as $group) { - $allGroups[]=$group['name']; + $allGroups[] = $group['name']; } -$_['subadmingroups'] = $_['groups']; +$_['subadmingroups'] = $allGroups; +$items = array_flip($_['subadmingroups']); +unset($items['admin']); +$_['subadmingroups'] = array_flip($items); ?> <div id="controls"> @@ -16,6 +19,7 @@ $_['subadmingroups'] = $_['groups']; <input id="newusername" placeholder="<?php echo $l->t('Name')?>" /> <input type="password" id="newuserpassword" placeholder="<?php echo $l->t('Password')?>" /> <select + class="groupsselect" id="newusergroups" data-placeholder="groups" title="<?php echo $l->t('Groups')?>" multiple="multiple"> <?php foreach($_["groups"] as $group): ?> @@ -62,7 +66,7 @@ $_['subadmingroups'] = $_['groups']; <th id="headerPassword"><?php echo $l->t( 'Password' ); ?></th> <th id="headerGroups"><?php echo $l->t( 'Groups' ); ?></th> <?php if(is_array($_['subadmins']) || $_['subadmins']): ?> - <th id="headerSubAdmins"><?php echo $l->t('SubAdmins'); ?></th> + <th id="headerSubAdmins"><?php echo $l->t('SubAdmin'); ?></th> <?php endif;?> <th id="headerQuota"><?php echo $l->t( 'Quota' ); ?></th> <th id="headerRemove"> </th> @@ -74,9 +78,10 @@ $_['subadmingroups'] = $_['groups']; <td class="name"><?php echo $user["name"]; ?></td> <td class="password"><span>●●●●●●●</span> <img class="svg action" src="<?php echo image_path('core','actions/rename.svg')?>" - alt="set new password" title="set new password" /> + alt="set new password" title="set new password"/> </td> <td class="groups"><select + class="groupsselect" data-username="<?php echo $user['name'] ;?>" data-user-groups="<?php echo $user['groups'] ;?>" data-placeholder="groups" title="<?php echo $l->t('Groups')?>" @@ -90,13 +95,14 @@ $_['subadmingroups'] = $_['groups']; </td> <?php if(is_array($_['subadmins']) || $_['subadmins']): ?> <td class="subadmins"><select + class="subadminsselect" data-username="<?php echo $user['name'] ;?>" - data-user-groups="<?php echo $user['groups'] ;?>" + data-subadmin="<?php echo $user['subadmin'] ;?>" data-placeholder="subadmins" title="<?php echo $l->t('SubAdmin for ...')?>" multiple="multiple"> <?php foreach($_["subadmingroups"] as $group): ?> - <option value="<?php echo $group['name'];?>"> - <?php echo $group['name'];?> + <option value="<?php echo $group;?>"> + <?php echo $group;?> </option> <?php endforeach;?> </select> diff --git a/settings/users.php b/settings/users.php index e066956291b..60ffc337a72 100644 --- a/settings/users.php +++ b/settings/users.php @@ -19,20 +19,20 @@ $groups = array(); $isadmin = OC_Group::inGroup(OC_User::getUser(),'admin')?true:false; if($isadmin){ - $groups = OC_Group::getGroups(); + $accessiblegroups = OC_Group::getGroups(); $accessibleusers = OC_User::getUsers(); $subadmins = OC_SubAdmin::getAllSubAdmins(); }else{ - $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); - $accessibleusers = OC_Group::usersInGroups($groups); + $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); + $accessibleusers = OC_Group::usersInGroups($accessiblegroups); $subadmins = false; } foreach($accessibleusers as $i){ - $users[] = array( "name" => $i, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($i)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/),'quota'=>OC_Preferences::getValue($i,'files','quota','default')); + $users[] = array( "name" => $i, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($i)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/),'quota'=>OC_Preferences::getValue($i,'files','quota','default'),'subadmin'=>implode(', ',OC_SubAdmin::getSubAdminsGroups($i))); } -foreach( $groups as $i ){ +foreach( $accessiblegroups as $i ){ // Do some more work here soon $groups[] = array( "name" => $i ); } @@ -55,7 +55,9 @@ if (\OC_App::isEnabled( "files_sharing" ) ) { $tmpl = new OC_Template( "settings", "users", "user" ); $tmpl->assign( "users", $users ); $tmpl->assign( "groups", $groups ); +$tmpl->assign( 'isadmin', $isadmin); $tmpl->assign( 'subadmins', $subadmins); +$tmpl->assign( 'numofgroups', count($accessiblegroups)); $tmpl->assign( 'quota_preset', $quotaPreset); $tmpl->assign( 'default_quota', $defaultQuota); $tmpl->assign( 'share_notice', $shareNotice); |