2014-12-22 16:54:50 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Tom Needham <tom@owncloud.com>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2015-02-26 13:37:37 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-12-22 16:54:50 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
namespace OCA\Provisioning_API\Tests;
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
class UsersTest extends TestCase {
|
|
|
|
protected function resetParams() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$_GET = null;
|
|
|
|
$_POST = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting the list of users
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsers() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsers(array());
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$count = $result->getData();
|
|
|
|
$count = count($count['users']);
|
|
|
|
$this->assertEquals(count(\OC_User::getUsers()), $count);
|
|
|
|
|
|
|
|
$user = $this->generateUsers();
|
|
|
|
$_GET['search'] = $user;
|
|
|
|
$result = \OCA\provisioning_API\Users::getUsers(array());
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($user, reset($data['users']));
|
|
|
|
|
|
|
|
// Add several users
|
|
|
|
$this->generateUsers(10);
|
|
|
|
$this->resetParams();
|
|
|
|
$_GET['limit'] = 2;
|
|
|
|
$result = \OCA\provisioning_API\Users::getUsers(array());
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$count = $result->getData();
|
|
|
|
$count = count($count['users']);
|
|
|
|
$this->assertEquals(2, $count);
|
|
|
|
|
|
|
|
$this->resetParams();
|
|
|
|
$_GET['limit'] = 1;
|
|
|
|
$_GET['offset'] = 1;
|
|
|
|
$result = \OCA\provisioning_API\Users::getUsers(array());
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals(\OC_User::getUsers('', 1, 1), $data['users']);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAddUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->resetParams();
|
2015-01-07 12:34:42 +03:00
|
|
|
$_POST['userid'] = $this->getUniqueID();
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['password'] = 'password';
|
|
|
|
$result = \OCA\provisioning_API\Users::addUser(array());
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertTrue(\OC_User::userExists($_POST['userid']));
|
|
|
|
$this->assertEquals($_POST['userid'], \OC_User::checkPassword($_POST['userid'], $_POST['password']));
|
|
|
|
$this->users[] = $_POST['userid'];
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUserOnSelf() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$params['userid'] = $user;
|
|
|
|
$result = \OCA\provisioning_API\Users::getUser($params);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUserOnNonExistingUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$params = array();
|
2015-01-07 12:34:42 +03:00
|
|
|
$params['userid'] = $this->getUniqueID();
|
2014-12-22 16:54:50 +03:00
|
|
|
while(\OC_User::userExists($params['userid'])) {
|
2015-01-07 12:34:42 +03:00
|
|
|
$params['userid'] = $this->getUniqueID();
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
$result = \OCA\provisioning_API\Users::getUser($params);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-04-18 11:30:02 +03:00
|
|
|
$this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUserOnOtherUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
$params['userid'] = $users[0];
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($users[1]);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUser($params);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
|
|
|
|
// Now as as admin
|
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
$params['userid'] = $users[0];
|
2015-05-18 13:28:54 +03:00
|
|
|
// login to generate home
|
|
|
|
self::loginAsUser($users[0]);
|
2014-12-22 16:54:50 +03:00
|
|
|
\OC_Group::addToGroup($users[1], 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($users[1]);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUser($params);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals(\OC::$server->getConfig()->getUserValue($users[0], 'core', 'enabled', 'true'), $data['enabled']);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testEditOwnDisplayName() {
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
// Test editing own name
|
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'display',
|
|
|
|
'value' => 'newname',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertEquals('newname', \OC_User::getDisplayName($user));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAdminEditDisplayNameOfUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
// Test admin editing users name
|
|
|
|
$user = $this->generateUsers();
|
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'display',
|
|
|
|
'value' => 'newname',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertEquals('newname', \OC_User::getDisplayName($user2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testUserEditOtherUserDisplayName() {
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
// Test editing other users name
|
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'display',
|
|
|
|
'value' => 'newname',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-07 18:56:13 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider providesQuotas
|
|
|
|
* @param $expected
|
|
|
|
* @param $quota
|
|
|
|
*/
|
|
|
|
public function testEditOwnQuota($expected, $quota) {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-07 18:56:13 +03:00
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
2015-05-07 18:56:13 +03:00
|
|
|
[
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user,
|
2015-05-07 18:56:13 +03:00
|
|
|
'_put' => [
|
2014-12-22 16:54:50 +03:00
|
|
|
'key' => 'quota',
|
2015-05-07 18:56:13 +03:00
|
|
|
'value' => $quota,
|
|
|
|
],
|
|
|
|
]
|
2014-12-22 16:54:50 +03:00
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
2015-05-07 18:56:13 +03:00
|
|
|
$this->assertEquals($expected, $result->succeeded());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providesQuotas() {
|
|
|
|
return [
|
|
|
|
[true, '20G'],
|
|
|
|
[true, '1234567'],
|
|
|
|
[true, 'none'],
|
|
|
|
[true, 'default'],
|
|
|
|
[false, 'qwertzu'],
|
|
|
|
];
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAdminEditOwnQuota() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'quota',
|
|
|
|
'value' => '20G',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAdminEditOtherUserQuota() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'quota',
|
|
|
|
'value' => '20G',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testUserEditOtherUserQuota() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'quota',
|
|
|
|
'value' => '20G',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testUserEditOwnEmail() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
|
|
|
$email = 'test@example.com';
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $user,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'email',
|
|
|
|
'value' => $email,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertEquals($email, \OC::$server->getConfig()->getUserValue($user, 'settings', 'email', null));
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testUserEditOtherUserEmailAsUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
$email = 'test@example.com';
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($users[0]);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $users[1],
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'email',
|
|
|
|
'value' => $email,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testUserEditOtherUserEmailAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
$email = 'test@example.com';
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($users[0]);
|
2014-12-22 16:54:50 +03:00
|
|
|
\OC_Group::addToGroup($users[0], 'admin');
|
|
|
|
$result = \OCA\provisioning_API\Users::editUser(
|
|
|
|
array(
|
|
|
|
'userid' => $users[1],
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'email',
|
|
|
|
'value' => $email,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertEquals($email, \OC::$server->getConfig()->getUserValue($users[1], 'settings', 'email', null));
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteSelf() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteOtherAsUser() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteOtherAsSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($user, $group);
|
|
|
|
\OC_Group::addToGroup($user2, $group);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user, $group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteOtherAsIrelevantSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
$group2 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_Group::addToGroup($user, $group);
|
|
|
|
\OC_Group::addToGroup($user2, $group2);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user, $group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group);
|
|
|
|
\OC_Group::deleteGroup($group2);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteOtherAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testDeleteSelfAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::deleteUser(array(
|
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsersGroupsOnSelf() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($user, $group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsersGroups(array(
|
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($group, reset($data['groups']));
|
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsersGroupOnOther() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($user2, $group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsersGroups(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsersGroupOnOtherAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($user2, $group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsersGroups(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($group, reset($data['groups']));
|
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsersGroupsOnOtherAsSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
$group2 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_Group::addToGroup($user2, $group1);
|
|
|
|
\OC_Group::addToGroup($user2, $group2);
|
|
|
|
\OC_Group::addToGroup($user1, $group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsersGroups(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($group1, reset($data['groups']));
|
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group1);
|
|
|
|
\OC_Group::deleteGroup($group2);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
$group2 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_Group::addToGroup($user2, $group2);
|
|
|
|
\OC_Group::addToGroup($user1, $group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_API\Users::getUsersGroups(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group1);
|
|
|
|
\OC_Group::deleteGroup($group2);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAddToGroup() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group;
|
|
|
|
$result = \OCA\provisioning_API\Users::addToGroup(array(
|
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertFalse(\OC_Group::inGroup($user, $group));
|
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAddToGroupAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user, 'admin');
|
|
|
|
$group = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group;
|
|
|
|
$result = \OCA\provisioning_API\Users::addToGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertTrue(\OC_Group::inGroup($user2, $group));
|
|
|
|
\OC_Group::deleteGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAddToGroupAsSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_API\Users::addToGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertFalse(\OC_Group::inGroup($user2, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testAddToGroupAsIrelevantSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
$group2 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group2;
|
|
|
|
$result = \OCA\provisioning_API\Users::addToGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertFalse(\OC_Group::inGroup($user2, $group2));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
|
|
|
\OC_Group::deleteGroup($group2);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// test delete /cloud/users/{userid}/groups
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testRemoveFromGroupAsSelf() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::addToGroup($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeFromGroup(array(
|
|
|
|
'userid' => $user1,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertTrue(\OC_Group::inGroup($user1, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testRemoveFromGroupAsAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::addToGroup($user2, $group1);
|
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeFromGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertFalse(\OC_Group::inGroup($user2, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testRemoveFromGroupAsSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::addToGroup($user1, $group1);
|
|
|
|
\OC_Group::addToGroup($user2, $group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeFromGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertFalse(\OC_Group::inGroup($user2, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testRemoveFromGroupAsIrelevantSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
$group2 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_Group::addToGroup($user1, $group1);
|
|
|
|
\OC_Group::addToGroup($user2, $group2);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeFromGroup(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group2,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertTrue(\OC_Group::inGroup($user2, $group2));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
|
|
|
\OC_Group::deleteGroup($group2);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testCreateSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_api\Users::addSubAdmin(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertTrue(\OC_SubAdmin::isSubAdminofGroup($user2, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$this->resetParams();
|
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = 'admin';
|
|
|
|
$result = \OCA\provisioning_api\Users::addSubAdmin(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertEquals(103, $result->getStatusCode());
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
|
|
|
|
$this->resetParams();
|
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_api\Users::addSubAdmin(array(
|
2015-01-07 12:34:42 +03:00
|
|
|
'userid' => $this->getUniqueID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(101, $result->getStatusCode());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testRemoveSubAdmin() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user2, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeSubAdmin(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-01-07 12:34:42 +03:00
|
|
|
$this->assertTrue(!\OC_SubAdmin::isSubAdminofGroup($user2, $group1));
|
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::removeSubAdmin(array(
|
2015-01-07 12:34:42 +03:00
|
|
|
'userid' => $this->getUniqueID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertEquals(101, $result->getStatusCode());
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
|
|
|
|
$this->resetParams();
|
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_api\Users::removeSubAdmin(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(102, $result->getStatusCode());
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetSubAdminGroups() {
|
2014-12-22 16:54:50 +03:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user2, $group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array(
|
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($group1, reset($data));
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
2014-12-22 16:54:50 +03:00
|
|
|
$result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array(
|
2015-01-07 12:34:42 +03:00
|
|
|
'userid' => $this->getUniqueID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(101, $result->getStatusCode());
|
|
|
|
}
|
2015-04-13 11:32:18 +03:00
|
|
|
|
|
|
|
public function testSubAdminOfGroupAlreadySubAdmin() {
|
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-04-13 11:32:18 +03:00
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
|
|
|
|
//Make user2 subadmin of group1
|
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_api\Users::addSubAdmin([
|
|
|
|
'userid' => $user2,
|
|
|
|
]);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
|
|
|
|
//Make user2 subadmin of group1 again
|
|
|
|
$_POST['groupid'] = $group1;
|
|
|
|
$result = \OCA\provisioning_api\Users::addSubAdmin([
|
|
|
|
'userid' => $user2,
|
|
|
|
]);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
}
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|