60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { service } from '@ember/service';
|
|
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
|
|
|
|
export default class ScopesScopeAuthMethodsNewRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
@service abilities;
|
|
@service router;
|
|
|
|
// =attributes
|
|
|
|
queryParams = {
|
|
type: {
|
|
refreshModel: true,
|
|
},
|
|
};
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Redirect to parent route when scope does not have create authorized action.
|
|
*/
|
|
beforeModel() {
|
|
const scopeModel = this.modelFor('scopes.scope');
|
|
if (
|
|
this.abilities.cannot('create model', scopeModel, {
|
|
collection: 'auth-methods',
|
|
})
|
|
) {
|
|
this.router.replaceWith('scopes.scope.auth-methods');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a new unsaved auth-method.
|
|
* @return {AuthMethodModel}
|
|
*/
|
|
model(params) {
|
|
const scopeModel = this.modelFor('scopes.scope');
|
|
const record = this.store.createRecord('auth-method', {
|
|
type: params.type,
|
|
});
|
|
record.scopeModel = scopeModel;
|
|
|
|
// if the auth method type is OIDC, initialize account_claim_maps with an empty row
|
|
if (params.type === TYPE_AUTH_METHOD_OIDC) {
|
|
record.account_claim_maps = [{ key: '', value: '' }];
|
|
}
|
|
|
|
return record;
|
|
}
|
|
}
|