public function createAction() { $data = $this->getGroupData($_POST); if (empty($data)) { $this->_redirect("/admin/group/new"); } $table = new USVN_Db_Table_Groups(); $group = $table->createRow($data); $this->view->group = $group; if ($table->isAGroup($data['groups_name'])) { $this->view->message = sprintf(T_("Group %s already exist"), $data['groups_name']); $this->render('new'); return; } try { $group->save(); foreach ($_POST['users'] as $user) { $group->addUser($user); } $this->_redirect("/admin/group/"); } catch (USVN_Exception $e) { $this->view->message = $e->getMessage(); $table = new USVN_Db_Table_Users(); $this->view->users = $table->fetchAll(null, "users_login"); $this->render('new'); } }
/** * Create a project * * @param array Fields data * @param string The creating user * @param bool Create a group for the project * @param bool Add user into group * @param bool Add user as admin for the project * @param bool Create SVN standard directories * @return USVN_Db_Table_Row_Project */ public static function createProject(array $data, $login, $create_group, $add_user_to_group, $create_admin, $create_svn_directories) { //We need check if admin exist before create project because we can't go back $user_table = new USVN_Db_Table_Users(); $user = $user_table->fetchRow(array('users_login = ?' => $login)); if ($user === null) { throw new USVN_Exception(T_('Login %s not found'), $login); } $groups = new USVN_Db_Table_Groups(); if ($create_group) { $group = $groups->fetchRow(array('groups_name = ?' => $data['projects_name'])); if ($group !== null) { throw new USVN_Exception(T_("Group %s already exists."), $data['projects_name']); } } try { $table = new USVN_Db_Table_Projects(); $table->getAdapter()->beginTransaction(); $project = $table->createRow($data); $project->save(); USVN_Project::createProjectSVN($data['projects_name'], $create_svn_directories); if ($create_group) { $group = $groups->createRow(); $group->description = sprintf(T_("Autocreated group for project %s"), $data['projects_name']); $group->name = $data['projects_name']; $group->save(); $project->addGroup($group); USVN_Project::ApplyFileRights($project, $group, $create_svn_directories); } if ($create_group && $add_user_to_group) { $group->addUser($user); $group->promoteUser($user); } if ($create_admin) { $project->addUser($user); } } catch (Exception $e) { $table->getAdapter()->rollBack(); throw $e; } $table->getAdapter()->commit(); return $project; }
public function testHasUserNewGroup() { $groups = new USVN_Db_Table_Groups(); $group = $groups->createRow(); $group->name = 'test'; $group->save(); $user2 = $this->users["test"]; $this->assertFalse($group->hasUser($user2)); }
/** * Save all information * */ public function save() { $this->user->save(); if ($this->createGroup) { $table = new USVN_Db_Table_Groups(); $group = $table->createRow(array("groups_name" => $this->user->login)); try { $group->save(); $this->groups[] = $group->id; } catch (Exception $e) { $table = new USVN_Db_Table_Groups(); $where = $table->getAdapter()->quoteInto('groups_name = ?', $this->user->login); $row = $table->fetchRow($where); if ($row != null) { $this->user->delete(); throw new USVN_Exception(T_("This user can't be created. A group has the same name.")); } else { throw $e; } } } if ($this->groups !== null) { $this->user->deleteAllGroups(); foreach ($this->groups as $group) { $this->user->addGroup($group); } } }
/** * Create and save a group * * @return USVN_Db_Table_Row_Group */ public function createGroup($name) { $table = new USVN_Db_Table_Groups(); try { $group = $table->createRow(array("groups_name" => "{$name}", "groups_description" => "{$name}'s description")); $group->save(); return $group; } catch (Exception $e) { $this->fail($name . " : " . $e->getMessage()); } }