Only Foundation admins can update the 'name' fields of official vendors

Once a vendor is registered and approved by the Foundation to become an
official vendor, only Foundation admins can make change to its vendor
name field.  This is to ensure that the Foundation will be aware of any
vendor identity (name) change.

Change-Id: Ia761707457091ce39fd1281ab5010e0456f779cc
This commit is contained in:
Catherine Diep 2016-11-30 15:42:16 -08:00
parent 0e8721e4ad
commit 098fb16b7f
5 changed files with 31 additions and 13 deletions

View File

@ -7,7 +7,8 @@
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label for="name">Name</label> <label for="name">Name</label>
<input type="text" <input ng-disabled="modal.vendor.type==3 && !modal.isAdmin"
type="text"
class="form-control" class="form-control"
id="name" id="name"
ng-model="modal.vendor.name"> ng-model="modal.vendor.name">

View File

@ -249,6 +249,7 @@
.controller('VendorEditModalController', VendorEditModalController); .controller('VendorEditModalController', VendorEditModalController);
VendorEditModalController.$inject = [ VendorEditModalController.$inject = [
'$rootScope',
'$uibModalInstance', '$http', '$state', 'vendor', 'refstackApiUrl' '$uibModalInstance', '$http', '$state', 'vendor', 'refstackApiUrl'
]; ];
@ -256,8 +257,8 @@
* Vendor Edit Modal Controller * Vendor Edit Modal Controller
* This controls the modal that allows editing a vendor. * This controls the modal that allows editing a vendor.
*/ */
function VendorEditModalController($uibModalInstance, $http, $state, function VendorEditModalController($rootScope, $uibModalInstance, $http,
vendor, refstackApiUrl) { $state, vendor, refstackApiUrl) {
var ctrl = this; var ctrl = this;
@ -267,7 +268,9 @@
ctrl.removeProperty = removeProperty; ctrl.removeProperty = removeProperty;
ctrl.vendor = vendor; ctrl.vendor = vendor;
ctrl.vendorName = vendor.name;
ctrl.vendorProperties = []; ctrl.vendorProperties = [];
ctrl.isAdmin = $rootScope.auth.currentUser.is_admin;
parseVendorProperties(); parseVendorProperties();
@ -294,9 +297,11 @@
ctrl.showSuccess = false; ctrl.showSuccess = false;
var url = [refstackApiUrl, '/vendors/', ctrl.vendor.id].join(''); var url = [refstackApiUrl, '/vendors/', ctrl.vendor.id].join('');
var properties = propertiesToJson(); var properties = propertiesToJson();
var content = {'name': ctrl.vendor.name, var content = {'description': ctrl.vendor.description,
'description': ctrl.vendor.description,
'properties': properties}; 'properties': properties};
if (ctrl.vendorName != ctrl.vendor.name) {
content.name = ctrl.vendor.name;
}
$http.put(url, content).success(function() { $http.put(url, content).success(function() {
ctrl.showSuccess = true; ctrl.showSuccess = true;
$state.reload(); $state.reload();

View File

@ -961,21 +961,27 @@ describe('Refstack controllers', function () {
}); });
describe('VendorEditModalController', function() { describe('VendorEditModalController', function() {
var ctrl, modalInstance, state; var rootScope, ctrl, modalInstance, state;
var fakeVendor = {'name': 'Foo', 'description': 'Bar', 'id': '1234', var fakeVendor = {'name': 'Foo', 'description': 'Bar', 'id': '1234',
'properties': {'key1': 'value1', 'key2': 'value2'}}; 'properties': {'key1': 'value1', 'key2': 'value2'}};
beforeEach(inject(function ($controller) { beforeEach(inject(function ($controller, $rootScope) {
modalInstance = { modalInstance = {
dismiss: jasmine.createSpy('modalInstance.dismiss') dismiss: jasmine.createSpy('modalInstance.dismiss')
}; };
state = { state = {
reload: jasmine.createSpy('state.reload') reload: jasmine.createSpy('state.reload')
}; };
rootScope = $rootScope.$new();
rootScope.auth = {'currentUser' : {'is_admin': true,
'openid': 'foo'}
};
ctrl = $controller('VendorEditModalController', ctrl = $controller('VendorEditModalController',
{$uibModalInstance: modalInstance, $state: state, {$rootScope: rootScope,
$uibModalInstance: modalInstance, $state: state,
vendor: fakeVendor} vendor: fakeVendor}
); );
})); }));
it('should be able to add/remove properties', it('should be able to add/remove properties',
@ -995,12 +1001,13 @@ describe('Refstack controllers', function () {
it('should have a function to save changes', it('should have a function to save changes',
function () { function () {
var expectedContent = { var expectedContent = {
'name': 'Foo', 'description': 'Bar', 'name': 'Foo1', 'description': 'Bar',
'properties': {'key1': 'value1', 'key2': 'value2'} 'properties': {'key1': 'value1', 'key2': 'value2'}
}; };
$httpBackend.expectPUT( $httpBackend.expectPUT(
fakeApiUrl + '/vendors/1234', expectedContent) fakeApiUrl + '/vendors/1234', expectedContent)
.respond(200, ''); .respond(200, '');
ctrl.vendor.name = 'Foo1';
ctrl.saveChanges(); ctrl.saveChanges();
$httpBackend.flush(); $httpBackend.flush();
}); });

View File

@ -115,22 +115,26 @@ class VendorsController(validation.BaseRestControllerWithValidation):
@pecan.expose('json', method='PUT') @pecan.expose('json', method='PUT')
def put(self, vendor_id, **kw): def put(self, vendor_id, **kw):
"""Handler for update item. Should return full info with updates.""" """Handler for update item. Should return full info with updates."""
is_admin = (api_utils.check_user_is_foundation_admin() is_foundation_admin = api_utils.check_user_is_foundation_admin()
is_admin = (is_foundation_admin
or api_utils.check_user_is_vendor_admin(vendor_id)) or api_utils.check_user_is_vendor_admin(vendor_id))
if not is_admin: if not is_admin:
pecan.abort(403, 'Forbidden.') pecan.abort(403, 'Forbidden.')
vendor_info = {'id': vendor_id} vendor_info = {'id': vendor_id}
vendor = db.get_organization(vendor_id)
if 'name' in kw: if 'name' in kw:
if (vendor['type'] == const.OFFICIAL_VENDOR and
not is_foundation_admin):
pecan.abort(
403, 'Name change for an official vendor is not allowed.')
vendor_info['name'] = kw['name'] vendor_info['name'] = kw['name']
if 'description' in kw: if 'description' in kw:
vendor_info['description'] = kw['description'] vendor_info['description'] = kw['description']
if 'properties' in kw: if 'properties' in kw:
vendor_info['properties'] = json.dumps(kw['properties']) vendor_info['properties'] = json.dumps(kw['properties'])
db.update_organization(vendor_info) vendor = db.update_organization(vendor_info)
pecan.response.status = 200 pecan.response.status = 200
vendor = db.get_organization(vendor_id)
vendor['can_manage'] = True vendor['can_manage'] = True
return vendor return vendor

View File

@ -441,6 +441,7 @@ def update_organization(organization_info):
organization.properties = organization_info.get( organization.properties = organization_info.get(
'properties', organization.properties) 'properties', organization.properties)
organization.save(session=session) organization.save(session=session)
return _to_dict(organization)
def get_organization(organization_id, allowed_keys=None): def get_organization(organization_id, allowed_keys=None):