Skip to content

Commit

Permalink
Allow a project owner to manage his own public project
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed May 6, 2016
1 parent ab56d9a commit cfb96c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions app/Model/ProjectUserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ public function getProjectsByUser($user_id, $status = array(Project::ACTIVE, Pro
*/
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');
Expand Down
20 changes: 20 additions & 0 deletions tests/units/Model/ProjectUserRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public function testGetRoleWithGroups()
$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);
Expand Down

0 comments on commit cfb96c8

Please sign in to comment.