function hasMember($oUser)
 {
     $oPD = $this->getPermissionDescriptor();
     if (PEAR::isError($oPD) || $oPD == false) {
         return false;
     }
     $aAllowed = $oPD->getAllowed();
     $iUserId = $oUser->getId();
     if ($aAllowed['user'] != null) {
         if (array_search($iUserId, $aAllowed['user']) !== false) {
             return true;
         }
     }
     // now we need the group objects.
     // FIXME this could accelerated to a single SQL query on group_user_link.
     $aGroups = $this->getGroups();
     if (PEAR::isError($aGroups) || $aGroups == false) {
         return false;
     } else {
         foreach ($aGroups as $oGroup) {
             $reason = GroupUtil::getMembershipReason($oUser, $oGroup);
             if (PEAR::isError($reason) || is_null($reason)) {
                 continue;
             }
             return true;
             // don't bother continuing - short-circuit for performance.
         }
     }
     return false;
 }
Example #2
0
 function getGroupStringForUser($oUser)
 {
     $aGroupNames = array();
     $aGroups = GroupUtil::listGroupsForUser($oUser);
     $MAX_GROUPS = 6;
     $add_elipsis = false;
     if (count($aGroups) == 0) {
         return _kt('User is currently not a member of any groups.');
     }
     if (count($aGroups) > $MAX_GROUPS) {
         $aGroups = array_slice($aGroups, 0, $MAX_GROUPS);
         $add_elipsis = true;
     }
     foreach ($aGroups as $oGroup) {
         $aGroupNames[] = $oGroup->getName();
     }
     if ($add_elipsis) {
         $aGroupNames[] = '…';
     }
     return implode(', ', $aGroupNames);
 }
 function allowTransition($oDocument, $oUser)
 {
     if (!$this->isLoaded()) {
         return true;
     }
     $iGroupId = $this->aConfig['group_id'];
     $oGroup = Group::get($this->aConfig['group_id']);
     if (PEAR::isError($oGroup)) {
         return true;
         // fail safe for cases where the role is deleted.
     }
     $res = GroupUtil::getMembershipReason($oUser, $oGroup);
     if (PEAR::isError($res) || empty($res)) {
         // broken setup, or no reason
         return false;
     } else {
         return true;
     }
 }
 function json_getSubGroups()
 {
     $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false);
     $aAllowedGroups = array('off' => _kt('-- Please filter --'));
     if ($sFilter && trim($sFilter)) {
         $iGroupID = KTUtil::arrayGet($_REQUEST, 'group_id', false);
         if (!$iGroupID) {
             return array('error' => true, 'type' => 'kt.invalid_entity', 'message' => _kt('An invalid group was selected'));
         }
         $oGroup = Group::get($iGroupID);
         $aMemberGroupsUnkeyed = $oGroup->getMemberGroups();
         $aMemberGroups = array();
         $aMemberIDs = array();
         foreach ($aMemberGroupsUnkeyed as $oMemberGroup) {
             $aMemberIDs[] = $oMemberGroup->getID();
             $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup;
         }
         $aGroupArray = GroupUtil::buildGroupArray();
         $aAllowedGroupIDs = GroupUtil::filterCyclicalGroups($oGroup->getID(), $aGroupArray);
         $aAllowedGroupIDs = array_diff($aAllowedGroupIDs, $aMemberIDs);
         $aAllowedGroups = array();
         foreach ($aAllowedGroupIDs as $iAllowedGroupID) {
             $g = Group::get($iAllowedGroupID);
             if (!PEAR::isError($g) && $g != false) {
                 $aAllowedGroups[$iAllowedGroupID] = $g->getName();
             }
         }
     }
     return $aAllowedGroups;
 }
 function getPermissionDescriptorsForUser($oUser)
 {
     $aGroups = GroupUtil::listGroupsForUserExpand($oUser);
     $roles = array(-3);
     // everyone
     $aEveryoneDescriptors = array();
     $aAuthenticatedDescriptors = array();
     if (!$oUser->isAnonymous()) {
         // authenticated
         $roles[] = -4;
     }
     $aRoleDescriptors = KTPermissionDescriptor::getByRoles($roles, array('ids' => true));
     $aPermissionDescriptors = KTPermissionDescriptor::getByGroups($aGroups, array('ids' => true));
     $aUserDescriptors = KTPermissionDescriptor::getByUser($oUser, array('ids' => true));
     return kt_array_merge($aPermissionDescriptors, $aUserDescriptors, $aRoleDescriptors);
 }
Example #6
0
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
foreach (GroupUtil::listGroups() as $oGroup) {
    print $oGroup->getName() . "\n";
}
Example #7
0
 function json_getUsers()
 {
     $oConfig = KTConfig::getSingleton();
     $bOnlyOwnGroup = $oConfig->get('email/onlyOwnGroups', false);
     $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false);
     $aUserList = array('off' => _kt('-- Please filter --'));
     if ($sFilter && trim($sFilter)) {
         $sWhere = sprintf('name LIKE \'%%%s%%\' AND disabled = \'0\'', $sFilter);
         if ($bOnlyOwnGroup != true) {
             $aUsers = User::getEmailUsers($sWhere);
         } else {
             $aGroups = GroupUtil::listGroupsForUser($this->oUser);
             $aMembers = array();
             foreach ($aGroups as $oGroup) {
                 $aMembers = kt_array_merge($aMembers, $oGroup->getMembers());
             }
             $aUsers = array();
             $aUserIds = array();
             foreach ($aMembers as $oUser) {
                 if (in_array($oUser->getId(), $aUserIds)) {
                     continue;
                 }
                 $aUsers[] = $oUser;
             }
         }
         $aUserList = array();
         foreach ($aUsers as $u) {
             $aUserList[$u->getId()] = $u->getName();
         }
     }
     return $aUserList;
 }
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
$oUser = User::get(1);
foreach (GroupUtil::listGroupsForUser($oUser) as $oGroup) {
    print $oGroup->getName() . "\n";
}
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
error_reporting(E_ALL);
$oUser =& User::get(4);
$aGroups = GroupUtil::listGroupsForUserExpand($oUser);
var_dump($aGroups);
Example #10
0
 function getMembershipReason($oUser, $oGroup)
 {
     $aGroupArray = GroupUtil::buildGroupArray();
     // short circuit
     if ($oGroup->hasMember($oUser)) {
         return sprintf(_kt('%s is a direct member.'), $oUser->getName());
     }
     $aSubgroups = (array) $aGroupArray[$oGroup->getId()];
     if (empty($aSubgroups)) {
         return null;
         // not a member, no subgroups.
     }
     $sTable = KTUtil::getTableName('users_groups');
     $sQuery = 'SELECT group_id FROM ' . $sTable . ' WHERE user_id = ? AND group_id IN (' . DBUtil::paramArray($aSubgroups) . ')';
     $aParams = array($oUser->getId());
     $aParams = kt_array_merge($aParams, $aSubgroups);
     $res = DBUtil::getOneResult(array($sQuery, $aParams));
     if (PEAR::isError($res)) {
         return $res;
     } else {
         if (is_null($res)) {
             return null;
             // not a member
         }
     }
     // else {
     $oSubgroup = Group::get($res['group_id']);
     if (PEAR::isError($oSubgroup)) {
         return $oSubgroup;
     }
     return sprintf(_kt('%s is a member of %s'), $oUser->getName(), $oSubgroup->getName());
     // could be error, but errors are caught.
     // }
 }
Example #11
0
 function do_assistance()
 {
     $sSubject = $this->oValidator->validateString($_REQUEST['subject']);
     $sDetails = $this->oValidator->validateString($_REQUEST['details']);
     $aUsers = array();
     $aGroups = array();
     $aRoles = array();
     foreach (Group::getAdministratorGroups() as $oGroup) {
         $aGroups[$oGroup->getId()] =& $oGroup;
     }
     foreach (Unit::getUnitsForFolder($this->oDocument->getFolderId()) as $oUnit) {
         foreach (Group::getUnitAdministratorGroupsByUnit($oUnit) as $oGroup) {
             $aGroups[$oGroup->getId()] =& $oGroup;
         }
     }
     $aRoles[-2] = Role::get(-2);
     $oDocument =& $this->oDocument;
     foreach ($aRoles as $oRole) {
         // Ignore anonymous or Everyone roles
         $iRoleId = KTUtil::getId($oRole);
         if ($iRoleId == -3 || $iRoleId == -4) {
             continue;
         }
         // first try on the document, then the folder above it.
         $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId);
         if (is_null($oRoleAllocation)) {
             // if we don't get a document role, try folder role.
             $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId());
         }
         if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) {
             continue;
         }
         $aRoleUsers = $oRoleAllocation->getUsers();
         $aRoleGroups = $oRoleAllocation->getGroups();
         foreach ($aRoleUsers as $id => $oU) {
             $aUsers[$id] = $oU;
         }
         foreach ($aRoleGroups as $id => $oGroup) {
             $aGroups[$id] = $oGroup;
         }
     }
     $aGroupMembershipSet = GroupUtil::buildGroupArray();
     $aAllIds = array_keys($aGroups);
     foreach ($aGroups as $id => $oGroup) {
         $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds);
     }
     foreach ($aAllIds as $id) {
         if (!array_key_exists($id, $aGroups)) {
             $aGroups[$id] = Group::get($id);
         }
     }
     // now, merge this (again) into the user-set.
     foreach ($aGroups as $oGroup) {
         $aNewUsers = $oGroup->getMembers();
         foreach ($aNewUsers as $oU) {
             $id = $oU->getId();
             if (!array_key_exists($id, $aUsers)) {
                 $aUsers[$id] = $oU;
             }
         }
     }
     foreach ($aUsers as $oU) {
         if (!PEAR::isError($oU)) {
             KTAssistNotification::newNotificationForDocument($this->oDocument, $oU, $this->oUser, $sSubject, $sDetails);
         }
     }
     $this->commitTransaction();
     $params = 'fDocumentId=' . $oDocument->getId();
     $url = generateControllerLink('viewDocument', $params);
     exit(redirect($url));
 }
Example #12
0
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
error_reporting(E_ALL);
$aGroupMembers = array(1 => array(3, 4), 2 => array(9), 3 => null, 4 => array(5), 5 => null, 6 => array(1), 7 => array(2, 3), 8 => array(1, 7));
$aExpectedRet = array(1 => array(3, 4, 5), 2 => array(9), 3 => null, 4 => array(5), 5 => null, 6 => array(1, 3, 4, 5), 7 => array(2, 3, 9), 8 => array(1, 2, 3, 4, 5, 7, 9));
$aRet = GroupUtil::expandGroupArray($aGroupMembers);
if ($aRet === $aExpectedRet) {
    print "Success!\n";
} else {
    print "Failure!\n";
    print "Expected: \n";
    print_r($aExpectedRet);
    print "Received: \n";
    print_r($aRet);
}
Example #13
0
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
var_dump(GroupUtil::buildGroupArray());
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
error_reporting(E_ALL);
$oUser =& User::get(4);
$aGroups = GroupUtil::_listGroupIDsForUserExpand($oUser);
var_dump($aGroups);
 function informUsersForState($oState, $aInformed, $oDocument, $oUser, $sComments)
 {
     // say no to duplicates.
     KTWorkflowNotification::clearNotificationsForDocument($oDocument);
     $aUsers = array();
     $aGroups = array();
     $aRoles = array();
     foreach (KTUtil::arrayGet($aInformed, 'user', array()) as $iUserId) {
         $oU = User::get($iUserId);
         if (PEAR::isError($oU) || $oU == false) {
             continue;
         } else {
             $aUsers[$oU->getId()] = $oU;
         }
     }
     foreach (KTUtil::arrayGet($aInformed, 'group', array()) as $iGroupId) {
         $oG = Group::get($iGroupId);
         if (PEAR::isError($oG) || $oG == false) {
             continue;
         } else {
             $aGroups[$oG->getId()] = $oG;
         }
     }
     foreach (KTUtil::arrayGet($aInformed, 'role', array()) as $iRoleId) {
         $oR = Role::get($iRoleId);
         if (PEAR::isError($oR) || $oR == false) {
             continue;
         } else {
             $aRoles[] = $oR;
         }
     }
     // FIXME extract this into a util - I see us using this again and again.
     // start with roles ... roles _only_ ever contain groups.
     foreach ($aRoles as $oRole) {
         // do NOT alert anonymous or Everyone roles - that would be very scary.
         $iRoleId = KTUtil::getId($oRole);
         if ($iRoleId == -3 || $iRoleId == -4) {
             continue;
         }
         // first try on the document, then the folder above it.
         $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId);
         if (is_null($oRoleAllocation)) {
             // if we don't get a document role, try folder role.
             $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId());
         }
         if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) {
             continue;
         }
         $aRoleUsers = $oRoleAllocation->getUsers();
         $aRoleGroups = $oRoleAllocation->getGroups();
         foreach ($aRoleUsers as $id => $oU) {
             $aUsers[$id] = $oU;
         }
         foreach ($aRoleGroups as $id => $oGroup) {
             $aGroups[$id] = $oGroup;
         }
     }
     // we now have a (potentially overlapping) set of groups, which may
     // have subgroups.
     //
     // what we need to do _now_ is build a canonical set of groups, and then
     // generate the singular user-base.
     $aGroupMembershipSet = GroupUtil::buildGroupArray();
     $aAllIds = array_keys($aGroups);
     foreach ($aGroups as $id => $oGroup) {
         $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds);
     }
     foreach ($aAllIds as $id) {
         if (!array_key_exists($id, $aGroups)) {
             $aGroups[$id] = Group::get($id);
         }
     }
     // now, merge this (again) into the user-set.
     foreach ($aGroups as $oGroup) {
         $aNewUsers = $oGroup->getMembers();
         foreach ($aNewUsers as $oU) {
             $id = $oU->getId();
             if (!array_key_exists($id, $aUsers)) {
                 $aUsers[$id] = $oU;
             }
         }
     }
     // and done.
     foreach ($aUsers as $oU) {
         if (!PEAR::isError($oU)) {
             KTWorkflowNotification::newNotificationForDocument($oDocument, $oU, $oState, $oUser, $sComments);
         }
     }
 }
Example #16
0
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
$ret = GroupUtil::addGroup(array("name" => "Test2"));
if (PEAR::isError($ret)) {
    print "Error adding group: " . $ret->toString();
} else {
    if ($ret === true) {
        print "Group added successfully.\n";
    } else {
        print "Bad code!\n";
    }
}
<?php

require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/groups/GroupUtil.php';
$aGroupMembers = array(1 => array(2, 3, 4), 2 => array(), 3 => null, 4 => array(5), 5 => null, 6 => array(1), 7 => array(2, 3));
$iGroupID = 5;
$aRet = GroupUtil::filterCyclicalGroups($iGroupID, $aGroupMembers);
sort($aRet);
$aExpectedResult = array(2, 3, 7);
if ($aRet === $aExpectedResult) {
    print "Success!\n";
} else {
    print "Failed!\n";
    print "Expected: " . print_r($aExpectedResult, true);
    print "Got: " . print_r($aRet, true);
}