vault/ui/app/components/control-group.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00

97 lines
2.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { inject as service } from '@ember/service';
import { alias, or } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { task } from 'ember-concurrency';
export default Component.extend({
tagName: '',
auth: service(),
controlGroup: service(),
// public API
model: null,
didReceiveAttrs() {
this._super(...arguments);
const accessor = this.model.id;
const data = this.controlGroup.wrapInfoForAccessor(accessor);
this.set('controlGroupResponse', data);
},
currentUserEntityId: alias('auth.authData.entity_id'),
currentUserIsRequesting: computed('currentUserEntityId', 'model.requestEntity.id', function () {
if (!this.model.requestEntity) return false;
return this.currentUserEntityId === this.model.requestEntity.id;
}),
currentUserHasAuthorized: computed('currentUserEntityId', 'model.authorizations.@each.id', function () {
const authorizations = this.model.authorizations || [];
return Boolean(authorizations.findBy('id', this.currentUserEntityId));
}),
isSuccess: or('currentUserHasAuthorized', 'model.approved'),
requestorName: computed('currentUserIsRequesting', 'model.requestEntity', function () {
const entity = this.model.requestEntity;
if (this.currentUserIsRequesting) {
return 'You';
}
if (entity && entity.name) {
return entity.name;
}
return 'Someone';
}),
bannerPrefix: computed('model.approved', 'currentUserHasAuthorized', function () {
if (this.currentUserHasAuthorized) {
return 'Thanks!';
}
if (this.model.approved) {
return 'Success!';
}
return 'Locked';
}),
bannerText: computed('model.approved', 'currentUserIsRequesting', 'currentUserHasAuthorized', function () {
const isApproved = this.model.approved;
const { currentUserHasAuthorized, currentUserIsRequesting } = this;
if (currentUserHasAuthorized) {
return 'You have given authorization';
}
if (currentUserIsRequesting && isApproved) {
return 'You have been given authorization';
}
if (isApproved) {
return 'This Control Group has been authorized';
}
if (currentUserIsRequesting) {
return 'The path you requested is locked by a Control Group';
}
return 'Someone is requesting access to a path locked by a Control Group';
}),
refresh: task(function* () {
try {
yield this.model.reload();
} catch (e) {
this.set('errors', e);
}
}).drop(),
authorize: task(function* () {
try {
yield this.model.save();
yield this.refresh.perform();
} catch (e) {
this.set('errors', e);
}
}).drop(),
});