Enable/Disable users

This commit is contained in:
Frederic Guillot
2016-02-13 15:38:35 -05:00
parent 567d623446
commit 6161eaef9e
31 changed files with 541 additions and 72 deletions

View File

@@ -106,6 +106,7 @@ class ProjectGroupRole extends Base
->join(GroupMember::TABLE, 'user_id', 'id', User::TABLE)
->join(self::TABLE, 'group_id', 'group_id', GroupMember::TABLE)
->eq(self::TABLE.'.project_id', $project_id)
->eq(User::TABLE.'.is_active', 1)
->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER))
->asc(User::TABLE.'.username')
->findAll();

View File

@@ -107,7 +107,8 @@ class ProjectPermission extends Base
*/
public function isAssignable($project_id, $user_id)
{
return in_array($this->projectUserRole->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER));
return $this->user->isActive($user_id) &&
in_array($this->projectUserRole->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER));
}
/**

View File

@@ -152,13 +152,14 @@ class ProjectUserRole extends Base
public function getAssignableUsers($project_id)
{
if ($this->projectPermission->isEverybodyAllowed($project_id)) {
return $this->user->getList();
return $this->user->getActiveUsersList();
}
$userMembers = $this->db->table(self::TABLE)
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->eq(User::TABLE.'.is_active', 1)
->eq(self::TABLE.'.project_id', $project_id)
->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER))
->findAll();

View File

@@ -40,6 +40,18 @@ class User extends Base
return $this->db->table(self::TABLE)->eq('id', $user_id)->exists();
}
/**
* Return true if the user is active
*
* @access public
* @param integer $user_id User id
* @return boolean
*/
public function isActive($user_id)
{
return $this->db->table(self::TABLE)->eq('id', $user_id)->eq('is_active', 1)->exists();
}
/**
* Get query to fetch all users
*
@@ -193,9 +205,9 @@ class User extends Base
* @param boolean $prepend Prepend "All users"
* @return array
*/
public function getList($prepend = false)
public function getActiveUsersList($prepend = false)
{
$users = $this->db->table(self::TABLE)->columns('id', 'username', 'name')->findAll();
$users = $this->db->table(self::TABLE)->eq('is_active', 1)->columns('id', 'username', 'name')->findAll();
$listing = $this->prepareList($users);
if ($prepend) {
@@ -280,6 +292,30 @@ class User extends Base
return $result;
}
/**
* Disable a specific user
*
* @access public
* @param integer $user_id
* @return boolean
*/
public function disable($user_id)
{
return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 0));
}
/**
* Enable a specific user
*
* @access public
* @param integer $user_id
* @return boolean
*/
public function enable($user_id)
{
return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 1));
}
/**
* Remove a specific user
*