Commit 554a7b45 authored by Ujvari Gergely's avatar Ujvari Gergely

Move authorization info to the annotation directive.

This way the auth('delete') and auth('update) is calculated only once per annotation
parent b36fa4ff
......@@ -13,8 +13,21 @@ annotation = ['$filter', 'annotator', ($filter, annotator) ->
scope.$watch 'model.$modelValue.id', (id) ->
scope.thread = annotator.threading.idTable[id]
scope.auth = {}
scope.auth.delete =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'delete', scope.model.$modelValue
else
true
scope.auth.update =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'update', scope.model.$modelValue
else
true
# Publish the controller
scope.model = controller
controller: 'AnnotationController'
priority: 100 # Must run before ngModel
require: '?ngModel'
......
......@@ -696,12 +696,6 @@ class Annotation
$scope.model.$modelValue.text = ''
$scope.model.$modelValue.tags = ''
$scope.authorize = (action) ->
if $scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize action, $scope.model.$modelValue
else
true
$scope.$on '$routeChangeStart', -> $scope.cancel() if $scope.editing
$scope.$on '$routeUpdate', -> $scope.cancel() if $scope.editing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment