mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-02 11:49:23 +00:00
Merge pull request #1064 from theseyi/acl-refac
replaces page notifications for acl access requests with notification…
This commit is contained in:
commit
a249e9ec52
@ -1,9 +1,7 @@
|
||||
import Component from '@ember/component';
|
||||
import { get, set, getProperties, computed } from '@ember/object';
|
||||
import ComputedProperty from '@ember/object/computed';
|
||||
import { get, set } from '@ember/object';
|
||||
import { TaskInstance, TaskProperty } from 'ember-concurrency';
|
||||
import { action } from 'ember-decorators/object';
|
||||
import DatasetAclAccessContainer from 'wherehows-web/components/datasets/containers/dataset-acl-access';
|
||||
import { IAccessControlAccessTypeOption } from 'wherehows-web/typings/api/datasets/aclaccess';
|
||||
import { getDefaultRequestAccessControlEntry } from 'wherehows-web/utils/datasets/acl-access';
|
||||
|
||||
@ -54,30 +52,6 @@ export default class DatasetAclAccess extends Component {
|
||||
*/
|
||||
removeAccessTask: TaskProperty<Promise<void>> & { perform: (a?: {} | undefined) => TaskInstance<Promise<void>> };
|
||||
|
||||
/**
|
||||
* External task reference to the last request for acl entry aliases `requestAccessAndCheckAccessTask`, if exists
|
||||
* @type {ComputedProperty<TaskInstance<DatasetAclAccessContainer.requestAccessAndCheckAccessTask>>}
|
||||
* @memberof DatasetAclAccess
|
||||
*/
|
||||
lastAccessRequestTask: ComputedProperty<TaskInstance<DatasetAclAccessContainer['requestAccessAndCheckAccessTask']>>;
|
||||
|
||||
/**
|
||||
* Resolves to true if the last request for access results in an error and the logged in user,
|
||||
* does not have access. Used to indicate that the request may have been denied
|
||||
* @type {ComputedProperty<boolean>}
|
||||
* @memberof DatasetAclAccess
|
||||
*/
|
||||
lastAccessRequestFailedOrDenied = computed('lastAccessRequestTask.isError', 'userHasAclAccess', function(
|
||||
this: DatasetAclAccess
|
||||
): boolean {
|
||||
const { lastAccessRequestTask, userHasAclAccess } = getProperties(this, [
|
||||
'lastAccessRequestTask',
|
||||
'userHasAclAccess'
|
||||
]);
|
||||
const lastRequestErrored = lastAccessRequestTask && lastAccessRequestTask.isError;
|
||||
return !!lastRequestErrored && !userHasAclAccess;
|
||||
});
|
||||
|
||||
/**
|
||||
* Action to reset the request form
|
||||
* @memberof DatasetAclAccess
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import Component from '@ember/component';
|
||||
import ComputedProperty, { equal, alias } from '@ember/object/computed';
|
||||
import ComputedProperty, { equal } from '@ember/object/computed';
|
||||
import { inject } from '@ember/service';
|
||||
import { get, set, getProperties, computed } from '@ember/object';
|
||||
import { task, TaskInstance } from 'ember-concurrency';
|
||||
@ -19,6 +19,7 @@ import {
|
||||
getDefaultRequestAccessControlEntry
|
||||
} from 'wherehows-web/utils/datasets/acl-access';
|
||||
import { hasEnumerableKeys } from 'wherehows-web/utils/object';
|
||||
import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications';
|
||||
|
||||
export default class DatasetAclAccessContainer extends Component {
|
||||
/**
|
||||
@ -28,6 +29,13 @@ export default class DatasetAclAccessContainer extends Component {
|
||||
*/
|
||||
currentUser: ComputedProperty<CurrentUser> = inject();
|
||||
|
||||
/**
|
||||
* App notifications service
|
||||
* @type {ComputedProperty<Notifications>}
|
||||
* @memberof DatasetAclAccessContainer
|
||||
*/
|
||||
notifications: ComputedProperty<Notifications> = inject();
|
||||
|
||||
/**
|
||||
* The currently logged in user
|
||||
* @type {IUser}
|
||||
@ -79,15 +87,6 @@ export default class DatasetAclAccessContainer extends Component {
|
||||
*/
|
||||
urn: string;
|
||||
|
||||
/**
|
||||
* Reference to the last requestAccessAndCheckAccessTask task
|
||||
* @type {ComputedProperty<TaskInstance<DatasetAclAccessContainer.requestAccessAndCheckAccessTask>>}
|
||||
* @memberof DatasetAclAccessContainer
|
||||
*/
|
||||
lastAccessRequestTask: ComputedProperty<
|
||||
TaskInstance<DatasetAclAccessContainer['requestAccessAndCheckAccessTask']>
|
||||
> = alias('requestAccessAndCheckAccessTask.last');
|
||||
|
||||
didInsertElement() {
|
||||
get(this, 'getContainerDataTask').perform();
|
||||
}
|
||||
@ -108,6 +107,22 @@ export default class DatasetAclAccessContainer extends Component {
|
||||
return hasEnumerableKeys(userAclRequest) && !!userAclRequest.businessJustification;
|
||||
});
|
||||
|
||||
/**
|
||||
* Notifies user of changes to acl access
|
||||
* @param {(string | Error)} param notification message string or error object
|
||||
* @returns {void}
|
||||
* @memberof DatasetAclAccessContainer
|
||||
*/
|
||||
notifyStatus(this: DatasetAclAccessContainer, param: string | Error) {
|
||||
const { notify } = get(this, 'notifications');
|
||||
|
||||
if (typeof param === 'string') {
|
||||
return notify(NotificationEvent.success, { content: param });
|
||||
}
|
||||
|
||||
notify(NotificationEvent.error, { content: param.message });
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent container task to get all data for the container component
|
||||
* @memberof DatasetAclAccessContainer
|
||||
@ -173,9 +188,15 @@ export default class DatasetAclAccessContainer extends Component {
|
||||
* @memberof DatasetAclAccessContainer
|
||||
*/
|
||||
requestAccessAndCheckAccessTask = task(function*(this: DatasetAclAccessContainer): IterableIterator<any> {
|
||||
yield get(this, 'requestAccessTask').perform();
|
||||
yield get(this, 'getDatasetAclsTask').perform();
|
||||
yield get(this, 'checkUserAccessTask').perform();
|
||||
try {
|
||||
yield get(this, 'requestAccessTask').perform();
|
||||
yield get(this, 'getDatasetAclsTask').perform();
|
||||
yield get(this, 'checkUserAccessTask').perform();
|
||||
|
||||
get(this, 'userHasAclAccess') && this.notifyStatus('Congrats, your request has been approved!');
|
||||
} catch (e) {
|
||||
this.notifyStatus(e);
|
||||
}
|
||||
}).drop();
|
||||
|
||||
/**
|
||||
@ -187,9 +208,15 @@ export default class DatasetAclAccessContainer extends Component {
|
||||
): IterableIterator<
|
||||
Promise<void> | TaskInstance<Array<IAccessControlEntry>> | TaskInstance<Promise<IAccessControlEntry[]>>
|
||||
> {
|
||||
yield removeAclAccess(get(this, 'urn'));
|
||||
yield get(this, 'getDatasetAclsTask').perform();
|
||||
yield get(this, 'checkUserAccessTask').perform();
|
||||
try {
|
||||
yield removeAclAccess(get(this, 'urn'));
|
||||
yield get(this, 'getDatasetAclsTask').perform();
|
||||
yield get(this, 'checkUserAccessTask').perform();
|
||||
|
||||
!get(this, 'userHasAclAccess') && this.notifyStatus('Your access has been removed');
|
||||
} catch (e) {
|
||||
this.notifyStatus(e);
|
||||
}
|
||||
}).drop();
|
||||
|
||||
/**
|
||||
|
||||
@ -1,63 +1,20 @@
|
||||
<header class="acl-permission__header">
|
||||
{{#unless lastAccessRequestTask}}
|
||||
|
||||
{{#if userHasAclAccess}}
|
||||
<i class="fa fa-check-circle-o fa-lg acl-permission__success" title="You are in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__success acl-permission__meta__header">
|
||||
You have access to this dataset
|
||||
</strong>
|
||||
</div>
|
||||
{{else}}
|
||||
<i class="fa fa-ban fa-lg acl-permission__reject" title="You are not in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__reject acl-permission__meta__header">
|
||||
You currently do not have access to this dataset
|
||||
</strong>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{/unless}}
|
||||
|
||||
{{#if lastAccessRequestFailedOrDenied}}
|
||||
{{#if userHasAclAccess}}
|
||||
<i class="fa fa-check-circle-o fa-lg acl-permission__success" title="You are in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__success acl-permission__meta__header">
|
||||
You have access to this dataset
|
||||
</strong>
|
||||
</div>
|
||||
{{else}}
|
||||
<i class="fa fa-ban fa-lg acl-permission__reject" title="You are not in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__reject acl-permission__meta__header">
|
||||
Sorry, your request has been denied by the system or an error occured with your request.
|
||||
You currently do not have access to this dataset
|
||||
</strong>
|
||||
<p>If you feel this is in error, contact ask_acl@linkedin.</p>
|
||||
</div>
|
||||
|
||||
{{/if}}
|
||||
|
||||
{{#if lastAccessRequestTask}}
|
||||
{{#if userHasAclAccess}}
|
||||
|
||||
<i class="fa fa-check-circle-o fa-lg acl-permission__success" title="You are in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__success acl-permission__meta__header">
|
||||
Congrats, your request has been approved.
|
||||
</strong>
|
||||
<p>You now have access to this dataset</p>
|
||||
</div>
|
||||
|
||||
{{else}}
|
||||
|
||||
<i class="fa fa-ban fa-lg acl-permission__reject" title="You are not in this dataset's ACL"></i>
|
||||
|
||||
<div class="acl-permission__meta">
|
||||
<strong class="acl-permission__reject acl-permission__meta__header">
|
||||
Your access has been removed
|
||||
</strong>
|
||||
<p>You no longer have access to this dataset</p>
|
||||
</div>
|
||||
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{#if userHasAclAccess}}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
userAclRequest=userAclRequest
|
||||
userHasAclAccess=userHasAclAccess
|
||||
requestAccessAndCheckAccessTask=requestAccessAndCheckAccessTask
|
||||
lastAccessRequestTask=lastAccessRequestTask
|
||||
removeAccessTask=removeAccessTask
|
||||
accessTypeDropDownOptions=accessTypeDropDownOptions
|
||||
expiresAtDidChange=(action "expiresAtDidChange")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user