Skip to content

Commit eb22a6c

Browse files
committed
Hide/Show observation edit based on edit permission
1 parent 574c5f9 commit eb22a6c

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

public/app/factories/user.service.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function UserService($rootScope, $q, $http, $location, $timeout, $window, LocalS
3030
deleteUser: deleteUser,
3131
clearUser: clearUser,
3232
getRoles: getRoles,
33+
hasPermission: hasPermission,
3334
addRecentEvent: addRecentEvent,
3435
getRecentEventId: getRecentEventId
3536
};
@@ -297,6 +298,10 @@ function UserService($rootScope, $q, $http, $location, $timeout, $window, LocalS
297298
return $http.get('/api/roles');
298299
}
299300

301+
function hasPermission(permission) {
302+
return _.contains(service.myself.role.permissions, permission);
303+
}
304+
300305
// TODO possibly name this addRecentEventForMyself
301306
function addRecentEvent(event) {
302307
return $http.post('/api/users/' + service.myself.id + '/events/' + event.id + '/recent');

public/app/observation/observation-feed.directive.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
</div>
3636

37-
<div style="height: 35px;">
37+
<div ng-if="canEdit" class="clearfix">
3838
<button class="btn btn-sm btn-primary pull-right" ng-click="editObservation()">Edit</button>
3939
</div>
4040
</div>

public/app/observation/observation-feed.directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ObservationNewsItemController.$inject = ['$scope', 'EventService', 'UserService'
1919

2020
function ObservationNewsItemController($scope, EventService, UserService) {
2121
$scope.edit = false;
22+
$scope.canEdit = UserService.hasPermission('UPDATE_OBSERVATION_EVENT') || UserService.hasPermission('UPDATE_OBSERVATION_ALL');
2223
$scope.fromNow = moment($scope.observation.properties.timestamp).fromNow();
2324

2425
UserService.getUser($scope.observation.userId).then(function(user) {

0 commit comments

Comments
 (0)