mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-30 20:01:48 -05:00
adding model for admin of orgs and disabling credential's org field
when appropriate
This commit is contained in:
@@ -277,9 +277,35 @@ function has (method, keys) {
|
||||
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) {
|
||||
let version = '/api/v2/';
|
||||
|
||||
|
||||
return `${version}${resource}/`;
|
||||
}
|
||||
|
||||
@@ -383,6 +409,7 @@ function BaseModel (path, settings) {
|
||||
this.search = search;
|
||||
this.set = set;
|
||||
this.unset = unset;
|
||||
this.extend = extend;
|
||||
|
||||
this.http = {
|
||||
get: httpGet.bind(this),
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
let BaseModel;
|
||||
|
||||
function getSelf () {
|
||||
return this.get('results[0]');
|
||||
}
|
||||
|
||||
function MeModel (method, resource, graft) {
|
||||
BaseModel.call(this, 'me');
|
||||
|
||||
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_) {
|
||||
|
||||
@@ -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 Me from './Me';
|
||||
import Organization from './Organization';
|
||||
import OrgAdmin from './OrgAdmin';
|
||||
|
||||
angular
|
||||
.module('at.lib.models', [])
|
||||
@@ -13,5 +12,4 @@ angular
|
||||
.service('CredentialModel', Credential)
|
||||
.service('CredentialTypeModel', CredentialType)
|
||||
.service('MeModel', Me)
|
||||
.service('OrganizationModel', Organization)
|
||||
.service('OrgAdminModel', OrgAdmin);
|
||||
.service('OrganizationModel', Organization);
|
||||
|
||||
Reference in New Issue
Block a user