Allow a project owner to manage his own public project

This commit is contained in:
Frederic Guillot 2016-05-05 22:13:11 -04:00
parent ab56d9aff2
commit cfb96c8749
3 changed files with 28 additions and 2 deletions

View File

@ -27,6 +27,7 @@ Improvements:
Bug fixes:
* Allow a project owner to manage his own public project
* Fixed PHP warning when removing a user with no Avatar image
* Fixed improper Markdown escaping for some tooltips
* Closing all tasks by column, also update closed tasks

View File

@ -69,8 +69,13 @@ class ProjectUserRole extends Base
*/
public function getUserRole($project_id, $user_id)
{
if ($this->projectPermission->isEverybodyAllowed($project_id)) {
return Role::PROJECT_MEMBER;
$projectInfo = $this->db->table(Project::TABLE)
->eq('id', $project_id)
->columns('owner_id', 'is_everybody_allowed')
->findOne();
if ($projectInfo['is_everybody_allowed'] == 1) {
return $projectInfo['owner_id'] == $user_id ? Role::PROJECT_MANAGER : Role::PROJECT_MEMBER;
}
$role = $this->db->table(self::TABLE)->eq('user_id', $user_id)->eq('project_id', $project_id)->findOneColumn('role');

View File

@ -101,6 +101,26 @@ class ProjectUserRoleTest extends Base
$this->assertEquals('', $userRoleModel->getUserRole(1, 2));
}
public function testGetRoleWithPublicProject()
{
$projectModel = new Project($this->container);
$userRoleModel = new ProjectUserRole($this->container);
$userModel = new User($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1')));
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2')));
$this->assertEquals(1, $projectModel->create(array('name' => 'Test'), 2, true));
$this->assertEquals(Role::PROJECT_MANAGER, $userRoleModel->getUserRole(1, 2));
$this->assertEquals(null, $userRoleModel->getUserRole(1, 3));
$this->assertTrue($projectModel->update(array('id' => 1, 'is_everybody_allowed' => 1)));
$this->assertEquals(Role::PROJECT_MANAGER, $userRoleModel->getUserRole(1, 2));
$this->assertEquals(Role::PROJECT_MEMBER, $userRoleModel->getUserRole(1, 3));
}
public function testGetAssignableUsersWithDisabledUsers()
{
$projectModel = new Project($this->container);