mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 07:26:03 -03:30
adding model for admin of orgs and disabling credential's org field
when appropriate
This commit is contained in:
@@ -43,8 +43,8 @@ function AddCredentialsController (models, $state, strings) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vm.form.save = data => {
|
vm.form.save = data => {
|
||||||
data.user = me.getSelf().id;
|
data.user = me.get('id');
|
||||||
|
|
||||||
return credential.request('post', data);
|
return credential.request('post', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ function EditCredentialsController (models, $state, $scope, strings) {
|
|||||||
vm.form.disabled = !isEditable;
|
vm.form.disabled = !isEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isOrgAdmin = _.some(me.get('related.admin_of_organizations.results'), (org) => {return org.id === organization.get('id');});
|
||||||
|
let isSuperuser = me.get('is_superuser');
|
||||||
|
let isCurrentAuthor = Boolean(credential.get('summary_fields.created_by.id') === me.get('id'));
|
||||||
|
vm.form.organization._disabled = true;
|
||||||
|
if(isSuperuser || isOrgAdmin || (credential.get('organization') === null && isCurrentAuthor)){
|
||||||
|
vm.form.organization._disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
vm.form.organization._resource = 'organization';
|
vm.form.organization._resource = 'organization';
|
||||||
vm.form.organization._model = organization;
|
vm.form.organization._model = organization;
|
||||||
vm.form.organization._route = 'credentials.edit.organization';
|
vm.form.organization._route = 'credentials.edit.organization';
|
||||||
@@ -75,12 +83,12 @@ function EditCredentialsController (models, $state, $scope, strings) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a credential's `credential_type` is changed while editing, the inputs associated with
|
* If a credential's `credential_type` is changed while editing, the inputs associated with
|
||||||
* the old type need to be cleared before saving the inputs associated with the new type.
|
* the old type need to be cleared before saving the inputs associated with the new type.
|
||||||
* Otherwise inputs are merged together making the request invalid.
|
* Otherwise inputs are merged together making the request invalid.
|
||||||
*/
|
*/
|
||||||
vm.form.save = data => {
|
vm.form.save = data => {
|
||||||
data.user = me.getSelf().id;
|
data.user = me.get('id');
|
||||||
credential.unset('inputs');
|
credential.unset('inputs');
|
||||||
|
|
||||||
return credential.request('put', data);
|
return credential.request('put', data);
|
||||||
|
|||||||
@@ -3,18 +3,19 @@ import AddController from './add-credentials.controller';
|
|||||||
import EditController from './edit-credentials.controller';
|
import EditController from './edit-credentials.controller';
|
||||||
import CredentialsStrings from './credentials.strings'
|
import CredentialsStrings from './credentials.strings'
|
||||||
|
|
||||||
function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType, Organization, OrgAdmin) {
|
function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType, Organization) {
|
||||||
let id = $stateParams.credential_id;
|
let id = $stateParams.credential_id;
|
||||||
|
|
||||||
let promises = {
|
let promises = {
|
||||||
me: new Me('get')
|
me: new Me('get').then((me) => {
|
||||||
|
return me.extend('get', 'admin_of_organizations');
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
promises.credential = new Credential('options');
|
promises.credential = new Credential('options');
|
||||||
promises.credentialType = new CredentialType();
|
promises.credentialType = new CredentialType();
|
||||||
promises.organization = new Organization();
|
promises.organization = new Organization();
|
||||||
promises.orgAdmin = new OrgAdmin();
|
|
||||||
|
|
||||||
return $q.all(promises)
|
return $q.all(promises)
|
||||||
}
|
}
|
||||||
@@ -25,19 +26,16 @@ function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType, O
|
|||||||
.then(models => {
|
.then(models => {
|
||||||
let typeId = models.credential.get('credential_type');
|
let typeId = models.credential.get('credential_type');
|
||||||
let orgId = models.credential.get('organization');
|
let orgId = models.credential.get('organization');
|
||||||
let userId = models.me.get('results')[0].id;
|
|
||||||
|
|
||||||
let dependents = {
|
let dependents = {
|
||||||
credentialType: new CredentialType('get', typeId),
|
credentialType: new CredentialType('get', typeId),
|
||||||
organization: new Organization('get', orgId),
|
organization: new Organization('get', orgId)
|
||||||
orgAdmin: new OrgAdmin('get', userId)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q.all(dependents)
|
return $q.all(dependents)
|
||||||
.then(related => {
|
.then(related => {
|
||||||
models.credentialType = related.credentialType;
|
models.credentialType = related.credentialType;
|
||||||
models.organization = related.organization;
|
models.organization = related.organization;
|
||||||
models.is_org_admin = related.orgAdmin;
|
|
||||||
|
|
||||||
return models;
|
return models;
|
||||||
});
|
});
|
||||||
@@ -50,8 +48,7 @@ CredentialsResolve.$inject = [
|
|||||||
'MeModel',
|
'MeModel',
|
||||||
'CredentialModel',
|
'CredentialModel',
|
||||||
'CredentialTypeModel',
|
'CredentialTypeModel',
|
||||||
'OrganizationModel',
|
'OrganizationModel'
|
||||||
'OrgAdminModel'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider, stringProvider) {
|
function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider, stringProvider) {
|
||||||
|
|||||||
@@ -277,9 +277,35 @@ function has (method, keys) {
|
|||||||
return value !== undefined && value !== null;
|
return value !== undefined && value !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extend (method, related) {
|
||||||
|
if (!related) {
|
||||||
|
related = method
|
||||||
|
method = 'GET'
|
||||||
|
} else {
|
||||||
|
method = method.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.has(method, `related.${related}`)) {
|
||||||
|
let id = this.get('id')
|
||||||
|
|
||||||
|
let req = {
|
||||||
|
method,
|
||||||
|
url: this.get(`related.${related}`)
|
||||||
|
};
|
||||||
|
|
||||||
|
return $http(req)
|
||||||
|
.then(({data}) => {
|
||||||
|
this.set(method, `related.${related}`, data);
|
||||||
|
return this;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(new Error(`No related property, ${related}, exists`));
|
||||||
|
}
|
||||||
|
|
||||||
function normalizePath (resource) {
|
function normalizePath (resource) {
|
||||||
let version = '/api/v2/';
|
let version = '/api/v2/';
|
||||||
|
|
||||||
return `${version}${resource}/`;
|
return `${version}${resource}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,6 +409,7 @@ function BaseModel (path, settings) {
|
|||||||
this.search = search;
|
this.search = search;
|
||||||
this.set = set;
|
this.set = set;
|
||||||
this.unset = unset;
|
this.unset = unset;
|
||||||
|
this.extend = extend;
|
||||||
|
|
||||||
this.http = {
|
this.http = {
|
||||||
get: httpGet.bind(this),
|
get: httpGet.bind(this),
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
let BaseModel;
|
let BaseModel;
|
||||||
|
|
||||||
function getSelf () {
|
|
||||||
return this.get('results[0]');
|
|
||||||
}
|
|
||||||
|
|
||||||
function MeModel (method, resource, graft) {
|
function MeModel (method, resource, graft) {
|
||||||
BaseModel.call(this, 'me');
|
BaseModel.call(this, 'me');
|
||||||
|
|
||||||
this.Constructor = MeModel;
|
this.Constructor = MeModel;
|
||||||
this.getSelf = getSelf.bind(this);
|
|
||||||
|
|
||||||
return this.create(method, resource, graft);
|
return this.create(method, resource, graft)
|
||||||
|
.then(() => {
|
||||||
|
if (this.has('results')) {
|
||||||
|
_.merge(this.model.GET, this.get('results[0]'));
|
||||||
|
this.unset('results');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function MeModelLoader (_BaseModel_) {
|
function MeModelLoader (_BaseModel_) {
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
let BaseModel;
|
|
||||||
|
|
||||||
function OrgAdminModel (method, resource, graft) {
|
|
||||||
BaseModel.call(this, {path: 'users', subPath: 'admin_of_organizations'});
|
|
||||||
|
|
||||||
this.Constructor = OrgAdminModel;
|
|
||||||
|
|
||||||
return this.create(method, resource, graft);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OrgAdminModelLoader (_BaseModel_) {
|
|
||||||
BaseModel = _BaseModel_;
|
|
||||||
|
|
||||||
return OrgAdminModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
OrgAdminModelLoader.$inject = ['BaseModel'];
|
|
||||||
|
|
||||||
export default OrgAdminModelLoader;
|
|
||||||
@@ -4,7 +4,6 @@ import Credential from './Credential';
|
|||||||
import CredentialType from './CredentialType';
|
import CredentialType from './CredentialType';
|
||||||
import Me from './Me';
|
import Me from './Me';
|
||||||
import Organization from './Organization';
|
import Organization from './Organization';
|
||||||
import OrgAdmin from './OrgAdmin';
|
|
||||||
|
|
||||||
angular
|
angular
|
||||||
.module('at.lib.models', [])
|
.module('at.lib.models', [])
|
||||||
@@ -13,5 +12,4 @@ angular
|
|||||||
.service('CredentialModel', Credential)
|
.service('CredentialModel', Credential)
|
||||||
.service('CredentialTypeModel', CredentialType)
|
.service('CredentialTypeModel', CredentialType)
|
||||||
.service('MeModel', Me)
|
.service('MeModel', Me)
|
||||||
.service('OrganizationModel', Organization)
|
.service('OrganizationModel', Organization);
|
||||||
.service('OrgAdminModel', OrgAdmin);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user