Check permissions in the directives tg-assigned-to and tg-wattchers
parent
f58d82c3fe
commit
ac3d49c8b1
|
@ -163,30 +163,41 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
|
||||||
#
|
#
|
||||||
# TODO: i18n
|
# TODO: i18n
|
||||||
template = _.template("""
|
template = _.template("""
|
||||||
|
<% if(isEditable){ %>
|
||||||
<div class="watchers-header">
|
<div class="watchers-header">
|
||||||
<span class="title">watchers</span>
|
<span class="title">watchers</span>
|
||||||
<a href="" title="Add watcher" class="icon icon-plus add-watcher"></a>
|
<a href="" title="Add watcher" class="icon icon-plus add-watcher"></a>
|
||||||
</div>
|
</div>
|
||||||
|
<% } else if(watchers.length > 0){ %>
|
||||||
|
<div class="watchers-header">
|
||||||
|
<span class="title">watchers</span>
|
||||||
|
</div>
|
||||||
|
<% }; %>
|
||||||
|
|
||||||
<% _.each(watchers, function(watcher) { %>
|
<% _.each(watchers, function(watcher) { %>
|
||||||
<div class="watcher-single">
|
<div class="watcher-single">
|
||||||
<div class="watcher-avatar">
|
<div class="watcher-avatar">
|
||||||
<a class="avatar" href="" title="Assigned to">
|
<span class="avatar" href="" title="<%- watcher.full_name_display %>">
|
||||||
<img src="<%= watcher.photo %>" alt="<%- watcher.full_name_display %>">
|
<img src="<%= watcher.photo %>" alt="<%- watcher.full_name_display %>">
|
||||||
</a>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="watcher-name">
|
<div class="watcher-name">
|
||||||
<span><%- watcher.full_name_display %></span>
|
<span><%- watcher.full_name_display %></span>
|
||||||
|
|
||||||
|
<% if(isEditable){ %>
|
||||||
<a class="icon icon-delete"
|
<a class="icon icon-delete"
|
||||||
data-watcher-id="<%= watcher.id %>" href="" title="delete-watcher">
|
data-watcher-id="<%= watcher.id %>" href="" title="delete-watcher">
|
||||||
</a>
|
</a>
|
||||||
|
<% }; %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
isEditable = ->
|
||||||
|
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
|
||||||
|
|
||||||
save = (model) ->
|
save = (model) ->
|
||||||
promise = $repo.save($model.$modelValue)
|
promise = $repo.save($model.$modelValue)
|
||||||
promise.then ->
|
promise.then ->
|
||||||
|
@ -199,20 +210,20 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
|
||||||
$confirm.notify("error")
|
$confirm.notify("error")
|
||||||
|
|
||||||
renderWatchers = (watchers) ->
|
renderWatchers = (watchers) ->
|
||||||
html = template({watchers: watchers})
|
ctx = {
|
||||||
|
watchers: watchers
|
||||||
|
isEditable: isEditable()
|
||||||
|
}
|
||||||
|
html = template(ctx)
|
||||||
$el.html(html)
|
$el.html(html)
|
||||||
|
|
||||||
if watchers.length == 0
|
if isEditable() and watchers.length == 0
|
||||||
$el.find(".title").text("Add watchers")
|
$el.find(".title").text("Add watchers")
|
||||||
$el.find(".watchers-header").addClass("no-watchers")
|
$el.find(".watchers-header").addClass("no-watchers")
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (item) ->
|
|
||||||
return if not item?
|
|
||||||
watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId])
|
|
||||||
renderWatchers(watchers)
|
|
||||||
|
|
||||||
$el.on "click", ".icon-delete", (event) ->
|
$el.on "click", ".icon-delete", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
return if not isEditable()
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
watcherId = target.data("watcher-id")
|
watcherId = target.data("watcher-id")
|
||||||
|
|
||||||
|
@ -231,6 +242,7 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
|
||||||
|
|
||||||
$el.on "click", ".add-watcher", (event) ->
|
$el.on "click", ".add-watcher", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
return if not isEditable()
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$rootscope.$broadcast("watcher:add", $model.$modelValue)
|
$rootscope.$broadcast("watcher:add", $model.$modelValue)
|
||||||
|
|
||||||
|
@ -244,6 +256,11 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
|
||||||
$model.$setViewValue(item)
|
$model.$setViewValue(item)
|
||||||
save(item)
|
save(item)
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (item) ->
|
||||||
|
return if not item?
|
||||||
|
watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId])
|
||||||
|
renderWatchers(watchers)
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
$scope.$on "$destroy", ->
|
||||||
$el.off()
|
$el.off()
|
||||||
|
|
||||||
|
@ -271,7 +288,7 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
|
||||||
<div class="assigned-to">
|
<div class="assigned-to">
|
||||||
<span class="assigned-title">Assigned to</span>
|
<span class="assigned-title">Assigned to</span>
|
||||||
|
|
||||||
<a href="" title="edit assignment" class="user-assigned editable">
|
<a href="" title="edit assignment" class="user-assigned <% if(isEditable){ %>editable<% }; %>">
|
||||||
<span class="assigned-name">
|
<span class="assigned-name">
|
||||||
<% if (assignedTo) { %>
|
<% if (assignedTo) { %>
|
||||||
<%- assignedTo.full_name_display %>
|
<%- assignedTo.full_name_display %>
|
||||||
|
@ -279,15 +296,18 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
|
||||||
Not assigned
|
Not assigned
|
||||||
<% } %>
|
<% } %>
|
||||||
</span>
|
</span>
|
||||||
<span class="icon icon-arrow-bottom"></span>
|
<% if(isEditable){ %><span class="icon icon-arrow-bottom"></span><% }; %>
|
||||||
</a>
|
</a>
|
||||||
<% if (assignedTo!==null) { %>
|
<% if (assignedTo!==null && isEditable) { %>
|
||||||
<a href="" title="delete assignment" class="icon icon-delete"></a>
|
<a href="" title="delete assignment" class="icon icon-delete"></a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
""")
|
""") # TODO: i18n
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
isEditable = ->
|
||||||
|
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
|
||||||
|
|
||||||
save = (model) ->
|
save = (model) ->
|
||||||
$loading.start($el)
|
$loading.start($el)
|
||||||
|
|
||||||
|
@ -304,25 +324,27 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
|
||||||
|
|
||||||
renderAssignedTo = (issue) ->
|
renderAssignedTo = (issue) ->
|
||||||
assignedToId = issue?.assigned_to
|
assignedToId = issue?.assigned_to
|
||||||
assignedTo = null
|
assignedTo = if assignedToId? then $scope.usersById[assignedToId] else null
|
||||||
assignedTo = $scope.usersById[assignedToId] if assignedToId?
|
|
||||||
html = template({assignedTo: assignedTo})
|
|
||||||
$el.html(html)
|
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (instance) ->
|
ctx = {
|
||||||
renderAssignedTo(instance)
|
assignedTo: assignedTo
|
||||||
|
isEditable: isEditable()
|
||||||
|
}
|
||||||
|
html = template(ctx)
|
||||||
|
$el.html(html)
|
||||||
|
|
||||||
$el.on "click", ".user-assigned", (event) ->
|
$el.on "click", ".user-assigned", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
return if not isEditable()
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$rootscope.$broadcast("assigned-to:add", $model.$modelValue)
|
$rootscope.$broadcast("assigned-to:add", $model.$modelValue)
|
||||||
|
|
||||||
$el.on "click", ".icon-delete", (event) ->
|
$el.on "click", ".icon-delete", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
title = "Remove assigned to"
|
return if not isEditable()
|
||||||
subtitle = ""
|
title = "Are you sure you want to leave it unassigned?" # TODO: i18n
|
||||||
|
|
||||||
$confirm.ask(title, subtitle).then (finish) =>
|
$confirm.ask(title).then (finish) =>
|
||||||
finish()
|
finish()
|
||||||
$model.$modelValue.assigned_to = null
|
$model.$modelValue.assigned_to = null
|
||||||
save($model.$modelValue)
|
save($model.$modelValue)
|
||||||
|
@ -331,6 +353,9 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
|
||||||
$model.$modelValue.assigned_to = userId
|
$model.$modelValue.assigned_to = userId
|
||||||
save($model.$modelValue)
|
save($model.$modelValue)
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (instance) ->
|
||||||
|
renderAssignedTo(instance)
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
$scope.$on "$destroy", ->
|
||||||
$el.off()
|
$el.off()
|
||||||
|
|
||||||
|
@ -339,7 +364,6 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
|
||||||
require:"ngModel"
|
require:"ngModel"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", AssignedToDirective])
|
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", AssignedToDirective])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ block content
|
||||||
div.duty-data(tg-issue-priority-button, ng-model="issue")
|
div.duty-data(tg-issue-priority-button, ng-model="issue")
|
||||||
div.duty-data(tg-issue-status-button, ng-model="issue")
|
div.duty-data(tg-issue-status-button, ng-model="issue")
|
||||||
|
|
||||||
section.duty-assigned-to(tg-assigned-to, ng-model="issue")
|
section.duty-assigned-to(tg-assigned-to, ng-model="issue", required-perm="modify_issue")
|
||||||
|
|
||||||
section.watchers(tg-watchers, ng-model="issue")
|
section.watchers(tg-watchers, ng-model="issue", required-perm="modify_issue")
|
||||||
|
|
||||||
section.us-detail-settings
|
section.us-detail-settings
|
||||||
tg-promote-issue-to-us-button(tg-check-permission="add_us", ng-model="issue")
|
tg-promote-issue-to-us-button(tg-check-permission="add_us", ng-model="issue")
|
||||||
|
|
|
@ -50,9 +50,9 @@ block content
|
||||||
div.duty-data-container
|
div.duty-data-container
|
||||||
div.duty-data(tg-task-status-button, ng-model="task")
|
div.duty-data(tg-task-status-button, ng-model="task")
|
||||||
|
|
||||||
section.duty-assigned-to(tg-assigned-to, ng-model="task")
|
section.duty-assigned-to(tg-assigned-to, ng-model="task", required-perm="modify_task")
|
||||||
|
|
||||||
section.watchers(tg-watchers, ng-model="task")
|
section.watchers(tg-watchers, ng-model="task", required-perm="modify_task")
|
||||||
|
|
||||||
section.us-detail-settings
|
section.us-detail-settings
|
||||||
fieldset(tg-task-is-iocaine-button, tg-check-permission="modify_task", ng-model="task")
|
fieldset(tg-task-is-iocaine-button, tg-check-permission="modify_task", ng-model="task")
|
||||||
|
|
|
@ -55,9 +55,9 @@ block content
|
||||||
div.duty-data-container
|
div.duty-data-container
|
||||||
div.duty-data(tg-us-status-button, ng-model="us")
|
div.duty-data(tg-us-status-button, ng-model="us")
|
||||||
|
|
||||||
section.duty-assigned-to(tg-assigned-to, ng-model="us")
|
section.duty-assigned-to(tg-assigned-to, ng-model="us", required-perm="modify_us")
|
||||||
|
|
||||||
section.watchers(tg-watchers, ng-model="us")
|
section.watchers(tg-watchers, ng-model="us", required-perm="modify_us")
|
||||||
|
|
||||||
section.us-detail-settings
|
section.us-detail-settings
|
||||||
tg-us-team-requirement-button(ng-model="us")
|
tg-us-team-requirement-button(ng-model="us")
|
||||||
|
|
Loading…
Reference in New Issue