/** * Prepare `Aco` and `Aro` identifiers to be used for finding Acos and Aros nodes */ protected function _prepareAcl() { $request = $this->request->params; $user = $this->_user; $guest = $this->_guest; $buildAroPath = function ($group = null, $path = array()) use(&$buildAroPath) { $parent = null; $path[] = Inflector::pluralize($group['slug']); if ($group['parent_id']) { $parent = UserGroups::first(array('conditions' => array('parent_id' => $group['parent_id']))); } if ($parent) { return $buildAroPath($parent, $path); } return join('/', $path); }; $prepareAco = function () use($request) { extract($request); $library = isset($library) ? $library . '/' : ''; return $library . 'controllers/' . $controller; }; $prepareAro = function () use($user, $guest, $buildAroPath) { if ($guest) { return 'guests'; } return 'users/' . $buildAroPath($user['user_group']); }; $this->_aco = $prepareAco(); $this->_aro = $prepareAro(); }
/** * Promote user to root if no root in user table * `li3 usermanager root <username>` */ protected function _root() { $root = Users::first(array('conditions' => array('UserGroups.slug' => 'root'), 'with' => 'UserGroups')); if ($root) { $output = array(array('ID', 'Username'), array('---', '----------'), array($root->id, $root->username)); $this->error('Root user already exists!'); $this->columns($output); return false; } $username = $this->request->args[0]; $user = Users::first(array('conditions' => compact('username'))); if (!$user) { $this->error("There is not user with username: {$username}"); } $root = UserGroups::first(array('conditions' => array('slug' => 'root'))); $user->user_group_id = $root->id; $user->save(); return true; }
/** * Promote user to other user group */ public function backend_promote() { if ($id = $this->request->params['id']) { $groups = array(); $manageUsers = array('li3_usermanager.ManageUsers::index', 'backend' => true); foreach (UserGroups::all() as $group) { $groups[$group->id] = $group->slug; } $user = Users::first(array('conditions' => compact('id'))); if ($this->request->data) { $user->user_group_id = $this->request->data['user_group_id']; if ($user->save()) { return $this->redirect($manageUsers); } } if ($user) { return compact('user', 'groups'); } } return $this->redirect($manageUsers); }