From 79335561029a46374e202407ff60200691a3ec1f Mon Sep 17 00:00:00 2001 From: Joubert RedRat Date: Fri, 29 May 2015 11:23:33 -0300 Subject: [PATCH] First step on assign subgroups to a groups, on member page is possible to associate users or/and groups to a groups --- actions/assign_togroup.php | 98 +++++++++++++++++++ actions/assign_usertogroup.php | 66 ------------- .../interfaces/IGroupEditProvider.iface.php | 17 +++- .../AuthFileGroupAndPathsProvider.class.php | 9 ++ usergroupassign.php => groupassign.php | 6 +- include/ifcorelib/IF_SVNAuthFileC.class.php | 94 ++++++++++++++++-- pages/global-navigation.php | 2 +- pages/group/membership.html.php | 26 ++++- translations/pt_BR/groupassign.txt | 7 ++ translations/pt_BR/groupcreate.txt | 3 +- translations/pt_BR/login.txt | 3 +- translations/pt_BR/usergroupassign.txt | 2 - translations/pt_BR/userview.txt | 2 +- 13 files changed, 243 insertions(+), 92 deletions(-) create mode 100644 actions/assign_togroup.php delete mode 100644 actions/assign_usertogroup.php rename usergroupassign.php => groupassign.php (95%) create mode 100644 translations/pt_BR/groupassign.txt delete mode 100644 translations/pt_BR/usergroupassign.txt diff --git a/actions/assign_togroup.php b/actions/assign_togroup.php new file mode 100644 index 0000000..a5405ef --- /dev/null +++ b/actions/assign_togroup.php @@ -0,0 +1,98 @@ +forwardInvalidModule( !$appEngine->isGroupEditActive() ); + +// Parameters. +$selusers = get_request_var('selusers'); +$selgroups = get_request_var('selgroups'); +$selsubgroups = get_request_var('selsubgroups'); + +if ($selusers == NULL) + $selusers = get_request_var("selected_users"); + +if ($selgroups == NULL) + $selgroups = get_request_var("selected_groups"); + +if ($selsubgroups == NULL) + $selsubgroups = get_request_var("selected_subgroups"); + +if ($selusers != NULL && count($selusers) > 0 && empty($selusers[0])) +{ + $selusers = NULL; +} + +if ($selgroups != NULL && count($selgroups) > 0 && empty($selgroups[0])) +{ + $selgroups = NULL; +} + +if ($selsubgroups != NULL && count($selsubgroups) > 0 && empty($selsubgroups[0])) +{ + $selsubgroups = NULL; +} + +// Validate. +if( ($selusers == NULL && $selsubgroups == NULL) || $selgroups == NULL ) +{ + $appEngine->addException(new ValidationException(tr("You have to select at least one user and one group."))); +} +// Do assignments. +else +{ + // Count of: All, Done, Failed + $cntAll = count($selgroups) * count($selusers); + try + { + // Iterate all selected users and groups. + for( $i=0; $iid = $selgroups[$i]; + $oG->name = $selgroups[$i]; + + for( $k=0; $kid = $selsubgroups[$k]; + $oS->name = $selsubgroups[$k]; + if ($oG->name != $oS->name) + { + if ($appEngine->getGroupEditProvider()->assignSubgroupToGroup($oS, $oG)) + { + $appEngine->getGroupEditProvider()->save(); + $appEngine->addMessage(tr("The group %0 is now a member of group %1", array($oS->name, $oG->name))); + } + else + { + $appEngine->addException(new Exception(tr("Can not add group %0 as member of group %1.", array($oS->name, $oG->name)))); + } + } + else + { + $appEngine->addException(new Exception(tr("Can not add group %0 as member of group %1, is same group.", array($oS->name, $oG->name)))); + } + } //for + + for( $j=0; $jid = $selusers[$j]; + $oU->name = $selusers[$j]; + + if ($appEngine->getGroupEditProvider()->assignUserToGroup($oU, $oG)) + { + $appEngine->getGroupEditProvider()->save(); + $appEngine->addMessage(tr("The user %0 is now a member of group %1", array($oU->name, $oG->name))); + } + else + { + $appEngine->addException(new Exception(tr("Can not add user %0 as member of group %1.", array($oU->name, $oG->name)))); + } + } //for + } //for + } + catch (Exception $ex) + { + $appEngine->addException($ex); + } +} +?> \ No newline at end of file diff --git a/actions/assign_usertogroup.php b/actions/assign_usertogroup.php deleted file mode 100644 index b06f1db..0000000 --- a/actions/assign_usertogroup.php +++ /dev/null @@ -1,66 +0,0 @@ -forwardInvalidModule( !$appEngine->isGroupEditActive() ); - -// Parameters. -$selusers = get_request_var('selusers'); -$selgroups = get_request_var('selgroups'); - -if ($selusers == NULL) - $selusers = get_request_var("selected_users"); - -if ($selgroups == NULL) - $selgroups = get_request_var("selected_groups"); - -if ($selusers != NULL && count($selusers) > 0 && empty($selusers[0])) -{ - $selusers = NULL; -} - -if ($selgroups != NULL && count($selgroups) > 0 && empty($selgroups[0])) -{ - $selgroups = NULL; -} - -// Validate. -if( $selusers == NULL || $selgroups == NULL ) -{ - $appEngine->addException(new ValidationException(tr("You have to select at least one user and one group."))); -} -// Do assignments. -else -{ - // Count of: All, Done, Failed - $cntAll = count($selgroups) * count($selusers); - try - { - // Iterate all selected users and groups. - for( $i=0; $iid = $selgroups[$i]; - $oG->name = $selgroups[$i]; - - for( $j=0; $jid = $selusers[$j]; - $oU->name = $selusers[$j]; - - if ($appEngine->getGroupEditProvider()->assignUserToGroup($oU, $oG)) - { - $appEngine->getGroupEditProvider()->save(); - $appEngine->addMessage(tr("The user %0 is now a member of group %1", array($oU->name, $oG->name))); - } - else - { - $appEngine->addException(new Exception(tr("Can not add user %0 as member of group %1.", array($oU->name, $oG->name)))); - } - } //for - } //for - } - catch (Exception $ex) - { - $appEngine->addException($ex); - } -} -?> diff --git a/classes/core/interfaces/IGroupEditProvider.iface.php b/classes/core/interfaces/IGroupEditProvider.iface.php index a83595d..2733ae4 100644 --- a/classes/core/interfaces/IGroupEditProvider.iface.php +++ b/classes/core/interfaces/IGroupEditProvider.iface.php @@ -34,24 +34,31 @@ public function addGroup( $objGroup ); * @return bool */ public function deleteGroup( $objGroup ); - + /** * Assigns the user to group. * @param $objUser * @param $objGroup - * @return bool + * @return bool */ public function assignUserToGroup( $objUser, $objGroup ); - + + /** + * Assigns the subgroup to group. + * @param $objSubgroup + * @param $objGroup + * @return bool + */ + public function assignSubgroupToGroup( $objSubgroup, $objGroup ); + /** * Removes the user from group. * @param $objUser * @param $objGroup * @return bool - */ + */ public function removeUserFromGroup( $objUser, $objGroup ); - /** * Removes the user from all groups where he is associated. * @param User $objUser diff --git a/classes/providers/AuthFileGroupAndPathsProvider.class.php b/classes/providers/AuthFileGroupAndPathsProvider.class.php index 427ee22..d0d6d23 100644 --- a/classes/providers/AuthFileGroupAndPathsProvider.class.php +++ b/classes/providers/AuthFileGroupAndPathsProvider.class.php @@ -225,6 +225,15 @@ public function assignUserToGroup( $objUser, $objGroup ) return $this->m_authfile->addUserToGroup( $objGroup->name, $objUser->name ); } + /** + * (non-PHPdoc) + * @see svnadmin\core\interfaces.IGroupEditProvider::assignSubgroupToGroup() + */ + public function assignSubgroupToGroup( $objSubgroup, $objGroup ) + { + return $this->m_authfile->addSubgroupToGroup( $objGroup->name, $objSubgroup->name ); + } + /** * (non-PHPdoc) * @see svnadmin\core\interfaces.IGroupEditProvider::removeUserFromGroup() diff --git a/usergroupassign.php b/groupassign.php similarity index 95% rename from usergroupassign.php rename to groupassign.php index 55cb76e..e653703 100644 --- a/usergroupassign.php +++ b/groupassign.php @@ -27,13 +27,13 @@ $appEngine->checkUserAuthentication(true, ACL_MOD_GROUP, ACL_ACTION_ASSIGN); // Load language. -$appTR->loadModule("usergroupassign"); +$appTR->loadModule("groupassign"); // Form request. $assign = check_request_var('assign'); if($assign) { - $appEngine->handleAction('assign_usertogroup'); + $appEngine->handleAction('assign_togroup'); } // User list. @@ -46,7 +46,7 @@ $o = new \svnadmin\core\entities\User; $o->id = '*'; $o->name = '*'; - + $users = remove_item_by_value($users, $o, true); usort($users, array('\svnadmin\core\entities\User',"compare")); } diff --git a/include/ifcorelib/IF_SVNAuthFileC.class.php b/include/ifcorelib/IF_SVNAuthFileC.class.php index 8c0e854..9875818 100644 --- a/include/ifcorelib/IF_SVNAuthFileC.class.php +++ b/include/ifcorelib/IF_SVNAuthFileC.class.php @@ -107,10 +107,10 @@ public function save($path = null) } return false; } - + /** * Gets all existing aliases. - * + * * @return array */ public function aliases() @@ -148,13 +148,13 @@ public function repositories() return $ret; } - + /** * Resolves the given alias to its real value. - * + * * @param string $alias - * - * @return string + * + * @return string */ public function getAliasValue($alias) { @@ -183,7 +183,10 @@ public function usersOfGroup($group) for ($i = 0; $i < $arrUsersLen; ++$i) { - $arrUsers[$i] = trim($arrUsers[$i]); + if (strpos($arrUsers[$i], '@') === false) + $arrUsers[$i] = trim($arrUsers[$i]); + else + unset($arrUsers[$i]); } return $arrUsers; @@ -192,6 +195,36 @@ public function usersOfGroup($group) return array(); } + /** + * Gets all subgroups of the given group. + * + * @param string $group + * + * @return array + */ + public function groupsOfGroup($group) + { + $groupString = $this->config->getValue($this->GROUP_SECTION, $group); + + if ($groupString != null) + { + $arrGroups = explode(',', $groupString); + $arrGroupsLen = count($arrGroups); + + for ($i = 0; $i < $arrGroupsLen; ++$i) + { + if(strpos($arrGroups[$i], '@') !== false) + $arrGroups[$i] = str_replace('@', '', trim($arrGroups[$i])); + else + unset($arrGroups[$i]); + } + + return $arrGroups; + } + + return array(); + } + /** * Gets all assigned members and groups which are directly assigned * to the given repository path. @@ -469,9 +502,11 @@ public function addUserToGroup($groupname, $username) return false; } - // Get current users. + // Get current users and groups. $users = $this->usersOfGroup($groupname); - if (!is_array($users)) + $groups = $this->groupsOfGroup($groupname); + + if (!is_array($users) || !is_array($groups)) { return false; } @@ -487,10 +522,49 @@ public function addUserToGroup($groupname, $username) $users[] = $username; // Set changes to config. - $this->config->setValue($this->GROUP_SECTION, $groupname, join(',', $users)); + $this->config->setValue($this->GROUP_SECTION, $groupname, ($groups ? '@' . join(',@', $groups) . ',' : '') . join(',', $users)); return true; } + /** + * Adds the subgroup to group. + * + * @param string $groupname + * @param string $subgroupname + * + * @return bool + */ + public function addSubgroupToGroup($groupname, $subgroupname) + { + if (!self::groupExists($groupname) || !self::groupExists($subgroupname)) + { + return false; + } + + // Get current users and groups. + $users = $this->usersOfGroup($groupname); + $groups = $this->groupsOfGroup($groupname); + + if (!is_array($users) || !is_array($groups)) + { + return false; + } + + // NOTE: Its no longer an error when the subgroup is already in group!!! + // Check whether the subgroup is already in group. + if (in_array($subgroupname, $groups)) + { + return true; + } + + // Add subgroup to groups array. + $groups[] = $subgroupname; + + // Set changes to config. + $this->config->setValue($this->GROUP_SECTION, $groupname, '@' . join(',@', $groups) . ($users ? ',' . join(',', $users) : '')); + return true; + } + /** * Checks whether the user is in the given group. * diff --git a/pages/global-navigation.php b/pages/global-navigation.php index 7030c51..4811aa3 100644 --- a/pages/global-navigation.php +++ b/pages/global-navigation.php @@ -26,7 +26,7 @@
  • -
  • +
diff --git a/pages/group/membership.html.php b/pages/group/membership.html.php index a0f226d..840c150 100644 --- a/pages/group/membership.html.php +++ b/pages/group/membership.html.php @@ -8,13 +8,16 @@ $("#selectallgroups").click(function(){ selectAll(this, "selgroups[]"); }); + $("#selectallsubgroups").click(function(){ + selectAll(this, "selsubgroups[]"); + }); }); -

+

-
+ @@ -40,6 +43,25 @@
+ + + + + + + + + + + + + + + + + +
name); ?>
+ diff --git a/translations/pt_BR/groupassign.txt b/translations/pt_BR/groupassign.txt new file mode 100644 index 0000000..f77ac68 --- /dev/null +++ b/translations/pt_BR/groupassign.txt @@ -0,0 +1,7 @@ +"User and Group <> Group assignment","Usuários e grupos <> Associar aos Grupos" +"Here you can assign users to groups.","Aqui você pode associar os usuários aos grupos." +"The group %0 is now a member of group %1","O grupo %0 agora é membro do grupo %1" +"Can not add group %0 as member of group %1.","Não foi possível adicionar %0 como membro do grupo %1." +"Can not add group %0 as member of group %1, is same group.", "Não foi possível adicionar %0 como membro do grupo %1, é o mesmo grupo." +"The user %0 is now a member of group %1","O usuário %0 agora é membro do grupo %1" +"Can not add user %0 as member of group %1.","Não foi possível %0 como membro do grupo %1." \ No newline at end of file diff --git a/translations/pt_BR/groupcreate.txt b/translations/pt_BR/groupcreate.txt index d6c8234..845c023 100644 --- a/translations/pt_BR/groupcreate.txt +++ b/translations/pt_BR/groupcreate.txt @@ -3,4 +3,5 @@ "New group data","Novo dado de grupo" "Group name","Nome do grupo" "Valid group names are","Nomes válidos para o grupo são" -"Invalid group names are","Nomes inválidos para o grupo são" \ No newline at end of file +"Invalid group names are","Nomes inválidos para o grupo são" +"Invalid group name", "Nome de grupo inválido" \ No newline at end of file diff --git a/translations/pt_BR/login.txt b/translations/pt_BR/login.txt index 4fc2310..d55cf35 100644 --- a/translations/pt_BR/login.txt +++ b/translations/pt_BR/login.txt @@ -1,4 +1,5 @@ "You must login to get access to the application.","Você precisa fazer login para acessar o aplicativo" "Username","Usuario" "Password","Senha" -"You are now logged out.","Agora você está desconectado." \ No newline at end of file +"You are now logged out.","Agora você está desconectado." +"Wrong user/password combination.","Usuário ou senha incorretos" \ No newline at end of file diff --git a/translations/pt_BR/usergroupassign.txt b/translations/pt_BR/usergroupassign.txt deleted file mode 100644 index 8559653..0000000 --- a/translations/pt_BR/usergroupassign.txt +++ /dev/null @@ -1,2 +0,0 @@ -"User <> Group assignment","Usuários <> Associar aos Grupos" -"Here you can assign users to groups.","Aqui você pode associar os usuários aos grupos." \ No newline at end of file diff --git a/translations/pt_BR/userview.txt b/translations/pt_BR/userview.txt index bd45d5f..97b7736 100644 --- a/translations/pt_BR/userview.txt +++ b/translations/pt_BR/userview.txt @@ -3,4 +3,4 @@ "Permissions of users","Permissões do usuário" "Inherit from Group","Herdar do grupo" "Note: You can not unassign permissions from user, which are inherited by a group.","Nota: Você não pode desassociar permissões de um usuário que são herdadas do grupo." -"User is project manager of:","El usuario es gestor de proyecto de:" \ No newline at end of file +"User is project manager of:","O usuário é gestor de projeto de:" \ No newline at end of file