Merge pull request #94 from nextcloud/use-ocs-api
Use OCS API to search for users/groups
This commit is contained in:
@@ -25,9 +25,6 @@ return [
|
|||||||
'routes' => [
|
'routes' => [
|
||||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||||
|
|
||||||
// share
|
|
||||||
['name' => 'share#searchUser', 'url' => '/share/search/{search}', 'verb' => 'GET'],
|
|
||||||
|
|
||||||
// boards
|
// boards
|
||||||
['name' => 'board#index', 'url' => '/boards', 'verb' => 'GET'],
|
['name' => 'board#index', 'url' => '/boards', 'verb' => 'GET'],
|
||||||
['name' => 'board#create', 'url' => '/boards', 'verb' => 'POST'],
|
['name' => 'board#create', 'url' => '/boards', 'verb' => 'POST'],
|
||||||
|
|||||||
@@ -866,3 +866,10 @@ button:hover {
|
|||||||
.icon-details-white {
|
.icon-details-white {
|
||||||
background-image: url('../img/details-white.svg');
|
background-image: url('../img/details-white.svg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hotfix for https://github.com/angular-ui/ui-select/issues/1652
|
||||||
|
*/
|
||||||
|
.ui-select-dropdown.select2-drop-active {
|
||||||
|
opacity: 1 !important;
|
||||||
|
}
|
||||||
@@ -119,12 +119,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
|||||||
$scope.statusservice.setError('Error occured', error);
|
$scope.statusservice.setError('Error occured', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
BoardService.searchUsers('%25');
|
|
||||||
|
|
||||||
$scope.searchForUser = function (search) {
|
$scope.searchForUser = function (search) {
|
||||||
if (search == "") {
|
|
||||||
search = "%25";
|
|
||||||
}
|
|
||||||
BoardService.searchUsers(search);
|
BoardService.searchUsers(search);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,30 +26,80 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
};
|
};
|
||||||
BoardService.prototype = angular.copy(ApiService.prototype);
|
BoardService.prototype = angular.copy(ApiService.prototype);
|
||||||
|
|
||||||
BoardService.prototype.searchUsers = function(search) {
|
BoardService.prototype.searchUsers = function (search) {
|
||||||
var url = OC.generateUrl('/apps/deck/share/search/'+search);
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.get(url).then(function (response) {
|
var searchData = {
|
||||||
|
format: 'json',
|
||||||
|
perPage: 4,
|
||||||
|
itemType: [0, 1]
|
||||||
|
};
|
||||||
|
if (search !== "") {
|
||||||
|
searchData.search = search;
|
||||||
|
}
|
||||||
|
$http({
|
||||||
|
method: 'GET',
|
||||||
|
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
|
||||||
|
params: searchData
|
||||||
|
})
|
||||||
|
.then(function (result) {
|
||||||
|
var response = result.data;
|
||||||
|
if (response.ocs.meta.statuscode !== 100) {
|
||||||
|
deferred.reject('Error while searching for sharees');
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.sharees = [];
|
self.sharees = [];
|
||||||
|
|
||||||
|
var users = response.ocs.data.exact.users.concat(response.ocs.data.users);
|
||||||
|
var groups = response.ocs.data.exact.groups.concat(response.ocs.data.groups);
|
||||||
|
|
||||||
// filter out everyone who is already in the share list
|
// filter out everyone who is already in the share list
|
||||||
angular.forEach(response.data, function(item) {
|
angular.forEach(users, function (item) {
|
||||||
var exists = false;
|
var exists = false;
|
||||||
angular.forEach(self.getCurrent().acl, function(acl) {
|
angular.forEach(self.getCurrent().acl, function (acl) {
|
||||||
if (acl.participant === item.participant) {
|
if (acl.participant.primaryKey === item.value.shareWith || OC.getCurrentUser() === item.value.shareWith) {
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!exists) {
|
if (!exists) {
|
||||||
self.sharees.push(item);
|
self.sharees.push({
|
||||||
|
boardId: null,
|
||||||
|
id: null,
|
||||||
|
owner: false,
|
||||||
|
participant: item.value.shareWith,
|
||||||
|
permissionEdit: true,
|
||||||
|
permissionManage: true,
|
||||||
|
permissionShare: true,
|
||||||
|
type: 'user'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
angular.forEach(groups, function (item) {
|
||||||
|
var exists = false;
|
||||||
|
angular.forEach(self.getCurrent().acl, function (acl) {
|
||||||
|
if (acl.participant.primaryKey === item.value.shareWith) {
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!exists) {
|
||||||
|
self.sharees.push({
|
||||||
|
boardId: null,
|
||||||
|
id: null,
|
||||||
|
owner: false,
|
||||||
|
participant: item.value.shareWith,
|
||||||
|
permissionEdit: true,
|
||||||
|
permissionManage: true,
|
||||||
|
permissionShare: true,
|
||||||
|
type: 'group'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(self.sharees);
|
||||||
}, function (error) {
|
}, function () {
|
||||||
deferred.reject('Error while update ' + self.endpoint);
|
deferred.reject('Error while searching for sharees');
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -130,13 +130,13 @@ class BoardController extends Controller {
|
|||||||
* @param $boardId
|
* @param $boardId
|
||||||
* @param $type
|
* @param $type
|
||||||
* @param $participant
|
* @param $participant
|
||||||
* @param $edit
|
* @param $permissionEdit
|
||||||
* @param $share
|
* @param $permissionShare
|
||||||
* @param $manage
|
* @param $permissionManage
|
||||||
* @return \OCP\AppFramework\Db\Entity
|
* @return \OCP\AppFramework\Db\Entity
|
||||||
*/
|
*/
|
||||||
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
|
public function addAcl($boardId, $type, $participant, $permissionEdit, $permissionShare, $permissionManage) {
|
||||||
return $this->boardService->addAcl($boardId, $type, $participant, $edit, $share, $manage);
|
return $this->boardService->addAcl($boardId, $type, $participant, $permissionEdit, $permissionShare, $permissionManage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
|
||||||
*
|
|
||||||
* @author Julius Härtl <jus@bitgrid.net>
|
|
||||||
*
|
|
||||||
* @license GNU AGPL version 3 or any later version
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\Deck\Controller;
|
|
||||||
|
|
||||||
use OCA\Deck\Db\Acl;
|
|
||||||
|
|
||||||
use OCA\Deck\Service\BoardService;
|
|
||||||
use OCP\IGroupManager;
|
|
||||||
use OCP\IRequest;
|
|
||||||
use OCP\AppFramework\Controller;
|
|
||||||
use OCP\IUserManager;
|
|
||||||
|
|
||||||
class ShareController extends Controller {
|
|
||||||
|
|
||||||
private $userManager;
|
|
||||||
private $groupManager;
|
|
||||||
private $boardService;
|
|
||||||
private $userId;
|
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, IUserManager $userManager, IGroupManager $groupManager, BoardService $boardService, $userId) {
|
|
||||||
parent::__construct($appName, $request);
|
|
||||||
$this->userManager = $userManager;
|
|
||||||
$this->groupManager = $groupManager;
|
|
||||||
$this->userId = $userId;
|
|
||||||
$this->boardService = $boardService;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @param $search
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function searchUser($search) {
|
|
||||||
$limit = 3;
|
|
||||||
$offset = null;
|
|
||||||
$result = [];
|
|
||||||
foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) {
|
|
||||||
$acl = new Acl();
|
|
||||||
$acl->setType('group');
|
|
||||||
$acl->setParticipant($group->getGID());
|
|
||||||
$acl->setPermissionEdit(true);
|
|
||||||
$acl->setPermissionShare(true);
|
|
||||||
$acl->setPermissionManage(true);
|
|
||||||
$result[] = $acl;
|
|
||||||
}
|
|
||||||
$limit = 10;
|
|
||||||
foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) {
|
|
||||||
if ($user->getUID() === $this->userId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$acl = new Acl();
|
|
||||||
$acl->setType('user');
|
|
||||||
$acl->setParticipant($user->getUID());
|
|
||||||
$acl->setPermissionEdit(true);
|
|
||||||
$acl->setPermissionShare(true);
|
|
||||||
$acl->setPermissionManage(true);
|
|
||||||
$result[] = $acl;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<div class="tabsContainer">
|
<div class="tabsContainer">
|
||||||
<div id="commentsTabView" class="tab commentsTabView" ng-if="status.boardtab==0 || !status.boardtab">
|
<div id="commentsTabView" class="tab commentsTabView" ng-if="status.boardtab==0 || !status.boardtab">
|
||||||
|
|
||||||
<ui-select ng-if="boardservice.canShare()" ng-model="status.addSharee" theme="select2" style="width:100%;" title="Choose a user to assign" placeholder="Assign users ..." on-select="aclAdd(status.addSharee)">
|
<ui-select ng-if="boardservice.canShare()" ng-model="status.addSharee" theme="select2" style="width:100%;" title="Choose a user to assign" placeholder="Assign users ..." on-select="aclAdd(status.addSharee)" search-enabled="true">
|
||||||
<ui-select-match placeholder="<?php p($l->t('Select users or groups to share with')); ?>">
|
<ui-select-match placeholder="<?php p($l->t('Select users or groups to share with')); ?>">
|
||||||
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span>
|
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span>
|
||||||
</ui-select-match>
|
</ui-select-match>
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
|
||||||
*
|
|
||||||
* @author Julius Härtl <jus@bitgrid.net>
|
|
||||||
*
|
|
||||||
* @license GNU AGPL version 3 or any later version
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\Deck\Controller;
|
|
||||||
|
|
||||||
use OCA\Deck\Db\Acl;
|
|
||||||
use OCP\IGroup;
|
|
||||||
use OCP\IUser;
|
|
||||||
|
|
||||||
class ShareControllerTest extends \PHPUnit_Framework_TestCase {
|
|
||||||
|
|
||||||
private $controller;
|
|
||||||
private $request;
|
|
||||||
private $userManager;
|
|
||||||
private $groupManager;
|
|
||||||
private $boardService;
|
|
||||||
private $permissionService;
|
|
||||||
private $userId = 'user';
|
|
||||||
|
|
||||||
public function setUp() {
|
|
||||||
$this->l10n = $this->request = $this->getMockBuilder(
|
|
||||||
'\OCP\IL10n')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->request = $this->getMockBuilder(
|
|
||||||
'\OCP\IRequest')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->userManager = $this->getMockBuilder(
|
|
||||||
'\OCP\IUserManager')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->groupManager = $this->getMockBuilder(
|
|
||||||
'\OCP\IGroupManager')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->boardService = $this->getMockBuilder(
|
|
||||||
'\OCA\Deck\Service\BoardService')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$this->groupManager->method('getUserGroupIds')
|
|
||||||
->willReturn(['admin', 'group1', 'group2']);
|
|
||||||
$this->userManager->method('get')
|
|
||||||
->with($this->userId)
|
|
||||||
->willReturn('user');
|
|
||||||
|
|
||||||
$this->controller = new ShareController(
|
|
||||||
'deck',
|
|
||||||
$this->request,
|
|
||||||
$this->userManager,
|
|
||||||
$this->groupManager,
|
|
||||||
$this->boardService,
|
|
||||||
$this->userId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testSearchGroup() {
|
|
||||||
$group = $this->getMockBuilder(IGroup::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$group->expects($this->once())
|
|
||||||
->method('getGID')
|
|
||||||
->willReturn('foo');
|
|
||||||
$groups = [$group];
|
|
||||||
$this->groupManager->expects($this->once())
|
|
||||||
->method('search')
|
|
||||||
->with('foo')
|
|
||||||
->willReturn($groups);
|
|
||||||
$this->userManager->expects($this->once())
|
|
||||||
->method('searchDisplayName')
|
|
||||||
->willReturn([]);
|
|
||||||
$actual = $this->controller->searchUser('foo');
|
|
||||||
|
|
||||||
$acl = new Acl();
|
|
||||||
$acl->setType('group');
|
|
||||||
$acl->setParticipant('foo');
|
|
||||||
$acl->setPermissionEdit(true);
|
|
||||||
$acl->setPermissionShare(true);
|
|
||||||
$acl->setPermissionManage(true);
|
|
||||||
$this->assertEquals([$acl], $actual);
|
|
||||||
}
|
|
||||||
public function testSearchUser() {
|
|
||||||
$user = $this->getMockBuilder(IUser::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$user->expects($this->any())
|
|
||||||
->method('getUID')
|
|
||||||
->willReturn('foo');
|
|
||||||
$users = [$user];
|
|
||||||
$this->groupManager->expects($this->once())
|
|
||||||
->method('search')
|
|
||||||
->willReturn([]);
|
|
||||||
|
|
||||||
$this->userManager->expects($this->once())
|
|
||||||
->method('searchDisplayName')
|
|
||||||
->with('foo')
|
|
||||||
->willReturn($users);
|
|
||||||
$actual = $this->controller->searchUser('foo');
|
|
||||||
|
|
||||||
$acl = new Acl();
|
|
||||||
$acl->setType('user');
|
|
||||||
$acl->setParticipant('foo');
|
|
||||||
$acl->setPermissionEdit(true);
|
|
||||||
$acl->setPermissionShare(true);
|
|
||||||
$acl->setPermissionManage(true);
|
|
||||||
$this->assertEquals([$acl], $actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSearchUserExcludeOwn() {
|
|
||||||
$user = $this->getMockBuilder(IUser::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$user->expects($this->any())
|
|
||||||
->method('getUID')
|
|
||||||
->willReturn('user');
|
|
||||||
$users = [$user];
|
|
||||||
$this->groupManager->expects($this->once())
|
|
||||||
->method('search')
|
|
||||||
->willReturn([]);
|
|
||||||
|
|
||||||
$this->userManager->expects($this->once())
|
|
||||||
->method('searchDisplayName')
|
|
||||||
->with('user')
|
|
||||||
->willReturn($users);
|
|
||||||
$actual = $this->controller->searchUser('user');
|
|
||||||
$this->assertEquals([], $actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user