2018-02-07 12:32:03 -08:00
|
|
|
import Component from '@ember/component';
|
2018-03-28 10:58:30 -07:00
|
|
|
import { get, set } from '@ember/object';
|
2018-04-02 16:27:46 -07:00
|
|
|
import ComputedProperty, { gte } from '@ember/object/computed';
|
2018-03-20 11:32:51 -07:00
|
|
|
import { TaskInstance, TaskProperty } from 'ember-concurrency';
|
2018-09-13 16:43:29 -07:00
|
|
|
import { action, computed } from '@ember-decorators/object';
|
2018-08-12 13:02:01 -07:00
|
|
|
import {
|
|
|
|
|
IAccessControlAccessTypeOption,
|
2018-09-13 16:43:29 -07:00
|
|
|
IAccessControlEntry,
|
2018-08-12 13:02:01 -07:00
|
|
|
IRequestAccessControlEntry
|
|
|
|
|
} from 'wherehows-web/typings/api/datasets/aclaccess';
|
2018-03-20 11:32:51 -07:00
|
|
|
import { getDefaultRequestAccessControlEntry } from 'wherehows-web/utils/datasets/acl-access';
|
2018-09-13 16:43:29 -07:00
|
|
|
import { IAvatar } from 'wherehows-web/typings/app/avatars';
|
|
|
|
|
import { arrayMap } from 'wherehows-web/utils/array';
|
|
|
|
|
import { IAppConfig } from 'wherehows-web/typings/api/configurator/configurator';
|
|
|
|
|
import { getAvatarProps } from 'wherehows-web/constants/avatars/avatars';
|
2018-09-28 15:31:07 -07:00
|
|
|
import moment from 'moment';
|
2018-02-07 12:32:03 -08:00
|
|
|
|
2018-03-29 10:49:25 -07:00
|
|
|
/**
|
|
|
|
|
* Date object with the minimum selectable date for acl request expiration,
|
|
|
|
|
* at least 1 day from now
|
|
|
|
|
* @type {Date}
|
|
|
|
|
*/
|
2018-09-28 15:31:07 -07:00
|
|
|
const minSelectableExpirationDate = new Date(
|
|
|
|
|
moment()
|
|
|
|
|
.endOf('day')
|
|
|
|
|
.valueOf()
|
|
|
|
|
);
|
2018-05-10 17:08:50 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Date object with the maximum selectable date for acl request expiration,
|
|
|
|
|
* up to 7 days from now
|
|
|
|
|
* @type {Date}
|
|
|
|
|
*/
|
2018-09-28 15:39:08 -07:00
|
|
|
const maxSelectableExpirationDate = new Date(
|
|
|
|
|
moment()
|
|
|
|
|
.add(7, 'days')
|
|
|
|
|
.valueOf()
|
|
|
|
|
);
|
2018-03-29 10:49:25 -07:00
|
|
|
|
2018-02-07 12:32:03 -08:00
|
|
|
export default class DatasetAclAccess extends Component {
|
2018-09-13 16:43:29 -07:00
|
|
|
/**
|
|
|
|
|
* External component attribute with list of acls
|
|
|
|
|
* @type {Array<IAccessControlEntry>}
|
|
|
|
|
*/
|
|
|
|
|
acls: Array<IAccessControlEntry>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* External component attribute with properties to construct an acl's avatar image
|
|
|
|
|
* @type {(IAppConfig['userEntityProps'] | undefined)}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
avatarProperties: IAppConfig['userEntityProps'] | undefined;
|
|
|
|
|
|
2018-08-26 23:25:51 -07:00
|
|
|
/**
|
|
|
|
|
* Named component argument with a string link reference to more information on acls
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
aclMoreInfoLink: string;
|
|
|
|
|
|
2018-02-07 12:32:03 -08:00
|
|
|
/**
|
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-23 17:55:33 -04:00
|
|
|
/**
|
|
|
|
|
* Currently selected date
|
|
|
|
|
* @type {Date}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
selectedDate: Date = new Date();
|
|
|
|
|
|
2018-08-12 13:02:01 -07:00
|
|
|
/**
|
|
|
|
|
* @type {IRequestAccessControlEntry | void}
|
|
|
|
|
*/
|
|
|
|
|
userAclRequest: IRequestAccessControlEntry | void;
|
|
|
|
|
|
2018-03-23 17:55:33 -04:00
|
|
|
/**
|
|
|
|
|
* Date around which the calendar is centered
|
|
|
|
|
* @type {Date}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
centeredDate: Date = this.selectedDate;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The earliest date a user can select as an expiration date
|
|
|
|
|
* @type {Date}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
2018-03-29 10:49:25 -07:00
|
|
|
minSelectableExpirationDate: Date = minSelectableExpirationDate;
|
2018-03-23 17:55:33 -04:00
|
|
|
|
2018-05-10 17:08:50 -07:00
|
|
|
/**
|
|
|
|
|
* The furthest date a user can select as an expiration date
|
|
|
|
|
* @type {Date}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
maxSelectableExpirationDate: Date = maxSelectableExpirationDate;
|
|
|
|
|
|
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}
|
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-23 17:55:33 -04:00
|
|
|
/**
|
|
|
|
|
* External action invoked on change to expiration date
|
|
|
|
|
* @type {(date: Date) => void}
|
|
|
|
|
*/
|
|
|
|
|
expiresAtDidChange: (date: Date) => void;
|
|
|
|
|
|
2018-03-29 10:49:25 -07:00
|
|
|
/**
|
|
|
|
|
* Checks if the expiration date is greater than the min allowed
|
|
|
|
|
* @type {ComputedProperty<boolean>}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
2018-04-02 16:27:46 -07:00
|
|
|
hasValidExpiration: ComputedProperty<boolean> = gte('selectedDate', minSelectableExpirationDate.getTime());
|
2018-03-29 10:49:25 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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() {
|
|
|
|
|
set(this, 'userAclRequest', getDefaultRequestAccessControlEntry());
|
2018-02-07 12:32:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:43:29 -07:00
|
|
|
/**
|
|
|
|
|
* Augments each acl in the list with properties for the user avatar
|
|
|
|
|
* @readonly
|
|
|
|
|
* @type {(Array<IAccessControlEntry & Record<'avatar', IAvatar>>)}
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
@computed('acls')
|
|
|
|
|
get aclsWithAvatarProps(): Array<IAccessControlEntry & Record<'avatar', IAvatar>> {
|
|
|
|
|
const { acls, avatarProperties } = this;
|
2018-09-13 17:59:39 -07:00
|
|
|
const aclWithAvatar = (acl: IAccessControlEntry): IAccessControlEntry & Record<'avatar', IAvatar> => ({
|
2018-09-13 16:43:29 -07:00
|
|
|
...acl,
|
|
|
|
|
avatar: getAvatarProps(avatarProperties!)({ userName: acl.principal })
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-13 17:59:39 -07:00
|
|
|
return avatarProperties ? arrayMap(aclWithAvatar)(acls) : [];
|
2018-09-13 16:43:29 -07:00
|
|
|
}
|
|
|
|
|
|
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-03-23 17:55:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the selectedDate property on this and invokes the external action to set the expiration date
|
|
|
|
|
* @param {Date} date
|
|
|
|
|
* @memberof DatasetAclAccess
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
onExpirationDateChange(date: Date) {
|
|
|
|
|
set(this, 'selectedDate', date);
|
|
|
|
|
get(this, 'expiresAtDidChange')(date);
|
|
|
|
|
}
|
2018-02-07 12:32:03 -08:00
|
|
|
}
|