the template link in the left menu is only shown to owners/admins

This commit is contained in:
Henry Oswald 2014-07-16 11:02:45 +01:00
parent c93c8b3f7d
commit 46377aea3d
3 changed files with 20 additions and 17 deletions

View file

@ -110,8 +110,9 @@ aside#left-menu.full-size(
) )
option(value="pdfjs") Built-In option(value="pdfjs") Built-In
option(value="native") Native option(value="native") Native
h4 Publish span(ng-controller="TemplatesController", ng-show="hasPermission('admin')")
ul.list-unstyled.nav(ng-controller="TemplatesController") h4() Publish
ul.list-unstyled.nav()
li li
a(ng-click="openPublishTemplateModal()") a(ng-click="openPublishTemplateModal()")
i.fa.fa-list-alt.fa-fw i.fa.fa-list-alt.fa-fw

View file

@ -1,11 +1,12 @@
define [], () -> define [], () ->
class PermissionsManager class PermissionsManager
constructor: (@ide, @$scope) -> constructor: (@ide, @$scope) ->
@$scope.$watch "permissionsLevel", (permissionsLevel) =>
@$scope.permissions = @$scope.permissions =
read: false read: false
write: false write: false
admin: false admin: false
@$scope.$watch "permissionsLevel", (permissionsLevel) =>
if permissionsLevel? if permissionsLevel?
if permissionsLevel == "readOnly" if permissionsLevel == "readOnly"
@$scope.permissions.read = true @$scope.permissions.read = true
@ -17,3 +18,5 @@ define [], () ->
@$scope.permissions.write = true @$scope.permissions.write = true
@$scope.permissions.admin = true @$scope.permissions.admin = true
@$scope.hasPermission = (requestedLevel)=>
return @$scope.permissions[requestedLevel]

View file

@ -1,7 +1,9 @@
define [ define [
"base" "base"
], (App) -> "ide/permissions/PermissionsManager"
], (App, PermissionsManager) ->
App.controller "TemplatesController", ($scope, $modal, ide) -> App.controller "TemplatesController", ($scope, $modal, ide) ->
$scope.showPublishTemplateLinkInSideBar = ide.$scope.hasPermission("admin")
$scope.openPublishTemplateModal = () -> $scope.openPublishTemplateModal = () ->
console.log "open" console.log "open"
@ -12,8 +14,9 @@ define [
diff: () -> $scope.trackChanges.diff diff: () -> $scope.trackChanges.diff
} }
App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, diff, ide) -> App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
user_id = window.user.id #TODO this is not correct, it needs to be the owners id permissionsManager = new PermissionsManager(ide, $scope)
user_id = ide.$scope.user.id
$scope.template = $scope.template =
description: window.project_description description: window.project_description
$scope.publishedDetails = $scope.publishedDetails =
@ -25,7 +28,6 @@ define [
refreshPublishedStatus = -> refreshPublishedStatus = ->
ide.socket.emit "getPublishedDetails", user_id, (err, data)-> ide.socket.emit "getPublishedDetails", user_id, (err, data)->
console.log "got published details"
$scope.publishedDetails = data $scope.publishedDetails = data
$scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a") $scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
@ -35,19 +37,16 @@ define [
description = $scope.template.description description = $scope.template.description
if description? if description?
ide.socket.emit 'updateProjectDescription', description, () => ide.socket.emit 'updateProjectDescription', description, () =>
console.log "updated"
$scope.publish = -> $scope.publish = ->
$scope.state.publishInflight = true $scope.state.publishInflight = true
ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) => ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) =>
console.log "published"
refreshPublishedStatus() refreshPublishedStatus()
$scope.state.publishInflight = false $scope.state.publishInflight = false
$scope.unpublishTemplate = -> $scope.unpublishTemplate = ->
$scope.state.unpublishInflight = true $scope.state.unpublishInflight = true
ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) => ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) =>
console.log "unpublished"
refreshPublishedStatus() refreshPublishedStatus()
$scope.state.unpublishInflight = false $scope.state.unpublishInflight = false