summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php2
-rw-r--r--app/Model/ProjectPermission.php64
2 files changed, 65 insertions, 1 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index 4a07d116..b8353b58 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -32,7 +32,7 @@ class Acl extends Base
*/
private $user_actions = array(
'app' => array('index', 'preview', 'status'),
- 'project' => array('index', 'show', 'exporttasks', 'exportdaily', 'share', 'edit', 'update', 'users', 'remove', 'duplicate', 'disable', 'enable', 'activity', 'search', 'tasks', 'create', 'save'),
+ 'project' => array('index', 'show', 'exporttasks', 'exportdaily', 'share', 'edit', 'update', 'users', 'remove', 'duplicate', 'disable', 'enable', 'activity', 'search', 'tasks', 'create', 'save', 'revoke', 'setowner', 'allow'),
'board' => array('index', 'show', 'save', 'check', 'changeassignee', 'updateassignee', 'changecategory', 'updatecategory', 'movecolumn', 'edit', 'update', 'add', 'confirm', 'remove', 'subtasks', 'togglesubtask', 'attachments', 'comments', 'description'),
'user' => array('edit', 'forbidden', 'logout', 'show', 'external', 'unlinkgoogle', 'unlinkgithub', 'sessions', 'removesession', 'last', 'notifications', 'password'),
'comment' => array('create', 'save', 'confirm', 'remove', 'update', 'edit', 'forbidden'),
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index 8984ef3e..aaff5e69 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -86,6 +86,27 @@ class ProjectPermission extends Base
}
/**
+ * Get a list of owners for a project
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function getOwners($project_id)
+ {
+ $users = $this->db
+ ->table(self::TABLE)
+ ->join(User::TABLE, 'id', 'user_id')
+ ->eq('project_id', $project_id)
+ ->eq('is_owner', 1)
+ ->asc('username')
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
+ ->findAll();
+
+ return $this->user->prepareList($users);
+ }
+
+ /**
* Get allowed and not allowed users for a project
*
* @access public
@@ -97,11 +118,13 @@ class ProjectPermission extends Base
$users = array(
'allowed' => array(),
'not_allowed' => array(),
+ 'owners' => array(),
);
$all_users = $this->user->getList();
$users['allowed'] = $this->getMembers($project_id);
+ $users['owners'] = $this->getOwners($project_id);
foreach ($all_users as $user_id => $username) {
@@ -129,6 +152,24 @@ class ProjectPermission extends Base
}
/**
+ * Make the specific user owner of the given project
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $user_id User id
+ * @param bool $is_owner Is user owner of the project
+ * @return bool
+ */
+ public function setOwner($project_id, $user_id, $is_owner = 1)
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('user_id', $user_id)
+ ->update(array('is_owner' => $is_owner));
+ }
+
+ /**
* Revoke a specific user for a given project
*
* @access public
@@ -164,6 +205,24 @@ class ProjectPermission extends Base
->eq('project_id', $project_id)
->eq('user_id', $user_id)
->count();
+ }
+
+ /**
+ * Check if a specific user is owner of a given project
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $user_id User id
+ * @return bool
+ */
+ public function isOwner($project_id, $user_id)
+ {
+ return (bool) $this->db
+ ->table(self::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('user_id', $user_id)
+ ->eq('is_owner', 1)
+ ->count();
}
/**
@@ -209,6 +268,10 @@ class ProjectPermission extends Base
return true;
}
+ if ($this->isOwner($project_id, $user_id)) {
+ return true;
+ }
+
return false;
}
@@ -291,6 +354,7 @@ class ProjectPermission extends Base
new Validators\Integer('project_id', t('This value must be an integer')),
new Validators\Required('user_id', t('The user id is required')),
new Validators\Integer('user_id', t('This value must be an integer')),
+ new Validators\Integer('is_owner', t('This value must be an integer')),
));
return array(