2023-03-01 09:39:41 -06:00
|
|
|
/**
|
2026-01-28 17:09:06 -08:00
|
|
|
* Copyright IBM Corp. 2021, 2026
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-07-14 18:47:35 -04:00
|
|
|
import GeneratedScopeModel from '../generated/models/scope';
|
2020-07-15 09:43:30 -04:00
|
|
|
|
2024-04-05 10:59:35 -07:00
|
|
|
export const TYPE_SCOPE_GLOBAL = 'global';
|
|
|
|
|
export const TYPE_SCOPE_ORG = 'org';
|
|
|
|
|
export const TYPE_SCOPE_PROJECT = 'project';
|
|
|
|
|
export const TYPES_SCOPE = Object.freeze([
|
|
|
|
|
TYPE_SCOPE_GLOBAL,
|
|
|
|
|
TYPE_SCOPE_ORG,
|
|
|
|
|
TYPE_SCOPE_PROJECT,
|
|
|
|
|
]);
|
2020-07-14 18:47:35 -04:00
|
|
|
|
|
|
|
|
export default class ScopeModel extends GeneratedScopeModel {
|
2020-07-15 12:41:58 -04:00
|
|
|
// =attributes
|
2020-07-15 09:43:30 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isGlobal() {
|
2024-04-05 10:59:35 -07:00
|
|
|
return this.type === TYPE_SCOPE_GLOBAL;
|
2020-07-15 09:43:30 -04:00
|
|
|
}
|
|
|
|
|
// There is only one global scope and it cannot be created by clients,
|
|
|
|
|
// thus no set.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isOrg() {
|
2024-04-05 10:59:35 -07:00
|
|
|
return this.type === TYPE_SCOPE_ORG;
|
2020-07-15 09:43:30 -04:00
|
|
|
}
|
|
|
|
|
set isOrg(value) {
|
2024-04-05 10:59:35 -07:00
|
|
|
if (value) this.type = TYPE_SCOPE_ORG;
|
2020-07-15 09:43:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isProject() {
|
2024-04-05 10:59:35 -07:00
|
|
|
return this.type === TYPE_SCOPE_PROJECT;
|
2020-07-15 09:43:30 -04:00
|
|
|
}
|
|
|
|
|
set isProject(value) {
|
2024-04-05 10:59:35 -07:00
|
|
|
if (value) this.type = TYPE_SCOPE_PROJECT;
|
2020-07-15 09:43:30 -04:00
|
|
|
}
|
2024-01-12 11:29:19 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attach policy via the `attach-staorage-policy` method.
|
|
|
|
|
* @param {[string]} policyId
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
attachStoragePolicy(policyId, options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'attach-storage-policy',
|
|
|
|
|
policyId,
|
|
|
|
|
};
|
|
|
|
|
// There is no "deep merge" in ES.
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detaches policy via the `detach-storage-policy` method.
|
|
|
|
|
* @param {[string]} policyId
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
detachStoragePolicy(policyId, options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'detach-storage-policy',
|
|
|
|
|
policyId,
|
|
|
|
|
};
|
|
|
|
|
// There is no "deep merge" in ES.
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-14 18:47:35 -04:00
|
|
|
}
|