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",
|
templateUrl: "/boardlist.mainView.html",
|
||||||
controller: 'ListController',
|
controller: 'ListController',
|
||||||
params: {
|
params: {
|
||||||
filter: { value: '' }
|
filter: { value: '', dynamic: true }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('board', {
|
.state('board', {
|
||||||
|
|||||||
@@ -20,11 +20,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.run(function ($document, $rootScope, $transitions) {
|
app.run(function ($document, $rootScope, $transitions, BoardService) {
|
||||||
'use strict';
|
'use strict';
|
||||||
$document.click(function (event) {
|
$document.click(function (event) {
|
||||||
$rootScope.$broadcast('documentClicked', 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$) {
|
$transitions.onEnter({to: 'board.card'}, function ($state, $transition$) {
|
||||||
$rootScope.sidebar.show = true;
|
$rootScope.sidebar.show = true;
|
||||||
});
|
});
|
||||||
@@ -40,9 +46,6 @@ app.run(function ($document, $rootScope, $transitions) {
|
|||||||
$transitions.onExit({from: 'board.detail'}, function ($state) {
|
$transitions.onExit({from: 'board.detail'}, function ($state) {
|
||||||
$rootScope.sidebar.show = false;
|
$rootScope.sidebar.show = false;
|
||||||
});
|
});
|
||||||
$transitions.onEnter({to: 'board.archive'}, function ($state) {
|
|
||||||
//BoardController.loadArchived();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('link[rel="shortcut icon"]').attr(
|
$('link[rel="shortcut icon"]').attr(
|
||||||
'href',
|
'href',
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ app.controller('ListController', function ($scope, $location, $filter, BoardServ
|
|||||||
|
|
||||||
$scope.filterData = function () {
|
$scope.filterData = function () {
|
||||||
angular.copy($scope.boardservice.getData(), $scope.boardservice.sorted);
|
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') {
|
if ($scope.status.filter === 'archived') {
|
||||||
var filter = {};
|
var filter = {};
|
||||||
|
|||||||
@@ -145,7 +145,13 @@ app.factory('ApiService', function($http, $q){
|
|||||||
return this.data[this.id];
|
return this.data[this.id];
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiService.prototype.getData = function() {
|
ApiService.prototype.unsetCurrrent = function () {
|
||||||
|
this.id = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ApiService.prototype.getData = function() {
|
||||||
return $.map(this.data, function(value, index) {
|
return $.map(this.data, function(value, index) {
|
||||||
return [value];
|
return [value];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -167,28 +167,31 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_READ'];
|
return this.getCurrent().permissions['PERMISSION_READ'];
|
||||||
}
|
};
|
||||||
|
|
||||||
BoardService.prototype.canEdit = function() {
|
BoardService.prototype.canEdit = function() {
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_EDIT'];
|
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) {
|
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_MANAGE'];
|
return this.getCurrent().permissions['PERMISSION_MANAGE'];
|
||||||
}
|
};
|
||||||
|
|
||||||
BoardService.prototype.canShare = function() {
|
BoardService.prototype.canShare = function() {
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_SHARE'];
|
return this.getCurrent().permissions['PERMISSION_SHARE'];
|
||||||
}
|
};
|
||||||
|
|
||||||
BoardService.prototype.isArchived = function () {
|
BoardService.prototype.isArchived = function () {
|
||||||
if(!this.getCurrent() || this.getCurrent().archived) {
|
if(!this.getCurrent() || this.getCurrent().archived) {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
|||||||
protected $archived = false;
|
protected $archived = false;
|
||||||
protected $labels = [];
|
protected $labels = [];
|
||||||
protected $acl = [];
|
protected $acl = [];
|
||||||
|
protected $permissions = [];
|
||||||
protected $shared;
|
protected $shared;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
@@ -43,6 +44,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
|||||||
$this->addRelation('labels');
|
$this->addRelation('labels');
|
||||||
$this->addRelation('acl');
|
$this->addRelation('acl');
|
||||||
$this->addRelation('shared');
|
$this->addRelation('shared');
|
||||||
|
$this->addRelation('permissions');
|
||||||
$this->addResolvable('owner');
|
$this->addResolvable('owner');
|
||||||
$this->shared = -1;
|
$this->shared = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ class BoardService {
|
|||||||
$this->boardMapper->mapAcl($acl);
|
$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;
|
$result[$item->getId()] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
|
|||||||
|
|
||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
use OCA\Deck\Db\AclMapper;
|
use OCA\Deck\Db\AclMapper;
|
||||||
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
use OCA\Deck\Db\IPermissionMapper;
|
use OCA\Deck\Db\IPermissionMapper;
|
||||||
use OCA\Deck\NoPermissionException;
|
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
|
* @param $boardId
|
||||||
* @return bool|array
|
* @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
|
* check permissions for replacing dark magic middleware
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -26,20 +26,20 @@
|
|||||||
<button class="icon icon-more"></button>
|
<button class="icon icon-more"></button>
|
||||||
<div class="popovermenu bubble hidden">
|
<div class="popovermenu bubble hidden">
|
||||||
<ul>
|
<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 class="menuitem"><span class="icon-archive"></span> <?php p($l->t('Archive board')); ?>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</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 class="menuitem"><span class="icon-archive"></span> <?php p($l->t('Unarchive board')); ?>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</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 class="menuitem"><span class="icon-delete"></span> <?php p($l->t('Delete board')); ?>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li ui-sref="board.detail({boardId: b.id})">
|
<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>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<ul class="with-icon">
|
<ul class="with-icon">
|
||||||
|
|
||||||
<li><a ui-sref="list({ filter: ''})" class="icon-deck"><?php p($l->t('All 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><a ui-sref="list({ filter: 'archived' })" class="icon-archive"><?php p($l->t('Archived 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><a ui-sref="list({ filter: 'shared' })" class="icon-share"><?php p($l->t('Shared 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">
|
<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>
|
<span class="board-bullet" style="background-color:#{{b.color}};" ng-if="!b.status.edit"> </span>
|
||||||
|
|||||||
Reference in New Issue
Block a user