2018-02-07 12:32:03 -08:00
|
|
|
import Component from '@ember/component';
|
2018-03-20 11:32:51 -07:00
|
|
|
import { get, set, getProperties, computed } from '@ember/object';
|
2018-02-07 12:32:03 -08:00
|
|
|
import ComputedProperty from '@ember/object/computed';
|
2018-03-20 11:32:51 -07:00
|
|
|
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';
|
2018-02-07 12:32:03 -08:00
|
|
|
|
|
|
|
export default class DatasetAclAccess extends Component {
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* The currently logged in user is listed on the related datasets acl
|
|
|
|
* @type {boolean}
|
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
readonly userHasAclAccess: boolean;
|
2018-02-07 12:32:03 -08:00
|
|
|
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* External action invoked on change to access request access type
|
|
|
|
* @type {(option: IAccessControlAccessTypeOption) => void}
|
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
accessTypeDidChange: (option: IAccessControlAccessTypeOption) => void;
|
2018-02-07 12:32:03 -08:00
|
|
|
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* External task to remove the logged in user from the related dataset's acl
|
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
removeAccessTask: TaskProperty<Promise<void>> & { perform: (a?: {} | undefined) => TaskInstance<Promise<void>> };
|
2018-02-07 12:32:03 -08:00
|
|
|
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* External task reference to the last request for acl entry aliases `requestAccessAndCheckAccessTask`, if exists
|
|
|
|
* @type {ComputedProperty<TaskInstance<DatasetAclAccessContainer.requestAccessAndCheckAccessTask>>}
|
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
lastAccessRequestTask: ComputedProperty<TaskInstance<DatasetAclAccessContainer['requestAccessAndCheckAccessTask']>>;
|
2018-02-07 12:32:03 -08:00
|
|
|
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* 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
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
lastAccessRequestFailedOrDenied = computed('lastAccessRequestTask.isError', 'userHasAclAccess', function(
|
2018-02-07 12:32:03 -08:00
|
|
|
this: DatasetAclAccess
|
2018-03-20 11:32:51 -07:00
|
|
|
): boolean {
|
|
|
|
const { lastAccessRequestTask, userHasAclAccess } = getProperties(this, [
|
|
|
|
'lastAccessRequestTask',
|
|
|
|
'userHasAclAccess'
|
|
|
|
]);
|
|
|
|
const lastRequestErrored = lastAccessRequestTask && lastAccessRequestTask.isError;
|
|
|
|
return !!lastRequestErrored && !userHasAclAccess;
|
2018-02-07 12:32:03 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to reset the request form
|
2018-03-20 11:32:51 -07:00
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
resetForm() {
|
|
|
|
//@ts-ignore dot notation property access
|
|
|
|
set(this, 'userAclRequest', getDefaultRequestAccessControlEntry());
|
2018-02-07 12:32:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-20 11:32:51 -07:00
|
|
|
* Invokes external action when the accessType to be requested is modified
|
|
|
|
* @param {IAccessControlAccessTypeOption} arg
|
|
|
|
* @memberof DatasetAclAccess
|
2018-02-07 12:32:03 -08:00
|
|
|
*/
|
2018-03-20 11:32:51 -07:00
|
|
|
@action
|
|
|
|
onAccessTypeChange(arg: IAccessControlAccessTypeOption): void {
|
|
|
|
get(this, 'accessTypeDidChange')(arg);
|
|
|
|
}
|
2018-02-07 12:32:03 -08:00
|
|
|
}
|