summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-11-30 12:02:48 -0800
committerFrédéric Guillot <fred@kanboard.net>2017-11-30 12:02:48 -0800
commitcb9e6377f6dd1d16d6c5d1aa98014941eef48814 (patch)
treeb0abb935cc996f869565fcf43613023052f63933
parentaa5199db7f0915e0115ac302fa4d3e0552b0a4b0 (diff)
Disable private projects when disabling a user
-rw-r--r--app/Model/UserModel.php6
-rw-r--r--tests/units/Model/UserModelTest.php13
2 files changed, 18 insertions, 1 deletions
diff --git a/app/Model/UserModel.php b/app/Model/UserModel.php
index af49ce7d..c44fd3e7 100644
--- a/app/Model/UserModel.php
+++ b/app/Model/UserModel.php
@@ -286,7 +286,11 @@ class UserModel extends Base
*/
public function disable($user_id)
{
- return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 0));
+ $this->db->startTransaction();
+ $result1 = $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 0));
+ $result2 = $this->db->table(ProjectModel::TABLE)->eq('is_private', 1)->eq('owner_id', $user_id)->update(array('is_active' => 0));
+ $this->db->closeTransaction();
+ return $result1 && $result2;
}
/**
diff --git a/tests/units/Model/UserModelTest.php b/tests/units/Model/UserModelTest.php
index a0c9c575..e7f6e0e5 100644
--- a/tests/units/Model/UserModelTest.php
+++ b/tests/units/Model/UserModelTest.php
@@ -381,4 +381,17 @@ class UserModelTest extends Base
$this->assertEquals(1, $user['is_active']);
$this->assertTrue($userModel->isActive(2));
}
+
+ public function testDisablePrivateProjects()
+ {
+ $userModel = new UserModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1', 'is_private' => 1, 'owner_id' => 2)));
+ $this->assertTrue($userModel->disable(2));
+
+ $project = $projectModel->getById(2);
+ $this->assertEquals(0, $project['is_active']);
+ }
}