Fix getting permissions and active indicator
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -41,7 +41,7 @@ app.config(function ($provide, $routeProvider, $interpolateProvider, $httpProvid
|
||||
templateUrl: "/boardlist.mainView.html",
|
||||
controller: 'ListController',
|
||||
params: {
|
||||
filter: { value: '' }
|
||||
filter: { value: '', dynamic: true }
|
||||
}
|
||||
})
|
||||
.state('board', {
|
||||
|
||||
@@ -20,11 +20,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
app.run(function ($document, $rootScope, $transitions) {
|
||||
app.run(function ($document, $rootScope, $transitions, BoardService) {
|
||||
'use strict';
|
||||
$document.click(function (event) {
|
||||
$rootScope.$broadcast('documentClicked', event);
|
||||
});
|
||||
$transitions.onEnter({from: 'list'}, function($state, $transition$) {
|
||||
BoardService.unsetCurrrent();
|
||||
});
|
||||
$transitions.onEnter({to: 'list'}, function($state, $transition$) {
|
||||
BoardService.unsetCurrrent();
|
||||
});
|
||||
$transitions.onEnter({to: 'board.card'}, function ($state, $transition$) {
|
||||
$rootScope.sidebar.show = true;
|
||||
});
|
||||
@@ -40,9 +46,6 @@ app.run(function ($document, $rootScope, $transitions) {
|
||||
$transitions.onExit({from: 'board.detail'}, function ($state) {
|
||||
$rootScope.sidebar.show = false;
|
||||
});
|
||||
$transitions.onEnter({to: 'board.archive'}, function ($state) {
|
||||
//BoardController.loadArchived();
|
||||
});
|
||||
|
||||
$('link[rel="shortcut icon"]').attr(
|
||||
'href',
|
||||
|
||||
@@ -44,7 +44,9 @@ app.controller('ListController', function ($scope, $location, $filter, BoardServ
|
||||
|
||||
$scope.filterData = function () {
|
||||
angular.copy($scope.boardservice.getData(), $scope.boardservice.sorted);
|
||||
$scope.boardservice.sidebar = $filter('orderBy')($scope.boardservice.sorted, 'title');
|
||||
angular.copy($scope.boardservice.sorted, $scope.boardservice.sidebar);
|
||||
$scope.boardservice.sidebar = $filter('orderBy')($scope.boardservice.sidebar, 'title');
|
||||
$scope.boardservice.sidebar = $filter('cardFilter')($scope.boardservice.sidebar, {archived: false});
|
||||
|
||||
if ($scope.status.filter === 'archived') {
|
||||
var filter = {};
|
||||
|
||||
@@ -145,6 +145,12 @@ app.factory('ApiService', function($http, $q){
|
||||
return this.data[this.id];
|
||||
};
|
||||
|
||||
ApiService.prototype.unsetCurrrent = function () {
|
||||
this.id = null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
ApiService.prototype.getData = function() {
|
||||
return $.map(this.data, function(value, index) {
|
||||
return [value];
|
||||
|
||||
@@ -167,28 +167,31 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
||||
return false;
|
||||
}
|
||||
return this.getCurrent().permissions['PERMISSION_READ'];
|
||||
}
|
||||
};
|
||||
|
||||
BoardService.prototype.canEdit = function() {
|
||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||
return false;
|
||||
}
|
||||
return this.getCurrent().permissions['PERMISSION_EDIT'];
|
||||
}
|
||||
};
|
||||
|
||||
BoardService.prototype.canManage = function() {
|
||||
BoardService.prototype.canManage = function(board = null) {
|
||||
if(board !== null) {
|
||||
return board.permissions['PERMISSION_MANAGE'];
|
||||
}
|
||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||
return false;
|
||||
}
|
||||
return this.getCurrent().permissions['PERMISSION_MANAGE'];
|
||||
}
|
||||
};
|
||||
|
||||
BoardService.prototype.canShare = function() {
|
||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||
return false;
|
||||
}
|
||||
return this.getCurrent().permissions['PERMISSION_SHARE'];
|
||||
}
|
||||
};
|
||||
|
||||
BoardService.prototype.isArchived = function () {
|
||||
if(!this.getCurrent() || this.getCurrent().archived) {
|
||||
|
||||
@@ -34,6 +34,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
||||
protected $archived = false;
|
||||
protected $labels = [];
|
||||
protected $acl = [];
|
||||
protected $permissions = [];
|
||||
protected $shared;
|
||||
|
||||
public function __construct() {
|
||||
@@ -43,6 +44,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
||||
$this->addRelation('labels');
|
||||
$this->addRelation('acl');
|
||||
$this->addRelation('shared');
|
||||
$this->addRelation('permissions');
|
||||
$this->addResolvable('owner');
|
||||
$this->shared = -1;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,13 @@ class BoardService {
|
||||
$this->boardMapper->mapAcl($acl);
|
||||
}
|
||||
}
|
||||
$permissions = $this->permissionService->matchPermissions($item);
|
||||
$item->setPermissions([
|
||||
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
|
||||
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
|
||||
]);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\IPermissionMapper;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
@@ -50,7 +51,7 @@ class PermissionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user permissions for a board
|
||||
* Get current user permissions for a board by id
|
||||
*
|
||||
* @param $boardId
|
||||
* @return bool|array
|
||||
@@ -66,6 +67,24 @@ class PermissionService {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user permissions for a board
|
||||
*
|
||||
* @param Board $board
|
||||
* @return array|bool
|
||||
* @internal param $boardId
|
||||
*/
|
||||
public function matchPermissions(Board $board) {
|
||||
$owner = $this->userIsBoardOwner($board->getId());
|
||||
$acls = $board->getAcl();
|
||||
return [
|
||||
Acl::PERMISSION_READ => $owner || $this->userCan($acls, Acl::PERMISSION_READ),
|
||||
Acl::PERMISSION_EDIT => $owner || $this->userCan($acls, Acl::PERMISSION_EDIT),
|
||||
Acl::PERMISSION_MANAGE => $owner || $this->userCan($acls, Acl::PERMISSION_MANAGE),
|
||||
Acl::PERMISSION_SHARE => $owner || $this->userCan($acls, Acl::PERMISSION_SHARE),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* check permissions for replacing dark magic middleware
|
||||
*
|
||||
|
||||
@@ -26,20 +26,20 @@
|
||||
<button class="icon icon-more"></button>
|
||||
<div class="popovermenu bubble hidden">
|
||||
<ul>
|
||||
<li ng-if="boardservice.canManage() && !b.archived" ng-click="boardArchive(b)">
|
||||
<li ng-if="boardservice.canManage(b) && !b.archived" ng-click="boardArchive(b)">
|
||||
<a class="menuitem"><span class="icon-archive"></span> <?php p($l->t('Archive board')); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li ng-if="boardservice.canManage() && b.archived" ng-click="boardUnarchive(b)">
|
||||
<li ng-if="boardservice.canManage(b) && b.archived" ng-click="boardUnarchive(b)">
|
||||
<a class="menuitem"><span class="icon-archive"></span> <?php p($l->t('Unarchive board')); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li ng-if="boardservice.canManage() && b.archived" ng-click="boardDelete(b)">
|
||||
<li ng-if="boardservice.canManage(b) && b.archived" ng-click="boardDelete(b)">
|
||||
<a class="menuitem"><span class="icon-delete"></span> <?php p($l->t('Delete board')); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li ui-sref="board.detail({boardId: b.id})">
|
||||
<a class="menuitem"><span class="icon-settings-dark"></span> <?php p($l->t('Board settings')); ?>
|
||||
<a class="menuitem"><span class="icon-info"></span> <?php p($l->t('Board details')); ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<ul class="with-icon">
|
||||
|
||||
<li><a ui-sref="list({ filter: ''})" class="icon-deck"><?php p($l->t('All Boards')); ?></a></li>
|
||||
<li><a ui-sref="list({ filter: 'archived' })" class="icon-archive"><?php p($l->t('Archived boards')); ?></a></li>
|
||||
<li><a ui-sref="list({ filter: 'shared' })" class="icon-share"><?php p($l->t('Shared boards')); ?></a></li>
|
||||
<li ng-class="{active: status.filter === '' && !boardservice.getCurrent()}"><a ui-sref="list({ filter: ''})" class="icon-deck"><?php p($l->t('All Boards')); ?></a></li>
|
||||
<li ng-class="{active: status.filter === 'archived'}"><a ui-sref="list({ filter: 'archived' })" class="icon-archive"><?php p($l->t('Archived boards')); ?></a></li>
|
||||
<li ng-class="{active: status.filter === 'shared'}"><a ui-sref="list({ filter: 'shared' })" class="icon-share"><?php p($l->t('Shared boards')); ?></a></li>
|
||||
|
||||
<li class="with-icon with-menu" ng-class="{active: b.id === boardservice.getCurrent().id}" data-ng-repeat="b in boardservice.sidebar">
|
||||
<span class="board-bullet" style="background-color:#{{b.color}};" ng-if="!b.status.edit"> </span>
|
||||
|
||||
Reference in New Issue
Block a user