diff --git a/services/web/app/views/project/editor/left-menu.jade b/services/web/app/views/project/editor/left-menu.jade index ea1f141671..c24a2622bc 100644 --- a/services/web/app/views/project/editor/left-menu.jade +++ b/services/web/app/views/project/editor/left-menu.jade @@ -110,12 +110,13 @@ aside#left-menu.full-size( ) option(value="pdfjs") Built-In option(value="native") Native - h4 Publish - ul.list-unstyled.nav(ng-controller="TemplatesController") - li - a(ng-click="openPublishTemplateModal()") - i.fa.fa-list-alt.fa-fw - |   Publish as Template + span(ng-controller="TemplatesController", ng-show="hasPermission('admin')") + h4() Publish + ul.list-unstyled.nav() + li + a(ng-click="openPublishTemplateModal()") + i.fa.fa-list-alt.fa-fw + |   Publish as Template #left-menu-mask( diff --git a/services/web/public/coffee/ide/permissions/PermissionsManager.coffee b/services/web/public/coffee/ide/permissions/PermissionsManager.coffee index b52ab933e4..8ce6549647 100644 --- a/services/web/public/coffee/ide/permissions/PermissionsManager.coffee +++ b/services/web/public/coffee/ide/permissions/PermissionsManager.coffee @@ -1,11 +1,12 @@ define [], () -> class PermissionsManager constructor: (@ide, @$scope) -> + @$scope.permissions = + read: false + write: false + admin: false @$scope.$watch "permissionsLevel", (permissionsLevel) => - @$scope.permissions = - read: false - write: false - admin: false + if permissionsLevel? if permissionsLevel == "readOnly" @$scope.permissions.read = true @@ -17,3 +18,5 @@ define [], () -> @$scope.permissions.write = true @$scope.permissions.admin = true + @$scope.hasPermission = (requestedLevel)=> + return @$scope.permissions[requestedLevel] \ No newline at end of file diff --git a/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee b/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee index e71e4eab42..11fa29a4fe 100644 --- a/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee +++ b/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee @@ -1,7 +1,9 @@ define [ "base" -], (App) -> + "ide/permissions/PermissionsManager" +], (App, PermissionsManager) -> App.controller "TemplatesController", ($scope, $modal, ide) -> + $scope.showPublishTemplateLinkInSideBar = ide.$scope.hasPermission("admin") $scope.openPublishTemplateModal = () -> console.log "open" @@ -12,8 +14,9 @@ define [ diff: () -> $scope.trackChanges.diff } - App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, diff, ide) -> - user_id = window.user.id #TODO this is not correct, it needs to be the owners id + App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) -> + permissionsManager = new PermissionsManager(ide, $scope) + user_id = ide.$scope.user.id $scope.template = description: window.project_description $scope.publishedDetails = @@ -25,7 +28,6 @@ define [ refreshPublishedStatus = -> ide.socket.emit "getPublishedDetails", user_id, (err, data)-> - console.log "got published details" $scope.publishedDetails = data $scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a") @@ -35,19 +37,16 @@ define [ description = $scope.template.description if description? ide.socket.emit 'updateProjectDescription', description, () => - console.log "updated" $scope.publish = -> $scope.state.publishInflight = true ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) => - console.log "published" refreshPublishedStatus() $scope.state.publishInflight = false $scope.unpublishTemplate = -> $scope.state.unpublishInflight = true ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) => - console.log "unpublished" refreshPublishedStatus() $scope.state.unpublishInflight = false