Skip to content

Commit

Permalink
Fix getting permissions and active indicator
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
juliusknorr committed Jun 8, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 90eb9ce commit 247b4dd
Showing 10 changed files with 62 additions and 20 deletions.
2 changes: 1 addition & 1 deletion js/app/Config.js
Original file line number Diff line number Diff line change
@@ -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', {
11 changes: 7 additions & 4 deletions js/app/Run.js
Original file line number Diff line number Diff line change
@@ -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',
4 changes: 3 additions & 1 deletion js/controller/ListController.js
Original file line number Diff line number Diff line change
@@ -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 = {};
8 changes: 7 additions & 1 deletion js/service/ApiService.js
Original file line number Diff line number Diff line change
@@ -145,7 +145,13 @@ app.factory('ApiService', function($http, $q){
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 [value];
});
13 changes: 8 additions & 5 deletions js/service/BoardService.js
Original file line number Diff line number Diff line change
@@ -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) {
2 changes: 2 additions & 0 deletions lib/Db/Board.php
Original file line number Diff line number Diff line change
@@ -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 @@ public function __construct() {
$this->addRelation('labels');
$this->addRelation('acl');
$this->addRelation('shared');
$this->addRelation('permissions');
$this->addResolvable('owner');
$this->shared = -1;
}
7 changes: 7 additions & 0 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
@@ -64,6 +64,13 @@ public function findAll($userInfo) {
$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;
}
}
21 changes: 20 additions & 1 deletion lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

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 @@ public function __construct(ILogger $logger, AclMapper $aclMapper, BoardMapper $
}

/**
* 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 @@ public function getPermissions($boardId) {
];
}

/**
* 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
*
8 changes: 4 additions & 4 deletions templates/part.boardlist.php
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 3 additions & 3 deletions templates/part.navigation.php
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 247b4dd

Please sign in to comment.