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;
|
|
|
|
}
|
|
|
|
|
2015-07-25 13:46:39 +03:00
|
|
|
protected function setup() {
|
|
|
|
parent::setup();
|
|
|
|
|
|
|
|
$this->userManager = \OC::$server->getUserManager();
|
|
|
|
$this->config = \OC::$server->getConfig();
|
|
|
|
$this->groupManager = \OC::$server->getGroupManager();
|
2015-07-25 16:01:31 +03:00
|
|
|
$this->userSession = \OC::$server->getUserSession();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->api = new \OCA\Provisioning_Api\Users(
|
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
2015-07-25 16:01:31 +03:00
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession
|
|
|
|
);
|
2015-07-25 13:46:39 +03:00
|
|
|
}
|
|
|
|
|
2014-12-22 16:54:50 +03:00
|
|
|
// Test getting the list of users
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetUsers() {
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUsers();
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$count = $result->getData();
|
|
|
|
$count = count($count['users']);
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals(count($this->userManager->search('', null, null)), $count);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$user = $this->generateUsers();
|
|
|
|
$_GET['search'] = $user;
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUsers();
|
2014-12-22 16:54:50 +03:00
|
|
|
$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;
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUsers();
|
2014-12-22 16:54:50 +03:00
|
|
|
$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;
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUsers(array());
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals(array_keys($this->userManager->search('', 1, 1)), $data['users']);
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
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';
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->addUser();
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue($this->userManager->userExists($_POST['userid']));
|
|
|
|
$this->assertEquals($_POST['userid'], $this->userManager->checkPassword($_POST['userid'], $_POST['password'])->getUID());
|
2014-12-22 16:54:50 +03:00
|
|
|
$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;
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUser($params);
|
2014-12-22 16:54:50 +03:00
|
|
|
$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();
|
2015-07-25 13:46:39 +03:00
|
|
|
while($this->userManager->userExists($params['userid'])) {
|
2015-01-07 12:34:42 +03:00
|
|
|
$params['userid'] = $this->getUniqueID();
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUser($params);
|
2014-12-22 16:54:50 +03:00
|
|
|
$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]);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUser($params);
|
2014-12-22 16:54:50 +03:00
|
|
|
$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]);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->getUser($params);
|
2014-12-22 16:54:50 +03:00
|
|
|
$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);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
array(
|
|
|
|
'userid' => $user,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'display',
|
|
|
|
'value' => 'newname',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals('newname', $this->userManager->get($user)->getDisplayName());
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
array(
|
|
|
|
'userid' => $user2,
|
|
|
|
'_put' => array(
|
|
|
|
'key' => 'display',
|
|
|
|
'value' => 'newname',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals('newname', $this->userManager->get($user2)->getDisplayName());
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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]);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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]);
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($users[0]));
|
|
|
|
$result = $this->api->editUser(
|
2014-12-22 16:54:50 +03:00
|
|
|
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);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->createGroup($group);
|
|
|
|
$this->groupManager->get($group)->addUser($this->userManager->get($user));
|
|
|
|
$this->groupManager->get($group)->addUser($this->userManager->get($user2));
|
2015-01-07 12:34:42 +03:00
|
|
|
\OC_SubAdmin::createSubAdmin($user, $group);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get($group)->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
|
|
|
$group2 = $this->groupManager->createGroup($group2);
|
|
|
|
$group->addUser($this->userManager->get($user));
|
|
|
|
$group2->addUser($this->userManager->get($user2));
|
|
|
|
\OC_SubAdmin::createSubAdmin($user, $group->getGID());
|
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
2015-07-25 13:46:39 +03:00
|
|
|
));
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$group->delete();
|
|
|
|
$group2->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->deleteUser(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
|
|
|
$group->addUser($this->userManager->get($user));
|
|
|
|
$result = $this->api->getUsersGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals($group->getGID(), reset($data['groups']));
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-07-25 13:46:39 +03:00
|
|
|
$group->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
|
|
|
$group->addUser($this->userManager->get($user2));
|
|
|
|
$result = $this->api->getUsersGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$group->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
|
|
|
$group->addUser($this->userManager->get($user2));
|
|
|
|
$result = $this->api->getUsersGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals($group->getGID(), reset($data['groups']));
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-07-25 13:46:39 +03:00
|
|
|
$group->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group2 = $this->groupManager->createGroup($group2);
|
|
|
|
$group1->addUser($this->userManager->get($user2));
|
|
|
|
$group2->addUser($this->userManager->get($user2));
|
|
|
|
$group1->addUser($this->userManager->get($user1));
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$result = $this->api->getUsersGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals($group1->getGID(), reset($data['groups']));
|
2014-12-22 16:54:50 +03:00
|
|
|
$this->assertEquals(1, count($data['groups']));
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1->delete();
|
|
|
|
$group2->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group2 = $this->groupManager->createGroup($group2);
|
|
|
|
$group2->addUser($this->userManager->get($user2));
|
|
|
|
$group1->addUser($this->userManager->get($user1));
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$result = $this->api->getUsersGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1->delete();
|
|
|
|
$group2->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-07-25 13:46:39 +03:00
|
|
|
$_POST['groupid'] = $group->getGID();
|
|
|
|
$result = $this->api->addToGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertFalse($group->inGroup($this->userManager->get($user)));
|
|
|
|
$group->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user));
|
2015-01-07 12:34:42 +03:00
|
|
|
$group = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group = $this->groupManager->createGroup($group);
|
2014-12-22 16:54:50 +03:00
|
|
|
$user2 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user);
|
2015-07-25 13:46:39 +03:00
|
|
|
$_POST['groupid'] = $group->getGID();
|
|
|
|
$result = $this->api->addToGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue($group->inGroup($this->userManager->get($user2)));
|
|
|
|
$group->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->addToGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertFalse($group1->inGroup($this->userManager->get($user2)));
|
|
|
|
$group1->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group2 = $this->groupManager->createGroup($group2);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$_POST['groupid'] = $group2->getGID();
|
|
|
|
$result = $this->api->addToGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertFalse($group2->inGroup($this->userManager->get($user2)));
|
|
|
|
$group1->delete();
|
|
|
|
$group2->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group1->addUser($this->userManager->get($user1));
|
|
|
|
$result = $this->api->removeFromGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user1,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue($group1->inGroup($this->userManager->get($user1)));
|
|
|
|
$group1->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group1->addUser($this->userManager->get($user2));
|
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
|
|
|
$result = $this->api->removeFromGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertFalse($group1->inGroup($this->userManager->get($user2)));
|
|
|
|
$group1->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group1->addUser($this->userManager->get($user1));
|
|
|
|
$group1->addUser($this->userManager->get($user2));
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$result = $this->api->removeFromGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertFalse($group1->inGroup($this->userManager->get($user2)));
|
|
|
|
$group1->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$group2 = $this->groupManager->createGroup($group2);
|
|
|
|
$group1->addUser($this->userManager->get($user1));
|
|
|
|
$group2->addUser($this->userManager->get($user2));
|
|
|
|
\OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
|
|
|
|
$result = $this->api->removeFromGroup(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group2->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue($group2->inGroup($this->userManager->get($user2)));
|
|
|
|
$group1->delete();
|
|
|
|
$group2->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->addSubAdmin(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue(\OC_SubAdmin::isSubAdminofGroup($user2, $group1->getGID()));
|
|
|
|
$group1->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2014-12-22 16:54:50 +03:00
|
|
|
$_POST['groupid'] = 'admin';
|
2015-07-25 13:46:39 +03:00
|
|
|
$result = $this->api->addSubAdmin(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->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-07-25 13:46:39 +03:00
|
|
|
$group1->delete();
|
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();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user2, $group1->getGID());
|
|
|
|
$result = $this->api->removeSubAdmin(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertTrue(!\OC_SubAdmin::isSubAdminofGroup($user2, $group1->getGID()));
|
|
|
|
$group1->delete();
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
|
|
|
$result = $this->api->removeSubAdmin(array(
|
2015-01-07 12:34:42 +03:00
|
|
|
'userid' => $this->getUniqueID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->removeSubAdmin(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
'_delete' => array(
|
2015-07-25 13:46:39 +03:00
|
|
|
'groupid' => $group1->getGID(),
|
2014-12-22 16:54:50 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(102, $result->getStatusCode());
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1->delete();
|
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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2015-01-07 12:34:42 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user2, $group1->getGID());
|
|
|
|
$result = $this->api->getUserSubAdminGroups(array(
|
2014-12-22 16:54:50 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->assertEquals($group1->getGID(), reset($data));
|
|
|
|
$group1->delete();
|
2014-12-22 16:54:50 +03:00
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-05-18 13:28:54 +03:00
|
|
|
self::loginAsUser($user1);
|
2015-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
|
|
|
$result = $this->api->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-07-25 13:46:39 +03:00
|
|
|
$this->groupManager->get('admin')->addUser($this->userManager->get($user1));
|
2015-04-13 11:32:18 +03:00
|
|
|
$group1 = $this->getUniqueID();
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1 = $this->groupManager->createGroup($group1);
|
2015-04-13 11:32:18 +03:00
|
|
|
|
|
|
|
//Make user2 subadmin of group1
|
2015-07-25 13:46:39 +03:00
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->addSubAdmin([
|
2015-04-13 11:32:18 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
]);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
|
|
|
|
//Make user2 subadmin of group1 again
|
2015-07-25 13:46:39 +03:00
|
|
|
$_POST['groupid'] = $group1->getGID();
|
|
|
|
$result = $this->api->addSubAdmin([
|
2015-04-13 11:32:18 +03:00
|
|
|
'userid' => $user2,
|
|
|
|
]);
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-07-25 13:46:39 +03:00
|
|
|
$group1->delete();
|
2015-04-13 11:32:18 +03:00
|
|
|
}
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|