/** * Insert project roles. */ public function insertProjectRoles() { $roles = [['name' => "Manager", 'is_assignable' => true, 'project_id' => 0], ['name' => "Developer", 'is_assignable' => true, 'project_id' => 0], ['name' => "Tester", 'is_assignable' => true, 'project_id' => 0]]; foreach ($roles as $role) { $model = new ProjectRole($role); $model->save(); } }
/** * Add project member. * * @return \Avalon\Http\RedirectResponse|\Avalon\Http\Response */ public function createAction() { $errors = []; $user = User::find('username', Request::$post->get('username')); $role = ProjectRole::find(Request::$post->get('role_id')); // Check if they entered a username if (!Request::$post->has('username') || Request::$post->get('username') == '') { $errors['username'] = $this->translate('errors.validations.required', ['field' => $this->translate('username')]); } elseif (!$user) { $errors['username'] = $this->translate('errors.users.doesnt_exist'); } // Check if the user is already a member of the project if ($user) { $member = UserRole::select('id')->where('project_id = ?')->setParameter(0, $this->currentProject['id'])->andWhere('user_id = ?')->setParameter(1, $user->id)->execute(); } if ($user && isset($member) && $member->rowCount() > 0) { $errors['username'] = $this->translate('errors.users.already_a_project_member'); } // Check if they chose a role if (Request::$post->get('role_id', '') == '') { $errors['role_id'] = $this->translate('errors.validations.required', ['field' => $this->translate('role')]); } // Check if the role exists if (!$role) { $errors['role'] = $this->translate('errors.roles.doesnt_exist'); } // Check if the role belongs to the project if ($role && ($role->project_id != 0 && $role->project_id != $this->currentProject['id'])) { $errors['role'] = $this->translate('errors.roles.invalid_role'); } if (count($errors)) { return $this->render('project_settings/members/new.phtml', ['errors' => $errors]); } else { $userRole = new UserRole(['project_id' => $this->currentProject['id'], 'project_role_id' => $role->id, 'user_id' => $user->id]); $userRole->save(); return $this->redirectTo('project_settings_members'); } }
/** * Fetches all the data for the permission listing page. */ private function permissions_for($type) { // Fetch groups, set permissions and actions arrays if ($type == 'usergroup') { $groups = Group::select()->where('is_admin', 1, '!=')->exec()->fetch_all(); $groups = array_merge(array(new Group(array('id' => 0, 'name' => l('defaults')))), $groups); } elseif ($type == 'role') { $groups = ProjectRole::select()->custom_sql("WHERE project_id = 0 OR project_id = {$this->project->id}")->exec()->fetch_all(); $groups = array_merge(array(new ProjectRole(array('id' => 0, 'name' => l('defaults'), 'project_id' => 0))), $groups); } $permissions = array(); // Loop over the groups foreach ($groups as $group) { // Set the group array in the permissions array if (!isset($permissions[$group->id])) { $permissions[$group->id] = array(); } // Loop over the permissions for the group foreach (Permission::get_permissions($this->project->id, $group->id, $type) as $action => $perm) { // Add the permission object to the permissions array $permissions[$group->id][$action] = $perm; } } // Send it all the to view. View::set('groups', $groups); View::set('permissions', $permissions); View::set('actions', permission_actions()); }
protected function getAllRows() { return ProjectRole::select('project_role.*', 'project.name AS project_name')->leftJoin('project_role', PREFIX . 'projects', 'project', 'project.id = project_role.project_id')->execute()->fetchAll(); }
function createProjectManager($project = null, $user = null) { if (!$project) { $project = createProject(); } if (!$user) { $user = createUser(); } $role = ProjectRole::find(1); $relation = new UserRole(['user_id' => $user['id'], 'project_id' => $project['id'], 'project_role_id' => $role['id']]); $relation->save(); return $relation; }