Commit f3773fa7 authored by Sacha Brants's avatar Sacha Brants
Browse files

Merge branch 'slb/dm3/fix-user-info' into 'master'

fix: added user info translation option to dataset list endpoint

See merge request !277
parents cfdda3df 32bc43ce
Pipeline #79647 failed with stages
in 17 minutes and 21 seconds
......@@ -179,8 +179,8 @@ paths:
name: seismicmeta
required: false
type: boolean
- description: 'If the dataset creator value is a subid, then enable conversion of it to email'
name: subid-to-email
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
in: query
type: boolean
default: true
......@@ -678,6 +678,14 @@ paths:
in: query
name: cursor
type: string
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
in: query
type: boolean
default: true
enum:
- true
- false
responses:
200:
description: "The list of all datasets in the subproject if no gtags are in the request parameters. If gtags exist in the request parameters, then list all datasets that have the same list of gtags."
......@@ -1158,8 +1166,8 @@ paths:
name: tenantid
required: true
type: string
- description: 'Convert subid value of subproject admin to email'
name: subid-to-email
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
in: query
type: boolean
default: true
......@@ -2252,4 +2260,4 @@ securityDefinitions:
bearer:
type: apiKey
name: Authorization
in: header
\ No newline at end of file
in: header
......@@ -189,8 +189,8 @@ paths:
name: seismicmeta
required: false
type: boolean
- description: 'If the dataset creator value is a subid, then enable conversion of it to email'
name: subid-to-email
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
default: true
in: query
type: boolean
......@@ -688,7 +688,14 @@ paths:
in: query
name: cursor
type: string
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
in: query
type: boolean
default: true
enum:
- true
- false
responses:
200:
description: "The list of all datasets in the subproject if no gtags are in the request parameters. If gtags exist in the request parameters, then datasets that have the same list of gtags."
......@@ -1162,8 +1169,8 @@ paths:
required: true
type: string
default: common
- description: 'Convert subid value of subproject admin to email'
name: subid-to-email
- description: 'translate the user-id to a more human readable user info'
name: translate-user-info
default: true
in: query
type: boolean
......
......@@ -10,7 +10,7 @@ export class DESUserAssociation extends AbstractUserAssociationSvcProvider {
private static _cache: Cache<string>;
public async convertPrincipalIdentifierToEmail(principalIdentifier: string,
public async convertPrincipalIdentifierToUserInfo(principalIdentifier: string,
dataPartitionID: string): Promise<string> {
if (!DESUserAssociation._cache) {
......
......@@ -17,11 +17,11 @@
import { Error } from '../shared';
export interface IUserAssociationSvcProvider {
convertPrincipalIdentifierToEmail(principalIdentifier: string, dataPartitionID: string): Promise<string>;
convertPrincipalIdentifierToUserInfo(principalIdentifier: string, dataPartitionID: string): Promise<string>;
}
export abstract class AbstractUserAssociationSvcProvider implements IUserAssociationSvcProvider {
public abstract convertPrincipalIdentifierToEmail(principalIdentifier: string,
public abstract convertPrincipalIdentifierToUserInfo(principalIdentifier: string,
dataPartitionID: string): Promise<string>;
}
......
......@@ -285,7 +285,7 @@ export class DatasetHandler {
// parse user request
const userInput = DatasetParser.get(req);
const datasetIN = userInput[0];
const convertSubIdToEmail = (userInput[2] !== undefined) ? userInput[2] : true;
const convertUserInfo = userInput[2];
// retrieve journalClient client
const journalClient = JournalFactoryTenantClient.get(tenant);
......@@ -321,11 +321,11 @@ export class DatasetHandler {
}
// Convert subid to email if user input query param subid_to_email is true
if (FeatureFlags.isEnabled(Feature.CCM_INTERACTION) && convertSubIdToEmail) {
if (FeatureFlags.isEnabled(Feature.CCM_INTERACTION) && convertUserInfo) {
if (!Utils.isEmail(datasetOUT.created_by)) {
const dataPartition = DESUtils.getDataPartitionID(tenant.esd);
const userEmail = await UserAssociationServiceFactory.build(Config.USER_ASSOCIATION_SVC_PROVIDER).
convertPrincipalIdentifierToEmail(datasetOUT.created_by, dataPartition);
convertPrincipalIdentifierToUserInfo(datasetOUT.created_by, dataPartition);
datasetOUT.created_by = userEmail;
}
......@@ -356,6 +356,7 @@ export class DatasetHandler {
const dataset = userInput.dataset;
const pagination = userInput.pagination;
const userInfo = userInput.userInfo;
// init journalClient client
const journalClient = JournalFactoryTenantClient.get(tenant);
......@@ -372,8 +373,14 @@ export class DatasetHandler {
const output = await DatasetDAO.list(journalClient, dataset, pagination) as any;
// attach the gcpid for fast check
const dataPartition = DESUtils.getDataPartitionID(tenant.esd);
const userAssociationService = UserAssociationServiceFactory.build(Config.USER_ASSOCIATION_SVC_PROVIDER);
for (const item of output.datasets) {
item.ctag = item.ctag + tenant.gcpid + ';' + DESUtils.getDataPartitionID(tenant.esd);
item.ctag = item.ctag + tenant.gcpid + ';' + dataPartition;
if (userInfo && !Utils.isEmail(item.created_by)) {
item.created_by = await userAssociationService.convertPrincipalIdentifierToUserInfo(
item.created_by, dataPartition);
}
}
// Retrieve the list of datasets metadata
......
......@@ -106,11 +106,11 @@ export class DatasetParser {
}
}
// [TODO-V4] dismiss subid-to-email in favor of translate-user-info
public static get(req: expRequest): [DatasetModel, boolean, boolean] {
return [this.createDatasetModelFromRequest(req),
req.query.seismicmeta === 'true', (req.query['subid-to-email'] !== undefined) ?
req.query['subid-to-email'] === 'true' : true];
const userInfo = req.query['translate-user-info'] ? !(req.query['translate-user-info'] === 'false') :
req.query['translate-user-info'] ? !(req.query['subid-to-email'] === 'false') : true;
return [ this.createDatasetModelFromRequest(req), req.query.seismicmeta === 'true', userInfo ]
}
public static list(req: expRequest): any {
......@@ -132,8 +132,11 @@ export class DatasetParser {
pagination = { limit, cursor };
}
const userInfo = req.query['translate-user-info'] ? !(req.query['translate-user-info'] === 'false') :
req.query['translate-user-info'] ? !(req.query['subid-to-email'] === 'false') : true;;
// Retrieve the list of datasets metadata
return { dataset, pagination };
return { dataset, pagination, userInfo };
}
......
......@@ -213,7 +213,7 @@ export class SubProjectHandler {
if (!Utils.isEmail(subproject.admin)) {
const dataPartition = DESUtils.getDataPartitionID(tenant.esd);
subproject.admin = await UserAssociationServiceFactory.build(Config.USER_ASSOCIATION_SVC_PROVIDER)
.convertPrincipalIdentifierToEmail(subproject.admin, dataPartition);
.convertPrincipalIdentifierToUserInfo(subproject.admin, dataPartition);
}
}
......
......@@ -14,12 +14,13 @@
// limitations under the License.
// ============================================================================
import sinon from 'sinon';
import { Datastore } from '@google-cloud/datastore';
import { Request as expRequest, Response as expResponse } from 'express';
import sinon from 'sinon';
import { Auth } from '../../../src/auth';
import { Config, google, JournalFactoryTenantClient } from '../../../src/cloud';
import { DESStorage, DESUtils } from '../../../src/dataecosystem';
import { DESStorage, DESUtils, DESUserAssociation } from '../../../src/dataecosystem';
import { DatasetDAO, DatasetModel } from '../../../src/services/dataset';
import { DatasetHandler } from '../../../src/services/dataset/handler';
import { Locker } from '../../../src/services/dataset/locker';
......@@ -442,12 +443,14 @@ export class TestDatasetSVC {
Tx.sectionInit('list');
Tx.testExp(async (done: any, expReq: expRequest, expRes: expResponse) => {
Config.USER_ASSOCIATION_SVC_PROVIDER = 'ccm-internal';
this.sandbox.stub(TenantDAO, 'get').resolves({} as any);
this.sandbox.stub(Auth, 'isReadAuthorized').resolves(undefined);
this.sandbox.stub(DatasetDAO, 'list').resolves({ datasets: [{} as DatasetModel], nextPageCursor: null });
this.sandbox.stub(Auth, 'isLegalTagValid').resolves(true);
this.sandbox.stub(SubProjectDAO, 'get').resolves(this.testSubProject);
this.sandbox.stub(DESUtils, 'getDataPartitionID').returns('datapartition');
this.sandbox.stub(DESUserAssociation.prototype, 'convertPrincipalIdentifierToUserInfo').resolves();
await DatasetHandler.handler(expReq, expRes, DatasetOP.List);
Tx.check200(expRes.statusCode, done);
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment