예제 #1
0
/**
 * Tells whether a user can assign a task to another user or company in a workspace.
 * 
 * @param $user User to which to check permissions
 * @param $workspace
 * @param $assignee
 * @return boolean
 */
function can_assign_task(User $user, Project $workspace, $assignee)
{
    if (!$assignee instanceof User && !$assignee instanceof Company) {
        return true;
    }
    if ($assignee instanceof Company) {
        $company = $assignee;
    } else {
        if ($assignee->getId() == $user->getId()) {
            return true;
        }
        // alow user to assign to himself
        $company = $assignee->getCompany();
    }
    $is_owner = $company->getId() == Companies::getOwnerCompany()->getId();
    $permissions = ProjectUsers::getByUserAndProject($workspace, $user);
    if ($permissions instanceof ProjectUser) {
        if ($is_owner) {
            if ($permissions->getCanAssignToOwners()) {
                return true;
            }
        } else {
            if ($permissions->getCanAssignToOther()) {
                return true;
            }
        }
    }
    $groups = GroupUsers::getGroupsByUser($user->getId());
    if (is_array($groups) && count($groups) > 0) {
        //user belongs to at least one group
        foreach ($groups as $group) {
            $permissions = ProjectUsers::getByUserAndProject($workspace, $group);
            if ($permissions instanceof ProjectUser) {
                if ($is_owner) {
                    if ($permissions->getCanAssignToOwners()) {
                        return true;
                    }
                } else {
                    if ($permissions->getCanAssignToOther()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
예제 #2
0
 function getGroups()
 {
     if (is_null($this->groups)) {
         $this->groups = GroupUsers::getGroupsByUser($this->getId());
     }
     // if
     return $this->groups;
 }