AMBARI-22263. Disable Actions menu while Wizard in progress instead of hide (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/84342f6a Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/84342f6a Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/84342f6a Branch: refs/heads/feature-branch-AMBARI-21307 Commit: 84342f6a851daa12ef612a96e0076ea893fd12f2 Parents: ee509e0 Author: Alex Antonenko <[email protected]> Authored: Wed Oct 18 18:26:08 2017 +0300 Committer: Alex Antonenko <[email protected]> Committed: Wed Oct 18 18:26:08 2017 +0300 ---------------------------------------------------------------------- ambari-web/app/app.js | 24 ++- .../models/configs/service_config_version.js | 9 +- ambari-web/app/models/host_stack_version.js | 4 +- .../common/configs/config_history_flow.hbs | 8 +- .../common/configs/service_version_box.hbs | 8 +- .../templates/common/host_progress_popup.hbs | 6 +- .../modal_popups/widget_browser_popup.hbs | 6 +- ambari-web/app/templates/experimental.hbs | 6 +- .../main/admin/stack_upgrade/versions.hbs | 6 +- ambari-web/app/templates/main/host.hbs | 4 +- .../templates/main/host/bulk_operation_menu.hbs | 4 +- .../main/host/details/host_component.hbs | 176 ++++++++++--------- .../app/templates/main/host/stack_versions.hbs | 4 +- ambari-web/app/templates/main/host/summary.hbs | 120 +++++++------ ambari-web/app/utils/helper.js | 23 +++ ambari-web/app/views/main/service/item.js | 2 +- ambari-web/test/views/main/service/item_test.js | 6 +- 17 files changed, 224 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/app.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/app.js b/ambari-web/app/app.js index 2c638e4..6432849 100644 --- a/ambari-web/app/app.js +++ b/ambari-web/app/app.js @@ -131,27 +131,18 @@ module.exports = Em.Application.create({ }.property('upgradeIsRunning', 'upgradeAborted', 'router.wizardWatcherController.isNonWizardUser', 'upgradeSuspended'), /** - * Options: - * - ignoreWizard: ignore when some wizard is running by another user (default `false`) - * * @param {string} authRoles - * @param {object} options * @returns {boolean} */ - isAuthorized: function (authRoles, options) { - options = $.extend({ignoreWizard: false}, options); + havePermissions: function (authRoles) { var result = false; authRoles = $.map(authRoles.split(","), $.trim); // When Upgrade running(not suspended) only operations related to upgrade should be allowed if ((!this.get('upgradeSuspended') && !authRoles.contains('CLUSTER.UPGRADE_DOWNGRADE_STACK')) && - !App.get('supports.opsDuringRollingUpgrade') && - !['NOT_REQUIRED', 'COMPLETED'].contains(this.get('upgradeState')) || - !App.auth){ - return false; - } - - if (!options.ignoreWizard && App.router.get('wizardWatcherController.isNonWizardUser')) { + !App.get('supports.opsDuringRollingUpgrade') && + !['NOT_REQUIRED', 'COMPLETED'].contains(this.get('upgradeState')) || + !App.auth){ return false; } @@ -161,6 +152,13 @@ module.exports = Em.Application.create({ return result; }, + /** + * @param {string} authRoles + * @returns {boolean} + */ + isAuthorized: function (authRoles) { + return this.havePermissions(authRoles) && !App.router.get('wizardWatcherController.isNonWizardUser'); + }, isStackServicesLoaded: false, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/models/configs/service_config_version.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/configs/service_config_version.js b/ambari-web/app/models/configs/service_config_version.js index 4120681..7645377 100644 --- a/ambari-web/app/models/configs/service_config_version.js +++ b/ambari-web/app/models/configs/service_config_version.js @@ -141,12 +141,13 @@ App.ServiceConfigVersion = DS.Model.extend({ * {{view: (string|boolean), compare: (string|boolean), revert: (string|boolean)}} disabledActionAttr */ disabledActionAttr: function () { + var isNonWizardUser = App.router.get('wizardWatcherController.isNonWizardUser'); return { - view: (this.get('isDisplayed')) ? 'disabled' : false, - compare: (this.get('isDisabled') || this.get('isDisplayed')) ? 'disabled' : false, - revert: (this.get('isDisabled') || this.get('isCurrent')) ? 'disabled' : false + view: (this.get('isDisplayed') || isNonWizardUser) ? 'disabled' : false, + compare: (this.get('isDisabled') || isNonWizardUser || this.get('isDisplayed')) ? 'disabled' : false, + revert: (this.get('isDisabled') || isNonWizardUser || this.get('isCurrent')) ? 'disabled' : false } - }.property('isDisplayed', 'isCurrent', 'isDisabled') + }.property('isDisplayed', 'isCurrent', 'isDisabled', 'App.router.wizardWatcherController.isNonWizardUser') }); App.ServiceConfigVersion.FIXTURES = []; http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/models/host_stack_version.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/host_stack_version.js b/ambari-web/app/models/host_stack_version.js index 7e6d0a0..15e62f4 100644 --- a/ambari-web/app/models/host_stack_version.js +++ b/ambari-web/app/models/host_stack_version.js @@ -61,7 +61,9 @@ App.HostStackVersion = DS.Model.extend({ */ installEnabled: Em.computed.existsIn('status', ['OUT_OF_SYNC', 'INSTALL_FAILED']), - installDisabled: Em.computed.not('installEnabled') + installDisabled: function(){ + return !this.get('installEnabled') || App.router.get('wizardWatcherController.isNonWizardUser'); + }.property('installEnabled', 'App.routerwizardWatcherController.isNonWizardUser') }); App.HostStackVersion.FIXTURES = []; http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/configs/config_history_flow.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/configs/config_history_flow.hbs b/ambari-web/app/templates/common/configs/config_history_flow.hbs index f063406..99cd140 100644 --- a/ambari-web/app/templates/common/configs/config_history_flow.hbs +++ b/ambari-web/app/templates/common/configs/config_history_flow.hbs @@ -70,12 +70,12 @@ </div> <div class="version-operations-buttons"> <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.view" class=":btn :btn-default view.parentView.hoveredServiceVersion.isDisplayed:not-allowed-cursor" title="view.parentView.hoveredServiceVersion.disabledActionMessages.view"}} {{action doAction undefined view.parentView.actionTypes.SWITCH target="view.parentView"}}><i class="glyphicon glyphicon-search"></i> {{t common.view}}</button> - {{#isAuthorized "SERVICE.COMPARE_CONFIGS"}} + {{#havePermissions "SERVICE.COMPARE_CONFIGS"}} <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.compare" class=":btn :btn-default view.parentView.hoveredServiceVersion.isDisplayed:not-allowed-cursor" title="view.parentView.hoveredServiceVersion.disabledActionMessages.compare"}} {{action doAction undefined view.parentView.actionTypes.COMPARE target="view.parentView"}}><i class="glyphicon glyphicon-copy"></i> {{t common.compare}}</button> - {{/isAuthorized}} - {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}} + {{/havePermissions}} + {{#havePermissions "SERVICE.MODIFY_CONFIGS"}} <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.revert" class=":btn :btn-default view.parentView.hoveredServiceVersion.isCurrent:not-allowed-cursor view.parentView.hoveredServiceVersion.isCompatible::hidden" title="view.parentView.hoveredServiceVersion.disabledActionMessages.revert"}} {{action doAction undefined view.parentView.actionTypes.REVERT target="view.parentView"}}>{{t dashboard.configHistory.info-bar.revert.button}}</button> - {{/isAuthorized}} + {{/havePermissions}} </div> {{/if}} {{/view}} http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/configs/service_version_box.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/configs/service_version_box.hbs b/ambari-web/app/templates/common/configs/service_version_box.hbs index aaa4520..738b83d 100644 --- a/ambari-web/app/templates/common/configs/service_version_box.hbs +++ b/ambari-web/app/templates/common/configs/service_version_box.hbs @@ -46,16 +46,16 @@ <button {{bindAttr disabled="view.disabledActionAttr.view" class=":btn :btn-default view.serviceVersion.isDisplayed:not-allowed-cursor" title="view.disabledActionMessages.view"}} {{action doAction view.serviceVersion view.actionTypes.SWITCH target="view.parentView"}}> <i class="glyphicon glyphicon-search"></i> {{t common.view}} </button> - {{#isAuthorized "SERVICE.COMPARE_CONFIGS"}} + {{#havePermissions "SERVICE.COMPARE_CONFIGS"}} <button {{bindAttr disabled="view.disabledActionAttr.compare" class=":btn :btn-default view.serviceVersion.isDisplayed:not-allowed-cursor" title="view.disabledActionMessages.compare"}} {{action doAction view.serviceVersion view.actionTypes.COMPARE target="view.parentView"}}> <i class="glyphicon glyphicon-copy"></i> {{t common.compare}} </button> - {{/isAuthorized}} - {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}} + {{/havePermissions}} + {{#havePermissions "SERVICE.MODIFY_CONFIGS"}} <button {{bindAttr disabled="view.disabledActionAttr.revert" class=":btn :btn-default view.serviceVersion.isCurrent:not-allowed-cursor view.serviceVersion.isCompatible::hidden" title="view.disabledActionMessages.revert"}} {{action doAction view.serviceVersion view.actionTypes.REVERT target="view.parentView"}}> {{t dashboard.configHistory.info-bar.revert.button}} </button> - {{/isAuthorized}} + {{/havePermissions}} </div> </div> </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/host_progress_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/host_progress_popup.hbs b/ambari-web/app/templates/common/host_progress_popup.hbs index f5b1c73..31358e4 100644 --- a/ambari-web/app/templates/common/host_progress_popup.hbs +++ b/ambari-web/app/templates/common/host_progress_popup.hbs @@ -256,11 +256,11 @@ <div class="col-sm-12"> {{#if App.supports.logSearch}} {{#if view.isLogSearchInstalled}} - {{#isAuthorized "SERVICE.VIEW_OPERATIONAL_LOGS"}} - <button type="button" class="btn btn-link pull-right" {{action navigateToHostLogs target="view"}} {{bindAttr class="view.isLogsLinkVisible::hidden"}}> + {{#havePermissions "SERVICE.VIEW_OPERATIONAL_LOGS"}} + <button type="button" class="btn btn-link pull-right" {{action navigateToHostLogs target="view"}} {{bindAttr class="view.isLogsLinkVisible::hidden" disabled="App.router.wizardWatcherController.isNonWizardUser"}}> <i class="glyphicon glyphicon-file"></i> {{t common.host}} {{t common.logs}} </button> - {{/isAuthorized}} + {{/havePermissions}} {{/if}} {{/if}} <button type="button" class="btn btn-link pull-right" {{translateAttr title="common.openNewWindow"}} {{action openTaskLogInDialog}}> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs index 2cc40c2..9910d07 100644 --- a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs +++ b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs @@ -26,13 +26,13 @@ <li {{bindAttr class="service.isActive:active"}}> <a {{action "filterByService" service.value target="view"}}>{{service.label}}</a></li> {{/each}} - {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}} + {{#havePermissions "SERVICE.MODIFY_CONFIGS"}} <li class="pull-right"> - <button type="button" class="btn btn-primary" {{action "createWidget" target="view"}} > + <button type="button" class="btn btn-primary" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action "createWidget" target="view"}} > <i class="glyphicon glyphicon-plus"></i> {{t dashboard.widgets.create}} </button> </li> - {{/isAuthorized}} + {{/havePermissions}} </ul> <!--Widgets table two column--> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/experimental.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/experimental.hbs b/ambari-web/app/templates/experimental.hbs index c3d9eba..80d9e3d 100644 --- a/ambari-web/app/templates/experimental.hbs +++ b/ambari-web/app/templates/experimental.hbs @@ -56,14 +56,14 @@ </div> <hr> <div class="control-group" style="margin-bottom: 100px;"> - {{#isAuthorized "CLUSTER.MANAGE_USER_PERSISTED_DATA"}} + {{#havePermissions "CLUSTER.MANAGE_USER_PERSISTED_DATA"}} <div class="pull-left" style="margin-bottom: 100px;"> - <button class="btn btn-danger" {{action doResetUIStates target="controller"}}>{{t reset.ui.states}}</button> + <button class="btn btn-danger" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action doResetUIStates target="controller"}}>{{t reset.ui.states}}</button> <p class="pull-right" style="margin-left: 10px; padding-top: 5px;"> Reset UI state locally and on the server </p> </div> - {{/isAuthorized}} + {{/havePermissions}} </div> {{else}} <div class="alert alert-danger"> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs b/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs index edcb37c..47f9a2d 100644 --- a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs +++ b/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs @@ -17,11 +17,11 @@ }} <div id="versions-filter-section" class="btn-toolbar"> - {{#isAuthorized "AMBARI.MANAGE_STACK_VERSIONS"}} - <button class="btn btn-primary" {{action goToVersions target="view"}} id="manage-versions-link"> + {{#havePermissions "AMBARI.MANAGE_STACK_VERSIONS"}} + <button class="btn btn-primary" {{action goToVersions target="view"}} {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} id="manage-versions-link"> <i class="icon-external-link"></i> {{t admin.stackVersions.manageVersions}} </button> - {{/isAuthorized}} + {{/havePermissions}} <div class="btn-group display-inline-block"> <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#"> <span class="filters-label">{{t common.filter}}: </span> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host.hbs b/ambari-web/app/templates/main/host.hbs index b373c40..07a9e7f 100644 --- a/ambari-web/app/templates/main/host.hbs +++ b/ambari-web/app/templates/main/host.hbs @@ -22,9 +22,9 @@ <h2 class="table-title col-sm-1">{{t common.hosts}}</h2> <div class="table-controls row col-sm-10 pull-right"> <div class="col-sm-12"> - {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE, HOST.ADD_DELETE_HOSTS"}} + {{#havePermissions "HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE, HOST.ADD_DELETE_HOSTS"}} {{view App.HostTableMenuView}} - {{/isAuthorized}} + {{/havePermissions}} <div class="col-sm-10 pull-right"> {{outlet}} </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs b/ambari-web/app/templates/main/host/bulk_operation_menu.hbs index 89551ca..d7bf8bd 100644 --- a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs +++ b/ambari-web/app/templates/main/host/bulk_operation_menu.hbs @@ -16,7 +16,8 @@ * limitations under the License. }} -<button class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#">{{t common.actions}} <span class="caret"></span></button> +<button class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}}>{{t common.actions}} <span class="caret"></span></button> +{{#unless App.router.wizardWatcherController.isNonWizardUser}} <ul class="dropdown-menu"> {{#isAuthorized "HOST.ADD_DELETE_HOSTS"}} <li><a href="#" {{action addHost}}><i class="glyphicon glyphicon-plus glyphicon-white"></i> {{t hosts.host.add}}</a></li> @@ -151,3 +152,4 @@ </div> </li> </ul> +{{/unless}} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/details/host_component.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/details/host_component.hbs b/ambari-web/app/templates/main/host/details/host_component.hbs index d94dd3b..28d2acf 100644 --- a/ambari-web/app/templates/main/host/details/host_component.hbs +++ b/ambari-web/app/templates/main/host/details/host_component.hbs @@ -54,112 +54,114 @@ </span> </div> <div class="col-md-5 col-lg-4"> - {{#isAuthorized "SERVICE.DECOMMISSION_RECOMMISSION"}} + {{#havePermissions "SERVICE.DECOMMISSION_RECOMMISSION"}} <div class="dropdown"> - <button {{ bindAttr class="view.disabled :btn :btn-default :btn-block :dropdown-toggle"}} data-toggle="dropdown"> + <button {{ bindAttr class="view.disabled :btn :btn-default :btn-block :dropdown-toggle" disabled="App.router.wizardWatcherController.isNonWizardUser"}} data-toggle="dropdown"> {{view.componentTextStatus}} <span class="caret pull-right button-caret-margin"></span> </button> - <ul class="dropdown-menu"> - {{#if view.isComponentDecommissionAvailable}} - {{view view.decommissionView}} - {{/if}} - {{#if view.isComponentRecommissionAvailable}} - {{view view.decommissionView}} - {{/if}} - {{#if view.isRestartableComponent}} - <li {{bindAttr class="view.isRestartComponentDisabled:hidden"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "restartComponent" view.content target="controller"}}> - {{t common.restart}} - </a> - </li> - {{/if}} - {{#unless view.isInstalling}} - {{#isAuthorized "SERVICE.START_STOP"}} - {{#if view.isStart}} - <li {{bindAttr class="view.isComponentDecommissioning:hidden view.noActionAvailable"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "stopComponent" view.content target="controller"}}> - {{t common.stop}} + {{#unless App.router.wizardWatcherController.isNonWizardUser}} + <ul class="dropdown-menu"> + {{#if view.isComponentDecommissionAvailable}} + {{view view.decommissionView}} + {{/if}} + {{#if view.isComponentRecommissionAvailable}} + {{view view.decommissionView}} + {{/if}} + {{#if view.isRestartableComponent}} + <li {{bindAttr class="view.isRestartComponentDisabled:hidden"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "restartComponent" view.content target="controller"}}> + {{t common.restart}} + </a> + </li> + {{/if}} + {{#unless view.isInstalling}} + {{#isAuthorized "SERVICE.START_STOP"}} + {{#if view.isStart}} + <li {{bindAttr class="view.isComponentDecommissioning:hidden view.noActionAvailable"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "stopComponent" view.content target="controller"}}> + {{t common.stop}} + </a> + </li> + {{/if}} + {{#unless view.isStart}} + {{#unless view.isInit}} + <li {{bindAttr class="view.isUpgradeFailed:hidden view.isInstallFailed:hidden view.isDecommissioning:hidden view.noActionAvailable"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "startComponent" view.content target="controller"}}> + {{t common.start}} + </a> + </li> + {{/unless}} + {{/unless}} + {{/isAuthorized}} + {{#if view.isUpgradeFailed}} + <li {{bindAttr class="view.noActionAvailable"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "upgradeComponent" view.content target="controller"}}> + {{t common.reUpgrade}} + </a> + </li> + {{/if}} + {{#if view.isInstallFailed}} + <li {{bindAttr class="view.noActionAvailable"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}> + {{t common.reinstall}} </a> </li> {{/if}} - {{#unless view.isStart}} - {{#unless view.isInit}} - <li {{bindAttr class="view.isUpgradeFailed:hidden view.isInstallFailed:hidden view.isDecommissioning:hidden view.noActionAvailable"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "startComponent" view.content target="controller"}}> - {{t common.start}} + {{#if view.isReassignable}} + {{#isAuthorized "SERVICE.MOVE"}} + <li {{bindAttr class="view.noActionAvailable view.isMoveComponentDisabled:disabled"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "moveComponent" view.content target="controller"}}> + {{t common.move}} </a> </li> - {{/unless}} - {{/unless}} - {{/isAuthorized}} - {{#if view.isUpgradeFailed}} - <li {{bindAttr class="view.noActionAvailable"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "upgradeComponent" view.content target="controller"}}> - {{t common.reUpgrade}} + {{/isAuthorized}} + {{/if}} + {{#isAuthorized "HOST.TOGGLE_MAINTENANCE"}} + <li {{bindAttr class="view.noActionAvailable view.content.isImpliedState:disabled :allow-tooltip"}} + {{bindAttr data-original-title="view.maintenanceTooltip"}} rel="passiveTooltip" > + <a href="javascript:void(null)" + data-toggle="modal" {{action "toggleMaintenanceMode" view.content target="controller"}}> + {{#if view.isActive}} + {{t passiveState.turnOn}} + {{else}} + {{t passiveState.turnOff}} + {{/if}} </a> </li> - {{/if}} - {{#if view.isInstallFailed}} - <li {{bindAttr class="view.noActionAvailable"}}> + {{/isAuthorized}} + {{/unless}} + {{#if view.isInit}} + <li> <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}> {{t common.reinstall}} </a> </li> {{/if}} - {{#if view.isReassignable}} - {{#isAuthorized "SERVICE.MOVE"}} - <li {{bindAttr class="view.noActionAvailable view.isMoveComponentDisabled:disabled"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "moveComponent" view.content target="controller"}}> - {{t common.move}} - </a> + {{#if view.isDeletableComponent}} + {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}} + <li {{bindAttr class="view.isDeleteComponentDisabled:disabled"}}> + <a href="javascript:void(null)" data-toggle="modal" {{action "deleteComponent" view.content target="controller"}}> + {{t common.delete}} + </a> </li> {{/isAuthorized}} {{/if}} - {{#isAuthorized "HOST.TOGGLE_MAINTENANCE"}} - <li {{bindAttr class="view.noActionAvailable view.content.isImpliedState:disabled :allow-tooltip"}} - {{bindAttr data-original-title="view.maintenanceTooltip"}} rel="passiveTooltip" > - <a href="javascript:void(null)" - data-toggle="modal" {{action "toggleMaintenanceMode" view.content target="controller"}}> - {{#if view.isActive}} - {{t passiveState.turnOn}} - {{else}} - {{t passiveState.turnOff}} - {{/if}} - </a> - </li> - {{/isAuthorized}} - {{/unless}} - {{#if view.isInit}} - <li> - <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}> - {{t common.reinstall}} - </a> - </li> - {{/if}} - {{#if view.isDeletableComponent}} - {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}} - <li {{bindAttr class="view.isDeleteComponentDisabled:disabled"}}> - <a href="javascript:void(null)" data-toggle="modal" {{action "deleteComponent" view.content target="controller"}}> - {{t common.delete}} - </a> - </li> - {{/isAuthorized}} - {{/if}} - {{#if view.isRefreshConfigsAllowed}} - <li> - <a href="javascript:void(null)" data-toggle="modal" {{action "refreshComponentConfigs" view.content target="controller"}}> - {{t hosts.host.details.refreshConfigs}} - </a> - </li> - {{/if}} + {{#if view.isRefreshConfigsAllowed}} + <li> + <a href="javascript:void(null)" data-toggle="modal" {{action "refreshComponentConfigs" view.content target="controller"}}> + {{t hosts.host.details.refreshConfigs}} + </a> + </li> + {{/if}} - {{#each command in view.customCommands}} - <li {{bindAttr class="command.disabled:disabled"}}> - <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>{{command.label}}</a> - </li> - {{/each}} - </ul> + {{#each command in view.customCommands}} + <li {{bindAttr class="command.disabled:disabled"}}> + <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>{{command.label}}</a> + </li> + {{/each}} + </ul> + {{/unless}} </div> - {{/isAuthorized}} + {{/havePermissions}} </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/stack_versions.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/stack_versions.hbs b/ambari-web/app/templates/main/host/stack_versions.hbs index 60e6571..cf167a4 100644 --- a/ambari-web/app/templates/main/host/stack_versions.hbs +++ b/ambari-web/app/templates/main/host/stack_versions.hbs @@ -54,9 +54,9 @@ {{/if}} </td> <td class="install-repo-version align-center"> - {{#isAuthorized "AMBARI.MANAGE_STACK_VERSIONS"}} + {{#havePermissions "AMBARI.MANAGE_STACK_VERSIONS"}} <button class="btn btn-default" {{action installVersionConfirmation version target="controller"}} {{bindAttr disabled="version.installDisabled"}}><i class="glyphicon glyphicon-off"></i> {{t common.install}}</button> - {{/isAuthorized}} + {{/havePermissions}} </td> </tr> {{/each}} http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/summary.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/summary.hbs b/ambari-web/app/templates/main/host/summary.hbs index 84a1c5e..3ceb92f 100644 --- a/ambari-web/app/templates/main/host/summary.hbs +++ b/ambari-web/app/templates/main/host/summary.hbs @@ -26,38 +26,40 @@ <h4 class="panel-title">{{t common.components}}</h4> </div> <div class="col-md-6"> - {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}} + {{#havePermissions "HOST.ADD_DELETE_COMPONENTS"}} <div class="dropdown pull-right"> - <button id="add_component" data-toggle="dropdown" {{bindAttr class="view.addComponentDisabled:disabled :btn :btn-default :dropdown-toggle"}}> + <button id="add_component" data-toggle="dropdown" {{bindAttr class="view.addComponentDisabled:disabled :btn :btn-default :dropdown-toggle" disabled="App.router.wizardWatcherController.isNonWizardUser"}}> <span class="glyphicon glyphicon-plus"></span> {{t add}} </button> - <ul class="dropdown-menu"> - {{#each component in view.addableComponents}} - <li> - <a href="javascript:void(null)" data-toggle="modal" {{action addComponentWithCheck component target="controller"}}> - {{component.displayName}} - </a> - </li> - {{/each}} - </ul> + {{#unless App.router.wizardWatcherController.isNonWizardUser}} + <ul class="dropdown-menu"> + {{#each component in view.addableComponents}} + <li> + <a href="javascript:void(null)" data-toggle="modal" {{action addComponentWithCheck component target="controller"}}> + {{component.displayName}} + </a> + </li> + {{/each}} + </ul> + {{/unless}} </div> - {{/isAuthorized}} + {{/havePermissions}} </div> </div> </div> <div class="host-components panel-body"> {{#if view.sortedComponents.length}} - {{#isAuthorized "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}} + {{#havePermissions "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}} {{#if view.content.componentsWithStaleConfigsCount}} <div class="alert alert-warning clearfix restart-required"> <i class="glyphicon glyphicon-refresh"></i> {{view.needToRestartMessage}} - <button {{bindAttr class=":btn :restart-components :pull-right :btn-warning"}} {{action restartAllStaleConfigComponents target="controller"}}> + <button {{bindAttr class=":btn :restart-components :pull-right :btn-warning" disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action restartAllStaleConfigComponents target="controller"}}> {{t hosts.host.details.needToRestart.button}} </button> </div> {{/if}} - {{/isAuthorized}} + {{/havePermissions}} {{#each component in view.sortedComponents}} {{view component.viewClass classNames="row row-no-pad" contentBinding="component"}} @@ -89,58 +91,60 @@ {{/if}} </div> <div class="col-md-5 col-lg-4 pull-right"> - {{#isAuthorized "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}} + {{#havePermissions "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}} {{#if view.clients.length}} <div class="dropdown"> <button id="add_component" - data-toggle="dropdown" {{bindAttr class=":btn :btn-default :btn-block :dropdown-toggle controller.content.isNotHeartBeating:disabled"}}> + data-toggle="dropdown" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser" class=":btn :btn-default :btn-block :dropdown-toggle controller.content.isNotHeartBeating:disabled"}}> {{t common.installed}} <span class="caret pull-right button-caret-margin"></span> </button> - <ul class="dropdown-menu"> - <li> - <a href="javascript:void(null)" - data-toggle="modal" {{action refreshConfigs view.clients target="controller"}}> - {{t hosts.host.details.refreshConfigs}} - </a> - </li> - <li> - <a href="javascript:void(null)" {{bindAttr class="view.areClientsNotInstalled::disabled" }} - data-toggle="modal" {{action installClients target="view"}}> - {{t host.host.details.installClients}} - </a> - </li> - {{#if view.anyClientFailedToInstall}} - <li> - <a href="javascript:void(null)" {{action reinstallClients target="view"}}> - {{t host.host.details.reinstallClients}} - </a> - </li> - {{/if}} - {{#each option in view.clientsWithCustomCommands}} - <li class="dropdown-submenu submenu-left"> - <a href="javascript:void(null)"> - <i class="glyphicon glyphicon-play-circle"></i> - {{option.label}} - </a> + {{#unless App.router.wizardWatcherController.isNonWizardUser}} + <ul class="dropdown-menu"> + <li> + <a href="javascript:void(null)" + data-toggle="modal" {{action refreshConfigs view.clients target="controller"}}> + {{t hosts.host.details.refreshConfigs}} + </a> + </li> + <li> + <a href="javascript:void(null)" {{bindAttr class="view.areClientsNotInstalled::disabled" }} + data-toggle="modal" {{action installClients target="view"}}> + {{t host.host.details.installClients}} + </a> + </li> + {{#if view.anyClientFailedToInstall}} + <li> + <a href="javascript:void(null)" {{action reinstallClients target="view"}}> + {{t host.host.details.reinstallClients}} + </a> + </li> + {{/if}} + {{#each option in view.clientsWithCustomCommands}} + <li class="dropdown-submenu submenu-left"> + <a href="javascript:void(null)"> + <i class="glyphicon glyphicon-play-circle"></i> + {{option.label}} + </a> - <div class="dropdown-menu-wrap"> - <ul class="dropdown-menu"> - {{#each command in option.commands}} - <li> - <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}> - {{command.label}} - </a> - </li> - {{/each}} - </ul> - </div> - </li> - {{/each}} - </ul> + <div class="dropdown-menu-wrap"> + <ul class="dropdown-menu"> + {{#each command in option.commands}} + <li> + <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}> + {{command.label}} + </a> + </li> + {{/each}} + </ul> + </div> + </li> + {{/each}} + </ul> + {{/unless}} </div> {{/if}} - {{/isAuthorized}} + {{/havePermissions}} </div> </div> </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/utils/helper.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js index 3bc247c..baacdf3 100644 --- a/ambari-web/app/utils/helper.js +++ b/ambari-web/app/utils/helper.js @@ -445,6 +445,29 @@ Em.Handlebars.registerHelper('isAuthorized', function (property, options) { }); /** + * Usage: + * + * <pre> + * {{#havePermissions "SERVICE.TOGGLE_ALERTS"}} + * {{! some truly code }} + * {{else}} + * {{! some falsy code }} + * {{/havePermissions}} + * </pre> + */ +Em.Handlebars.registerHelper('havePermissions', function (property, options) { + var permission = Ember.Object.create({ + havePermissions: function() { + return App.havePermissions(property); + }.property() + }); + + // wipe out contexts so boundIf uses `this` (the permission) as the context + options.contexts = null; + return Ember.Handlebars.helpers.boundIf.call(permission, "havePermissions", options); +}); + +/** * @namespace App */ App = require('app'); http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/views/main/service/item.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/service/item.js b/ambari-web/app/views/main/service/item.js index 45c783b..945dc8f 100644 --- a/ambari-web/app/views/main/service/item.js +++ b/ambari-web/app/views/main/service/item.js @@ -319,7 +319,7 @@ App.MainServiceItemView = Em.View.extend({ }.property('maintenance'), hasConfigTab: function() { - return App.isAuthorized('CLUSTER.VIEW_CONFIGS', {ignoreWizard: true}) && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName')); + return App.havePermissions('CLUSTER.VIEW_CONFIGS') && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName')); }.property('controller.content.serviceName','App.services.noConfigTypes'), hasHeatmapTab: function() { http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/test/views/main/service/item_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/service/item_test.js b/ambari-web/test/views/main/service/item_test.js index e4a1940..b86d021 100644 --- a/ambari-web/test/views/main/service/item_test.js +++ b/ambari-web/test/views/main/service/item_test.js @@ -614,7 +614,7 @@ describe('App.MainServiceItemView', function () { describe('#hasConfigTab', function() { beforeEach(function() { - this.mockAuthorized = sinon.stub(App, 'isAuthorized'); + this.mockAuthorized = sinon.stub(App, 'havePermissions'); this.mockGet = sinon.stub(App, 'get').returns(['S2']); }); afterEach(function() { @@ -622,7 +622,7 @@ describe('App.MainServiceItemView', function () { this.mockGet.restore(); }); - it('should return false when not authorized', function() { + it('should return false when have not permissions', function() { this.mockAuthorized.returns(false); view.set('controller.content.serviceName', 'S1'); expect(view.get('hasConfigTab')).to.be.false; @@ -634,7 +634,7 @@ describe('App.MainServiceItemView', function () { expect(view.get('hasConfigTab')).to.be.false; }); - it('should return true when authorized', function() { + it('should return true when have permissions', function() { this.mockAuthorized.returns(true); view.set('controller.content.serviceName', 'S1'); expect(view.get('hasConfigTab')).to.be.true;
