Tobias Jeger pushed to branch feature/cmng-psp1 at cms-community / hippo-addon-channel-manager
Commits: f511261f by Tobias Jeger at 2016-03-09T12:37:40+01:00 CHANNELMGR-483: Remove the edit button when the user has no write access in the current channel. - - - - - 4 changed files: - frontend-ng/src/angularjs/api/session.service.js - frontend-ng/src/angularjs/api/session.service.spec.js - frontend-ng/src/angularjs/channel/channel.controller.js - frontend-ng/src/angularjs/channel/channel.html Changes: ===================================== frontend-ng/src/angularjs/api/session.service.js ===================================== --- a/frontend-ng/src/angularjs/api/session.service.js +++ b/frontend-ng/src/angularjs/api/session.service.js @@ -19,15 +19,20 @@ export class SessionService { 'ngInject'; this.HstService = HstService; - this.canWrite = false; + + this._canWrite = false; } initialize(channel) { return this.HstService .initializeSession(channel.hostname, channel.mountId) .then((canWrite) => { - this.canWrite = canWrite; + this._canWrite = canWrite; return channel; }); } + + hasWriteAccess() { + return this._canWrite; + } } ===================================== frontend-ng/src/angularjs/api/session.service.spec.js ===================================== --- a/frontend-ng/src/angularjs/api/session.service.spec.js +++ b/frontend-ng/src/angularjs/api/session.service.spec.js @@ -38,7 +38,7 @@ describe('SessionService', function () { }); it('should always be readonly before initialization', function () { - expect(sessionService.canWrite).toEqual(false); + expect(sessionService.hasWriteAccess()).toEqual(false); }); it('should resolve a promise with the channel argument when initialization is successful', function () { @@ -67,7 +67,7 @@ describe('SessionService', function () { sessionService.initialize(channelMock); deferred.resolve(true); $rootScope.$apply(); - expect(sessionService.canWrite).toEqual(true); + expect(sessionService.hasWriteAccess()).toEqual(true); }); }); ===================================== frontend-ng/src/angularjs/channel/channel.controller.js ===================================== --- a/frontend-ng/src/angularjs/channel/channel.controller.js +++ b/frontend-ng/src/angularjs/channel/channel.controller.js @@ -18,13 +18,14 @@ const SIDENAVS = ['components']; export class ChannelCtrl { - constructor($log, $mdSidenav, ChannelService, ScalingService) { + constructor($log, $mdSidenav, ChannelService, ScalingService, SessionService) { 'ngInject'; this.$log = $log; this.$mdSidenav = $mdSidenav; this.ChannelService = ChannelService; this.ScalingService = ScalingService; + this.SessionService = SessionService; this.iframeUrl = ChannelService.getUrl(); this.isEditMode = false; @@ -40,6 +41,10 @@ export class ChannelCtrl { this._closeSidenavs(); } + isEditable() { + return this.SessionService.hasWriteAccess(); + } + _closeSidenavs() { SIDENAVS.forEach((sidenav) => { if (this._isSidenavOpen(sidenav)) { ===================================== frontend-ng/src/angularjs/channel/channel.html ===================================== --- a/frontend-ng/src/angularjs/channel/channel.html +++ b/frontend-ng/src/angularjs/channel/channel.html @@ -22,7 +22,9 @@ {{ 'TOOLBAR_BUTTON_COMPONENTS' | translate }} </md-button> <span flex></span> - <md-button ng-click="channelCtrl.toggleEditMode()" ng-disabled="channelCtrl.isCreatingPreview"> + <md-button ng-if="channelCtrl.isEditable()" + ng-disabled="channelCtrl.isCreatingPreview" + ng-click="channelCtrl.toggleEditMode()"> <md-icon class="material-icons">{{ channelCtrl.isEditMode ? 'remove_red_eye' : 'mode_edit' }}</md-icon> {{ channelCtrl.isEditMode ? 'TOOLBAR_SWITCH_VIEWER_MODE_VIEW' : 'TOOLBAR_SWITCH_VIEWER_MODE_EDIT' | translate }} </md-button> View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/f511261faf919febd9b0c48f1cc0bfacbca9e832
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn