2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-01 17:31:22 -04:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
2022-07-19 12:11:16 -07:00
|
|
|
import { hash } from 'rsvp';
|
2022-01-03 09:28:24 -05:00
|
|
|
import { loading } from 'ember-loading';
|
2020-11-18 13:19:46 -05:00
|
|
|
import { confirm } from 'core/decorators/confirm';
|
2020-11-18 13:59:11 -05:00
|
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
2020-09-01 17:31:22 -04:00
|
|
|
|
|
|
|
|
export default class ScopesScopeGroupsGroupMembersRoute extends Route {
|
|
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service intl;
|
2022-08-31 10:24:25 -07:00
|
|
|
|
2022-07-19 12:11:16 -07:00
|
|
|
@service resourceFilterStore;
|
2020-09-01 17:31:22 -04:00
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns users associated with this group.
|
2020-09-02 16:20:12 -04:00
|
|
|
* @return {Promise{group: GroupModel, members: Promise{[UserModel]}}}
|
2020-09-01 17:31:22 -04:00
|
|
|
*/
|
2020-09-02 16:45:43 -04:00
|
|
|
model() {
|
2020-09-01 17:31:22 -04:00
|
|
|
const group = this.modelFor('scopes.scope.groups.group');
|
2020-09-02 16:20:12 -04:00
|
|
|
return hash({
|
|
|
|
|
group,
|
2022-07-19 12:11:16 -07:00
|
|
|
members: group.member_ids?.length
|
|
|
|
|
? this.resourceFilterStore.queryBy(
|
|
|
|
|
'user',
|
|
|
|
|
{ id: group.member_ids },
|
|
|
|
|
{ scope_id: 'global', recursive: true }
|
|
|
|
|
)
|
|
|
|
|
: [],
|
2020-09-02 16:20:12 -04:00
|
|
|
});
|
2020-09-01 17:31:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =actions
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a member from the current role and redirect to members index.
|
|
|
|
|
* @param {GroupModel} group
|
|
|
|
|
* @param {UserModel} member
|
|
|
|
|
*/
|
|
|
|
|
@action
|
2020-09-25 18:09:56 -04:00
|
|
|
@loading
|
2020-09-30 18:50:12 -04:00
|
|
|
@confirm('questions.remove-confirm')
|
2020-10-08 18:01:27 -04:00
|
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
|
|
|
@notifySuccess('notifications.remove-success')
|
2020-09-01 17:31:22 -04:00
|
|
|
async removeMember(group, member) {
|
2020-10-08 18:01:27 -04:00
|
|
|
await group.removeMember(member.id);
|
|
|
|
|
this.refresh();
|
2020-09-01 17:31:22 -04:00
|
|
|
}
|
|
|
|
|
}
|