2018-01-20 00:46:47 -08:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
import { set, get, setProperties } from '@ember/object';
|
|
|
|
import { inject } from '@ember/service';
|
2017-04-28 13:44:31 -07:00
|
|
|
import { makeUrnBreadcrumbs } from 'wherehows-web/utils/entities';
|
2018-01-23 13:32:47 -08:00
|
|
|
import { isRequiredMinOwnersNotConfirmed } from 'wherehows-web/constants/datasets/owner';
|
2018-02-28 16:31:37 -08:00
|
|
|
import { datasetIdToUrn, readDatasetByUrn } from 'wherehows-web/utils/api/datasets/dataset';
|
2018-02-21 09:46:04 -08:00
|
|
|
import isUrn, { isWhUrn, isLiUrn, convertWhUrnToLiUrn, encodeUrn, decodeUrn } from 'wherehows-web/utils/validators/urn';
|
2017-03-24 22:15:48 -07:00
|
|
|
|
2018-02-07 12:32:03 -08:00
|
|
|
import { checkAclAccess } from 'wherehows-web/utils/api/datasets/acl-access';
|
|
|
|
import { currentUser } from 'wherehows-web/utils/api/authentication';
|
2018-02-21 09:46:04 -08:00
|
|
|
import { refreshModelQueryParams } from 'wherehows-web/utils/helpers/routes';
|
2017-03-24 22:15:48 -07:00
|
|
|
|
|
|
|
export default Route.extend({
|
2017-06-19 17:11:53 -07:00
|
|
|
/**
|
|
|
|
* Runtime application configuration options
|
|
|
|
* @type {Ember.Service}
|
|
|
|
*/
|
2018-01-20 00:46:47 -08:00
|
|
|
configurator: inject(),
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* Reference to the application notifications Service
|
|
|
|
* @type {ComputedProperty<Notifications>}
|
|
|
|
*/
|
|
|
|
notifications: inject(),
|
2017-06-19 17:11:53 -07:00
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
queryParams: refreshModelQueryParams(['urn']),
|
2017-09-20 16:10:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the dataset given a identifier from the dataset endpoint
|
2018-01-20 00:46:47 -08:00
|
|
|
* @param {string} dataset_id a identifier / id for the dataset to be fetched
|
2017-09-20 16:10:52 -07:00
|
|
|
* @param {string} [urn] optional urn identifier for dataset
|
2018-02-21 09:46:04 -08:00
|
|
|
* @return {Promise<IDataset|IDatasetView>}
|
2017-09-20 16:10:52 -07:00
|
|
|
*/
|
2018-02-21 09:46:04 -08:00
|
|
|
async model({ dataset_id: identifier, urn }) {
|
|
|
|
const isIdentifierUrn = isUrn(decodeUrn(String(identifier)));
|
|
|
|
|
|
|
|
if (identifier === 'urn' || isIdentifierUrn) {
|
|
|
|
isIdentifierUrn && (urn = identifier);
|
|
|
|
const decodedUrn = decodeUrn(urn);
|
|
|
|
|
|
|
|
isWhUrn(decodedUrn) && (urn = convertWhUrnToLiUrn(decodedUrn));
|
2017-09-20 16:10:52 -07:00
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
if (isLiUrn(decodeUrn(urn))) {
|
2018-02-25 20:34:38 -08:00
|
|
|
return await readDatasetByUrn(urn);
|
2018-02-14 20:47:26 -08:00
|
|
|
}
|
2018-02-21 09:46:04 -08:00
|
|
|
|
|
|
|
get(this, 'notifications.notify')('error', {
|
|
|
|
content: 'Could not adequately determine the URN for the requested dataset.'
|
|
|
|
});
|
2017-09-20 16:10:52 -07:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:18:50 -08:00
|
|
|
identifier = await datasetIdToUrn(identifier);
|
|
|
|
|
2018-02-28 16:31:37 -08:00
|
|
|
// recurse with dataset urn from id
|
2018-03-01 08:18:50 -08:00
|
|
|
if (identifier) {
|
|
|
|
return this.model({ dataset_id: identifier });
|
|
|
|
}
|
2018-03-01 08:37:01 -08:00
|
|
|
|
|
|
|
throw new TypeError(`Could not parse identifier ${identifier}. Please ensure format is valid.`);
|
2017-09-20 16:10:52 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* resetting the urn query param when the hook is invoked
|
|
|
|
* @param {Controller} controller
|
|
|
|
*/
|
|
|
|
resetController(controller) {
|
|
|
|
set(controller, 'urn', void 0);
|
|
|
|
},
|
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
async setupController(controller, model) {
|
|
|
|
set(controller, 'model', model);
|
|
|
|
setProperties(controller, {
|
|
|
|
isInternal: await get(this, 'configurator').getConfig('isInternal')
|
|
|
|
});
|
2017-02-13 11:26:50 -08:00
|
|
|
|
2018-02-07 12:32:03 -08:00
|
|
|
// TODO: Get current user ACL permission info for ACL access tab
|
|
|
|
Promise.resolve(currentUser())
|
|
|
|
.then(userInfo => {
|
|
|
|
setProperties(controller, {
|
|
|
|
userInfo
|
|
|
|
});
|
|
|
|
return checkAclAccess(userInfo.userName).then(value => {
|
|
|
|
setProperties(controller, {
|
|
|
|
aclAccessResponse: value,
|
|
|
|
currentUserInfo: userInfo.userName,
|
|
|
|
aclUsers: value.body
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
setProperties(controller, {
|
|
|
|
aclAccessResponse: null,
|
|
|
|
currentUserInfo: ''
|
|
|
|
});
|
|
|
|
});
|
2017-02-13 11:26:50 -08:00
|
|
|
}
|
|
|
|
});
|