| 
									
										
										
										
											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-05-14 14:54:03 -07:00
										 |  |  | import { action } from '@ember-decorators/object'; | 
					
						
							| 
									
										
										
										
											2018-08-12 13:02:01 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   IAccessControlAccessTypeOption, | 
					
						
							|  |  |  |   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-02-07 12:32:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 17:08:50 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Returns the number of days in milliseconds, default is 1 day | 
					
						
							|  |  |  |  * @param {number} [day=1] the number of days to scale | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const millisecondDays = (day = 1) => day * 24 * 60 * 60 * 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-05-10 17:08:50 -07:00
										 |  |  | const minSelectableExpirationDate = new Date(Date.now() + millisecondDays()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Date object with the maximum selectable date for acl request expiration, | 
					
						
							|  |  |  |  * up to 7 days from now | 
					
						
							|  |  |  |  * @type {Date} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const maxSelectableExpirationDate = new Date(Date.now() + millisecondDays(7)); | 
					
						
							| 
									
										
										
										
											2018-03-29 10:49:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 12:32:03 -08:00
										 |  |  | export default class DatasetAclAccess extends Component { | 
					
						
							| 
									
										
										
										
											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-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
										 |  |  | } |