Commit 2314e91adc7cc8e55fa7c3df8a99209c17280db5

Authored by nbm
1 parent 4a04ddec

Allow the admin to remove a group despite it having members, since

all they're going to do is remove the users from that group, and remove
a group despite it being a member of the unit, since all they're going
to do is remove it from the unit.  So do it for them.  They still have
to confirm that they want to delete that group.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3114 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/groups/Group.inc
... ... @@ -209,7 +209,40 @@ class Group extends KTEntity {
209 209 $sName = lookupField("$default->groups_table", "name", "id", $id );
210 210 return $sName;
211 211 }
  212 +
  213 + function &getMembers() {
  214 + require_once(KT_LIB_DIR . '/groups/GroupUserLink.inc');
  215 + require_once(KT_LIB_DIR . '/users/User.inc');
  216 + $aLinks = GroupUserLink::getList(array('group_id = ?', $this->getID()));
  217 + $aMembers = array();
  218 + foreach ($aLinks as $oLink) {
  219 + $oUser = User::get($oLink->getUserID());
  220 + if ($oUser !== false) {
  221 + $aMembers[] =& $oUser;
  222 + }
  223 + }
  224 + return $aMembers;
  225 + }
  226 +
  227 + function delete() {
  228 + require_once(KT_LIB_DIR . '/groups/GroupUserLink.inc');
  229 + require_once(KT_LIB_DIR . '/groups/GroupUnitLink.inc');
  230 +
  231 + // XXX: Urg, should I just DELETE instead?
  232 + $aLinks = GroupUserLink::getList(array('group_id = ?', $this->getID()));
  233 + foreach ($aLinks as $oLink) {
  234 + $oLink->delete();
  235 + }
  236 +
  237 + $aLinks = GroupUnitLink::getList(array('group_id = ?', $this->getID()));
  238 + foreach ($aLinks as $oLink) {
  239 + $oLink->delete();
  240 + }
  241 + return parent::delete();
  242 + }
212 243 }
  244 +
  245 +
213 246 /*
214 247 * static function
215 248 *
... ...
presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php
... ... @@ -45,29 +45,21 @@ if (checkSession()) {
45 45  
46 46 if (isset($fGroupID)) {
47 47 $oGroup = Group::get($fGroupID);
48   - if (!$oGroup->hasUsers()) {
49   - if (!$oGroup->hasUnit()) {
50   - if (!$oGroup->hasRoutingSteps()) {
51   - if (isset($fForDelete)) {
52   - if ($oGroup->delete()) {
53   - // FIXME: refactor getStatusPage in Html.inc
54   - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group successfully removed"), "", "listGroups"));
55   - } else {
56   - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group deletion failed!"), _("There was an error deleting this group. Please try again later."), "listGroups"));
57   - }
58   - } else {
59   - $oPatternCustom->setHtml(getDeletePage($fGroupID));
60   - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDelete=1");
61   - }
62   - } else {
63   - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is part of a document routing step!"), _("This group can not be deleted because it is involved in the document routing process."), "listGroups"));
64   - }
65   - } else {
66   - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is in a unit!"), _("This group can not be deleted because it belongs to a unit."), "listGroups"));
67   - }
68   - } else {
69   - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group has users!"), _("This group can not be deleted because there are still users in it."), "listGroups"));
70   - }
  48 + if (!$oGroup->hasRoutingSteps()) {
  49 + if (isset($fForDelete)) {
  50 + if ($oGroup->delete()) {
  51 + // FIXME: refactor getStatusPage in Html.inc
  52 + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group successfully removed"), "", "listGroups"));
  53 + } else {
  54 + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group deletion failed!"), _("There was an error deleting this group. Please try again later."), "listGroups"));
  55 + }
  56 + } else {
  57 + $oPatternCustom->setHtml(getDeletePage($fGroupID));
  58 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDelete=1");
  59 + }
  60 + } else {
  61 + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is part of a document routing step!"), _("This group can not be deleted because it is involved in the document routing process."), "listGroups"));
  62 + }
71 63 } else {
72 64 $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("No group was selected for deletion"), "", "listGroups"));
73 65 }
... ...