75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { inject as service } from '@ember/service';
|
|
import { action } from '@ember/object';
|
|
import { loading } from 'ember-loading';
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
|
|
|
export default class ScopesScopeStorageBucketsRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
@service session;
|
|
@service can;
|
|
@service router;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* If arriving here unauthenticated, redirect to index for further processing.
|
|
*/
|
|
beforeModel() {
|
|
if (!this.session.isAuthenticated) this.router.transitionTo('index');
|
|
}
|
|
|
|
/**
|
|
* Load all storage buckets under current scope.
|
|
* @return {Promise{[StorageBucketModel]}}
|
|
*/
|
|
async model() {
|
|
const scope = this.modelFor('scopes.scope');
|
|
const { id: scope_id } = scope;
|
|
if (
|
|
this.can.can('list storage-bucket', scope, {
|
|
collection: 'storage-buckets',
|
|
})
|
|
) {
|
|
return this.store.query('storage-bucket', { scope_id });
|
|
}
|
|
}
|
|
|
|
// =actions
|
|
|
|
/**
|
|
* Handle save
|
|
* @param {StorageBucketModel} storageBucket
|
|
*/
|
|
@action
|
|
@loading
|
|
@notifyError(({ message }) => message)
|
|
@notifySuccess('notifications.save-success')
|
|
async save(storageBucket) {
|
|
await storageBucket.save();
|
|
await this.router.transitionTo(
|
|
'scopes.scope.storage-buckets.storage-bucket',
|
|
storageBucket
|
|
);
|
|
this.refresh();
|
|
}
|
|
|
|
/**
|
|
* Rollback changes on storage buckets.
|
|
* @param {StorageBucketModel} storageBucket
|
|
*/
|
|
@action
|
|
cancel(storageBucket) {
|
|
const { isNew } = storageBucket;
|
|
storageBucket.rollbackAttributes();
|
|
if (isNew) this.router.transitionTo('scopes.scope.storage-buckets');
|
|
}
|
|
}
|