mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-16 05:34:54 +00:00

* finish the alc access page layout, logics and sass files * Fix css issue and request permission response error message * finish the testing part * simplify code finished * finish spinner * Finished ACL access page, testing cases, clean code format * Clean format, address comments, refactor JS code of ACL page to TS * address comments, replace type any and fix merge issue
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { ApiStatus } from 'wherehows-web/utils/api/shared';
|
|
import { Response, faker } from 'ember-cli-mirage';
|
|
import ApprovedAclUser from 'wherehows-web/mirage/fixtures/dataset-acl-users';
|
|
|
|
const textContentHeader = { 'Content-Type': 'text/plain; charset=utf-8' };
|
|
//TODO: Build a dummy server to simulate ACL authentication process
|
|
/**
|
|
* Build response body property
|
|
* @param {sting} ldap
|
|
*/
|
|
const approvedUserInfo = (ldap: string | undefined) => {
|
|
return {
|
|
tableItem: {
|
|
userName: ldap,
|
|
name: faker.name.findName(),
|
|
idType: 'USER',
|
|
source: `${faker.random.alphaNumeric()}${faker.random.alphaNumeric()}`.toUpperCase(),
|
|
modifiedTime: faker.date.past(),
|
|
ownerShip: 'DataOwner'
|
|
}
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Build ACL authentication server POST logic
|
|
* @param {any}_schema
|
|
* @param {string} requestBody
|
|
*/
|
|
const aclAuth = (_schema: any, { requestBody }: { requestBody: string }) => {
|
|
const { principal, businessJustification } = <{
|
|
principal: string;
|
|
businessJustification: string;
|
|
}>JSON.parse(requestBody);
|
|
|
|
const isApproved = businessJustification.toLowerCase().includes('read');
|
|
|
|
if (businessJustification && isApproved) {
|
|
let LADA: string | undefined = principal.split(':').get('lastObject');
|
|
const responseBody = {
|
|
principal,
|
|
businessJustification,
|
|
accessTypes: 'READ',
|
|
...approvedUserInfo(LADA)
|
|
};
|
|
_schema.db.datasetAclUsers.insert(responseBody);
|
|
return {
|
|
status: ApiStatus.OK,
|
|
...responseBody
|
|
};
|
|
}
|
|
return new Response(401, textContentHeader, { status: ApiStatus.FAILED, isApproved: false });
|
|
};
|
|
|
|
/**
|
|
* For testing purpose, defined a mocked response when user is granted ACL permission
|
|
*/
|
|
const approvedResponseTesting = ApprovedAclUser[0];
|
|
|
|
/**
|
|
* For testing purpose, defined a method to mock ACL server response
|
|
*/
|
|
const accessInfoTesting = (permmision: boolean) => {
|
|
return {
|
|
isAccess: permmision,
|
|
body: [approvedResponseTesting]
|
|
};
|
|
};
|
|
|
|
export { aclAuth, accessInfoTesting, approvedResponseTesting };
|