Add Angular keystone role edit action
To test set 'roles_panel' to True in settings.py and have v3 enabled Change-Id: Id02349a539f12dfe86924a075c62ba190999724d Co-Authored-By: Richard Jones <r1chardj0n3s@gmail.com> Partially-Implements: blueprint ng-roles
This commit is contained in:
parent
5b8bb1f135
commit
0e17dadfc4
@ -34,6 +34,7 @@
|
||||
'horizon.framework.conf.resource-type-registry.service',
|
||||
'horizon.dashboard.identity.roles.actions.create.service',
|
||||
'horizon.dashboard.identity.roles.actions.delete.service',
|
||||
'horizon.dashboard.identity.roles.actions.edit.service',
|
||||
'horizon.dashboard.identity.roles.resourceType'
|
||||
];
|
||||
|
||||
@ -41,11 +42,19 @@
|
||||
registry,
|
||||
createService,
|
||||
deleteService,
|
||||
editService,
|
||||
roleResourceTypeCode
|
||||
) {
|
||||
var roleResourceType = registry.getResourceType(roleResourceTypeCode);
|
||||
|
||||
roleResourceType.itemActions
|
||||
.append({
|
||||
id: 'editRoleAction',
|
||||
service: editService,
|
||||
template: {
|
||||
text: gettext('Edit Role')
|
||||
}
|
||||
})
|
||||
.append({
|
||||
id: 'deleteAction',
|
||||
service: deleteService,
|
||||
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright 2016 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('horizon.dashboard.identity.roles')
|
||||
.factory('horizon.dashboard.identity.roles.actions.edit.service', editService);
|
||||
|
||||
editService.$inject = [
|
||||
'horizon.dashboard.identity.roles.resourceType',
|
||||
'horizon.dashboard.identity.roles.role-schema',
|
||||
'horizon.app.core.openstack-service-api.keystone',
|
||||
'horizon.app.core.openstack-service-api.policy',
|
||||
'horizon.framework.widgets.form.ModalFormService',
|
||||
'horizon.framework.util.actions.action-result.service',
|
||||
'horizon.framework.widgets.toast.service'
|
||||
];
|
||||
|
||||
/**
|
||||
* @ngDoc factory
|
||||
* @name horizon.dashboard.identity.roles.actions.edit.service
|
||||
* @Description A service to handle the Edit Role modal.
|
||||
*/
|
||||
function editService(
|
||||
resourceType,
|
||||
schema,
|
||||
keystoneAPI,
|
||||
policy,
|
||||
modalFormService,
|
||||
actionResultService,
|
||||
toast
|
||||
) {
|
||||
var service = {
|
||||
allowed: allowed,
|
||||
perform: perform,
|
||||
onLoad: onLoad,
|
||||
submit: submit,
|
||||
onSuccess: onSuccess
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
//////////////
|
||||
|
||||
function allowed() {
|
||||
return policy.ifAllowed({ rules: [['identity', 'identity:update_role']] });
|
||||
}
|
||||
|
||||
function perform(role) {
|
||||
return keystoneAPI.getRole(role.id).then(service.onLoad);
|
||||
}
|
||||
|
||||
function onLoad(response) {
|
||||
var config = {
|
||||
title: gettext('Edit Role'),
|
||||
schema: schema,
|
||||
form: ['*'],
|
||||
model: response.data
|
||||
};
|
||||
return modalFormService.open(config).then(service.submit);
|
||||
}
|
||||
|
||||
function submit(context) {
|
||||
return keystoneAPI.editRole(context.model).then(service.onSuccess);
|
||||
}
|
||||
|
||||
function onSuccess(response) {
|
||||
toast.add('success', gettext('Role updated successfully.'));
|
||||
|
||||
return actionResultService.getActionResult()
|
||||
.updated(resourceType, response.config.data.id)
|
||||
.result;
|
||||
}
|
||||
}
|
||||
})();
|
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright 2016 Rackspace
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use self file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
describe('horizon.dashboard.identity.roles.actions.edit.service', function() {
|
||||
beforeEach(module('horizon.app.core'));
|
||||
beforeEach(module('horizon.dashboard.identity.roles'));
|
||||
beforeEach(module('horizon.framework'));
|
||||
|
||||
var modalService, service, keystoneAPI, policyAPI, toast, resourceType, $q, $scope;
|
||||
|
||||
beforeEach(inject(function($injector, _$q_, _$rootScope_) {
|
||||
service = $injector.get('horizon.dashboard.identity.roles.actions.edit.service');
|
||||
keystoneAPI = $injector.get('horizon.app.core.openstack-service-api.keystone');
|
||||
modalService = $injector.get('horizon.framework.widgets.form.ModalFormService');
|
||||
policyAPI = $injector.get('horizon.app.core.openstack-service-api.policy');
|
||||
toast = $injector.get('horizon.framework.widgets.toast.service');
|
||||
resourceType = $injector.get('horizon.dashboard.identity.roles.resourceType');
|
||||
$q = _$q_;
|
||||
$scope = _$rootScope_.$new();
|
||||
}));
|
||||
|
||||
describe('perform', function() {
|
||||
it('should fetch the correct role', function test() {
|
||||
var deferred = $q.defer();
|
||||
deferred.resolve({id: 1, name: 'spam roll'});
|
||||
spyOn(keystoneAPI, 'getRole').and.returnValue(deferred.promise);
|
||||
spyOn(service, 'onLoad');
|
||||
|
||||
service.perform({id: 2});
|
||||
$scope.$apply();
|
||||
|
||||
expect(keystoneAPI.getRole).toHaveBeenCalled();
|
||||
expect(service.onLoad).toHaveBeenCalledWith({id: 1, name: 'spam roll'});
|
||||
});
|
||||
|
||||
it('should open the edit modal', function test() {
|
||||
var role = {id: 1, name: 'spam roll'};
|
||||
var edited = {id: 1, name: 'egg roll'};
|
||||
var deferred = $q.defer();
|
||||
spyOn(modalService, 'open').and.returnValue(deferred.promise);
|
||||
spyOn(service, 'submit');
|
||||
|
||||
deferred.resolve(edited);
|
||||
service.onLoad({data: role});
|
||||
$scope.$apply();
|
||||
|
||||
expect(modalService.open).toHaveBeenCalled();
|
||||
var config = modalService.open.calls.argsFor(0)[0];
|
||||
expect(config.model).toEqual(role);
|
||||
expect(config.schema).toBeDefined();
|
||||
expect(service.submit).toHaveBeenCalledWith(edited);
|
||||
});
|
||||
|
||||
it('should handle edit modal submission', function test() {
|
||||
var deferred = $q.defer();
|
||||
spyOn(keystoneAPI, 'editRole').and.returnValue(deferred.promise);
|
||||
spyOn(service, 'onSuccess');
|
||||
|
||||
deferred.resolve('result');
|
||||
service.submit({model: 'model'});
|
||||
$scope.$apply();
|
||||
|
||||
expect(keystoneAPI.editRole).toHaveBeenCalledWith('model');
|
||||
expect(service.onSuccess).toHaveBeenCalledWith('result');
|
||||
});
|
||||
|
||||
it('should handle successful edit', function test() {
|
||||
spyOn(toast, 'add');
|
||||
var result = service.onSuccess({config: {data: {id: 2}}});
|
||||
|
||||
expect(result.updated).toEqual([{type: resourceType, id: 2}]);
|
||||
expect(toast.add).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('allow method', function() {
|
||||
it('should use default policy if batch action', function test() {
|
||||
spyOn(policyAPI, 'ifAllowed');
|
||||
service.allowed();
|
||||
expect(policyAPI.ifAllowed).toHaveBeenCalled();
|
||||
});
|
||||
}); // end of allowed
|
||||
|
||||
}); // end of edit
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user