Bump popovermenu item options and tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
f4cec587d9
commit
62e1014b2e
5 changed files with 3045 additions and 433 deletions
|
@ -42,21 +42,15 @@ namespace OC\Settings\Controller;
|
|||
use OC\Accounts\AccountManager;
|
||||
use OC\AppFramework\Http;
|
||||
use OC\ForbiddenException;
|
||||
use OC\HintException;
|
||||
use OC\Settings\Mailer\NewUserMailHelper;
|
||||
use OC\Security\IdentityProof\Manager;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Files\Config\IUserMountCache;
|
||||
use OCP\Encryption\IEncryptionModule;
|
||||
use OCP\Encryption\IManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
|
@ -64,57 +58,37 @@ use OCP\IUserManager;
|
|||
use OCP\IUserSession;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCP\Mail\IMailer;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use OCP\Util;
|
||||
use OC\Settings\BackgroundJobs\VerifyUserData;
|
||||
|
||||
/**
|
||||
* @package OC\Settings\Controller
|
||||
*/
|
||||
class UsersController extends Controller {
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var bool */
|
||||
private $isAdmin;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var ILogger */
|
||||
private $log;
|
||||
/** @var bool */
|
||||
private $isAdmin;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var IMailer */
|
||||
private $mailer;
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
/** @var bool contains the state of the encryption app */
|
||||
private $isEncryptionAppEnabled;
|
||||
/** @var bool contains the state of the admin recovery setting */
|
||||
private $isRestoreEnabled = false;
|
||||
/** @var IAppManager */
|
||||
private $appManager;
|
||||
/** @var IAvatarManager */
|
||||
private $avatarManager;
|
||||
/** @var AccountManager */
|
||||
private $accountManager;
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
/** @var NewUserMailHelper */
|
||||
private $newUserMailHelper;
|
||||
/** @var Manager */
|
||||
private $keyManager;
|
||||
/** @var IJobList */
|
||||
private $jobList;
|
||||
|
||||
/** @var IUserMountCache */
|
||||
private $userMountCache;
|
||||
|
||||
/** @var IManager */
|
||||
private $encryptionManager;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
|
@ -124,19 +98,12 @@ class UsersController extends Controller {
|
|||
IConfig $config,
|
||||
bool $isAdmin,
|
||||
IL10N $l10n,
|
||||
ILogger $log,
|
||||
IMailer $mailer,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator,
|
||||
IAppManager $appManager,
|
||||
IAvatarManager $avatarManager,
|
||||
AccountManager $accountManager,
|
||||
ISecureRandom $secureRandom,
|
||||
NewUserMailHelper $newUserMailHelper,
|
||||
Manager $keyManager,
|
||||
IJobList $jobList,
|
||||
IUserMountCache $userMountCache,
|
||||
IManager $encryptionManager) {
|
||||
IJobList $jobList) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
|
@ -144,18 +111,12 @@ class UsersController extends Controller {
|
|||
$this->config = $config;
|
||||
$this->isAdmin = $isAdmin;
|
||||
$this->l10n = $l10n;
|
||||
$this->log = $log;
|
||||
$this->mailer = $mailer;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->appManager = $appManager;
|
||||
$this->avatarManager = $avatarManager;
|
||||
$this->accountManager = $accountManager;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->newUserMailHelper = $newUserMailHelper;
|
||||
$this->keyManager = $keyManager;
|
||||
$this->jobList = $jobList;
|
||||
$this->userMountCache = $userMountCache;
|
||||
$this->encryptionManager = $encryptionManager;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
<template>
|
||||
<li>
|
||||
<!-- If item.href is set, a link will be directly used -->
|
||||
<a @click="item.action" v-if="item.href" :href="(item.href) ? item.href : '#' ">
|
||||
<span :class="item.icon"></span>
|
||||
<span>{{item.text}}</span>
|
||||
<span v-if="item.text">{{item.text}}</span>
|
||||
<p v-else-if="item.longtext">{{item.longtext}}</p>
|
||||
</a>
|
||||
<button @click="item.action" v-else>
|
||||
<!-- If item.action is set instead, a button will be used -->
|
||||
<button @click="item.action" v-else-if="item.action">
|
||||
<span :class="item.icon"></span>
|
||||
<span>{{item.text}}</span>
|
||||
<span v-if="item.text">{{item.text}}</span>
|
||||
<p v-else-if="item.longtext">{{item.longtext}}</p>
|
||||
</button>
|
||||
<!-- If item.longtext is set AND the item does not have an action -->
|
||||
<span v-else>
|
||||
<span :class="item.icon"></span>
|
||||
<span v-if="item.text">{{item.text}}</span>
|
||||
<p v-else-if="item.longtext">{{item.longtext}}</p>
|
||||
</span>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -132,9 +132,9 @@ export default {
|
|||
text: t('settings','Delete user'),
|
||||
action: this.deleteUser
|
||||
},{
|
||||
'icon': this.user.enabled ? 'icon-close' : 'icon-add',
|
||||
'text': this.user.enabled ? t('settings','Disable user') : t('settings','Enable user'),
|
||||
'action': this.enableDisableUser
|
||||
icon: this.user.enabled ? 'icon-close' : 'icon-add',
|
||||
text: this.user.enabled ? t('settings','Disable user') : t('settings','Enable user'),
|
||||
action: this.enableDisableUser
|
||||
}]
|
||||
},
|
||||
|
||||
|
|
|
@ -1,381 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Lukas Reschke
|
||||
* @copyright 2014 Lukas Reschke lukas@owncloud.com
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace Tests\Settings\Controller;
|
||||
|
||||
use OC\Group\Group;
|
||||
use OC\Group\MetaData;
|
||||
use OC\Settings\Controller\GroupsController;
|
||||
use OC\User\User;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
|
||||
/**
|
||||
* @package Tests\Settings\Controller
|
||||
*/
|
||||
class GroupsControllerTest extends \Test\TestCase {
|
||||
|
||||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $userSession;
|
||||
|
||||
/** @var GroupsController */
|
||||
private $groupsController;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
$this->groupsController = new GroupsController(
|
||||
'settings',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->groupManager,
|
||||
$this->userSession,
|
||||
true,
|
||||
$l
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
|
||||
* to test for subadmins. Thus the test always assumes you have admin permissions...
|
||||
*/
|
||||
public function testIndexSortByName() {
|
||||
$firstGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$firstGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('firstGroup'));
|
||||
$firstGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('First group'));
|
||||
$firstGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(12));
|
||||
$secondGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$secondGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('secondGroup'));
|
||||
$secondGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Second group'));
|
||||
$secondGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(25));
|
||||
$thirdGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$thirdGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('thirdGroup'));
|
||||
$thirdGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Third group'));
|
||||
$thirdGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(14));
|
||||
$fourthGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$fourthGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('admin'));
|
||||
$fourthGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Admin'));
|
||||
$fourthGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(18));
|
||||
/** @var \OC\Group\Group[] $groups */
|
||||
$groups = array();
|
||||
$groups[] = $firstGroup;
|
||||
$groups[] = $secondGroup;
|
||||
$groups[] = $thirdGroup;
|
||||
$groups[] = $fourthGroup;
|
||||
|
||||
$user = $this->getMockBuilder(User::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->userSession
|
||||
->expects($this->once())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($user));
|
||||
$user
|
||||
->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('MyAdminUser'));
|
||||
$this->groupManager->method('search')
|
||||
->will($this->returnValue($groups));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'data' => array(
|
||||
'adminGroups' => array(
|
||||
0 => array(
|
||||
'id' => 'admin',
|
||||
'name' => 'Admin',
|
||||
'usercount' => 0,//User count disabled 18,
|
||||
)
|
||||
),
|
||||
'groups' =>
|
||||
array(
|
||||
0 => array(
|
||||
'id' => 'firstGroup',
|
||||
'name' => 'First group',
|
||||
'usercount' => 0,//User count disabled 12,
|
||||
),
|
||||
1 => array(
|
||||
'id' => 'secondGroup',
|
||||
'name' => 'Second group',
|
||||
'usercount' => 0,//User count disabled 25,
|
||||
),
|
||||
2 => array(
|
||||
'id' => 'thirdGroup',
|
||||
'name' => 'Third group',
|
||||
'usercount' => 0,//User count disabled 14,
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$response = $this->groupsController->index('', false, MetaData::SORT_GROUPNAME);
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
|
||||
* to test for subadmins. Thus the test always assumes you have admin permissions...
|
||||
*/
|
||||
public function testIndexSortbyCount() {
|
||||
$firstGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$firstGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('firstGroup'));
|
||||
$firstGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('First group'));
|
||||
$firstGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(12));
|
||||
$secondGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$secondGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('secondGroup'));
|
||||
$secondGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Second group'));
|
||||
$secondGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(25));
|
||||
$thirdGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$thirdGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('thirdGroup'));
|
||||
$thirdGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Third group'));
|
||||
$thirdGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(14));
|
||||
$fourthGroup = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$fourthGroup
|
||||
->method('getGID')
|
||||
->will($this->returnValue('admin'));
|
||||
$fourthGroup
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('Admin'));
|
||||
$fourthGroup
|
||||
->method('count')
|
||||
->will($this->returnValue(18));
|
||||
/** @var \OC\Group\Group[] $groups */
|
||||
$groups = array();
|
||||
$groups[] = $firstGroup;
|
||||
$groups[] = $secondGroup;
|
||||
$groups[] = $thirdGroup;
|
||||
$groups[] = $fourthGroup;
|
||||
|
||||
$user = $this->getMockBuilder(User::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->userSession
|
||||
->expects($this->once())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($user));
|
||||
$user
|
||||
->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('MyAdminUser'));
|
||||
$this->groupManager
|
||||
->method('search')
|
||||
->will($this->returnValue($groups));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'data' => array(
|
||||
'adminGroups' => array(
|
||||
0 => array(
|
||||
'id' => 'admin',
|
||||
'name' => 'Admin',
|
||||
'usercount' => 18,
|
||||
)
|
||||
),
|
||||
'groups' =>
|
||||
array(
|
||||
0 => array(
|
||||
'id' => 'secondGroup',
|
||||
'name' => 'Second group',
|
||||
'usercount' => 25,
|
||||
),
|
||||
1 => array(
|
||||
'id' => 'thirdGroup',
|
||||
'name' => 'Third group',
|
||||
'usercount' => 14,
|
||||
),
|
||||
2 => array(
|
||||
'id' => 'firstGroup',
|
||||
'name' => 'First group',
|
||||
'usercount' => 12,
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$response = $this->groupsController->index();
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
public function testCreateWithExistingGroup() {
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('ExistingGroup')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'message' => 'Group already exists.'
|
||||
),
|
||||
Http::STATUS_CONFLICT
|
||||
);
|
||||
$response = $this->groupsController->create('ExistingGroup');
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
public function testCreateSuccessful() {
|
||||
$group = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue(false));
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue($group));
|
||||
$group
|
||||
->expects($this->once())
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('NewGroup'));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'groupname' => 'NewGroup'
|
||||
),
|
||||
Http::STATUS_CREATED
|
||||
);
|
||||
$response = $this->groupsController->create('NewGroup');
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
public function testCreateUnsuccessful() {
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('groupExists')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue(false));
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('NewGroup')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'status' => 'error',
|
||||
'data' => array('message' => 'Unable to add group.')
|
||||
),
|
||||
Http::STATUS_FORBIDDEN
|
||||
);
|
||||
$response = $this->groupsController->create('NewGroup');
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
public function testDestroySuccessful() {
|
||||
$group = $this->getMockBuilder(Group::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('ExistingGroup')
|
||||
->will($this->returnValue($group));
|
||||
$group
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->returnValue(true));
|
||||
$group
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue('ExistingGroup'));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'data' => array('groupname' => 'ExistingGroup')
|
||||
),
|
||||
Http::STATUS_NO_CONTENT
|
||||
);
|
||||
$response = $this->groupsController->destroy('ExistingGroup');
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
public function testDestroyUnsuccessful() {
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('ExistingGroup')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$expectedResponse = new DataResponse(
|
||||
array(
|
||||
'status' => 'error',
|
||||
'data' => array('message' => 'Unable to delete group.')
|
||||
),
|
||||
Http::STATUS_FORBIDDEN
|
||||
);
|
||||
$response = $this->groupsController->destroy('ExistingGroup');
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
}
|
3022
tests/Settings/Controller/UsersControllerTest.php
Normal file
3022
tests/Settings/Controller/UsersControllerTest.php
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue