Fix issue when unlinking Gitlab account

This commit is contained in:
Frederic Guillot
2015-10-03 18:22:06 -04:00
parent 260c8515c5
commit c9e3178720
4 changed files with 31 additions and 3 deletions

View File

@@ -96,6 +96,22 @@ abstract class Base extends \Core\Base
} }
} }
/**
* Force some fields to be null if empty
*
* @access public
* @param array $values Input array
* @param string[] $keys List of keys
*/
public function convertNullFields(array &$values, array $keys)
{
foreach ($keys as $key) {
if (array_key_exists($key, $values) && empty($values[$key])) {
$values[$key] = null;
}
}
}
/** /**
* Build SQL condition for a given time range * Build SQL condition for a given time range
* *

View File

@@ -279,7 +279,7 @@ class User extends Base
$this->removeFields($values, array('confirmation', 'current_password')); $this->removeFields($values, array('confirmation', 'current_password'));
$this->resetFields($values, array('is_admin', 'is_ldap_user', 'is_project_admin', 'disable_login_form')); $this->resetFields($values, array('is_admin', 'is_ldap_user', 'is_project_admin', 'disable_login_form'));
$this->removeEmptyFields($values, array('gitlab_id')); $this->convertNullFields($values, array('gitlab_id'));
$this->convertIntegerFields($values, array('gitlab_id')); $this->convertIntegerFields($values, array('gitlab_id'));
} }

View File

@@ -76,3 +76,8 @@ Kanboard uses these information from your Gitlab profile:
- Gitlab unique id - Gitlab unique id
The Gitlab unique id is used to link the local user account and the Gitlab account. The Gitlab unique id is used to link the local user account and the Gitlab account.
Known issues
------------
Gitlab OAuth will work only with url rewrite enabled. At the moment, Gitlab doesn't support callback url with query string parameters. See [Gitlab issue](https://gitlab.com/gitlab-org/gitlab-ce/issues/2443)

View File

@@ -250,7 +250,7 @@ class UserTest extends Base
); );
$u->prepare($input); $u->prepare($input);
$this->assertEquals(array(), $input); $this->assertEquals(array('gitlab_id' => null), $input);
$input = array( $input = array(
'gitlab_id' => 'something', 'gitlab_id' => 'something',
@@ -325,8 +325,11 @@ class UserTest extends Base
public function testUpdate() public function testUpdate()
{ {
$u = new User($this->container); $u = new User($this->container);
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123')));
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute'))); $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
$this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => '')));
$user = $u->getById(2); $user = $u->getById(2);
$this->assertNotFalse($user); $this->assertNotFalse($user);
@@ -335,6 +338,10 @@ class UserTest extends Base
$this->assertEquals('Toto', $user['name']); $this->assertEquals('Toto', $user['name']);
$this->assertEquals(0, $user['is_admin']); $this->assertEquals(0, $user['is_admin']);
$this->assertEquals(0, $user['is_ldap_user']); $this->assertEquals(0, $user['is_ldap_user']);
$user = $u->getById(3);
$this->assertNotEmpty($user);
$this->assertEquals(null, $user['gitlab_id']);
} }
public function testRemove() public function testRemove()