Use OCS API to search for users/groups

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-04-26 10:57:19 +02:00
parent 6ae6bdf74a
commit c1ff005710
5 changed files with 87 additions and 35 deletions

View File

@@ -866,3 +866,10 @@ button:hover {
.icon-details-white {
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;
}

View File

@@ -119,12 +119,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
$scope.statusservice.setError('Error occured', error);
});
BoardService.searchUsers('%25');
$scope.searchForUser = function (search) {
if (search == "") {
search = "%25";
}
BoardService.searchUsers(search);
};

View File

@@ -26,32 +26,82 @@ app.factory('BoardService', function(ApiService, $http, $q){
};
BoardService.prototype = angular.copy(ApiService.prototype);
BoardService.prototype.searchUsers = function(search) {
var url = OC.generateUrl('/apps/deck/share/search/'+search);
var deferred = $q.defer();
var self = this;
$http.get(url).then(function (response) {
BoardService.prototype.searchUsers = function (search) {
var deferred = $q.defer();
var self = this;
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 = [];
// filter out everyone who is already in the share list
angular.forEach(response.data, function(item) {
var exists = false;
angular.forEach(self.getCurrent().acl, function(acl) {
if (acl.participant === item.participant) {
exists = true;
}
});
if(!exists) {
self.sharees.push(item);
}
});
var users = response.ocs.data.exact.users.concat(response.ocs.data.users);
var groups = response.ocs.data.exact.groups.concat(response.ocs.data.groups);
deferred.resolve(response.data);
}, function (error) {
deferred.reject('Error while update ' + self.endpoint);
});
return deferred.promise;
};
// filter out everyone who is already in the share list
angular.forEach(users, function (item) {
var exists = false;
angular.forEach(self.getCurrent().acl, function (acl) {
if (acl.participant.primaryKey === item.value.shareWith || OC.getCurrentUser() === 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: '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(self.sharees);
}, function () {
deferred.reject('Error while searching for sharees');
});
return deferred.promise;
};
BoardService.prototype.addAcl = function(acl) {
var board = this.getCurrent();

View File

@@ -130,13 +130,13 @@ class BoardController extends Controller {
* @param $boardId
* @param $type
* @param $participant
* @param $edit
* @param $share
* @param $manage
* @param $permissionEdit
* @param $permissionShare
* @param $permissionManage
* @return \OCP\AppFramework\Db\Entity
*/
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
return $this->boardService->addAcl($boardId, $type, $participant, $edit, $share, $manage);
public function addAcl($boardId, $type, $participant, $permissionEdit, $permissionShare, $permissionManage) {
return $this->boardService->addAcl($boardId, $type, $participant, $permissionEdit, $permissionShare, $permissionManage);
}
/**

View File

@@ -17,7 +17,7 @@
<div class="tabsContainer">
<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')); ?>">
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span>
</ui-select-match>