Skip to content

Commit

Permalink
Merge pull request #884 from US-Trustee-Program/CAMS-282-restrict-dat…
Browse files Browse the repository at this point in the history
…a-verification

CAMS-282 restrict data verification
  • Loading branch information
btposey authored Sep 11, 2024
2 parents ed0637a + af686ed commit 927208e
Show file tree
Hide file tree
Showing 42 changed files with 667 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};
const testCaseAttorneyAssignment2: CaseAssignment = {
documentType: 'ASSIGNMENT',
Expand All @@ -41,7 +42,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: perryMason,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

const assignmentId1 = await repository.createAssignment(testCaseAttorneyAssignment1);
Expand Down Expand Up @@ -75,7 +77,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

const actualIdResponse = await repository.createAssignment(testCaseAttorneyAssignment);
Expand All @@ -98,7 +101,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await repository.createAssignment(existingCaseAttorneyAssignment);
Expand All @@ -110,7 +114,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: benMatlock,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await expect(repository.updateAssignment(testCaseAttorneyAssignment)).rejects.toThrow(
Expand All @@ -128,7 +133,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};
const testCaseAttorneyAssignment2: CaseAssignment = {
documentType: 'ASSIGNMENT',
Expand All @@ -137,7 +143,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: perryMason,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

const assignmentId1 = await repository.createAssignment(testCaseAttorneyAssignment1);
Expand Down Expand Up @@ -176,7 +183,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: benMatlock,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await expect(repository.createAssignment(testCaseAttorneyAssignment)).rejects.toThrow(
Expand Down Expand Up @@ -222,7 +230,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: perryMason,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};
const testCaseAttorneyAssignment2: CaseAssignment = {
documentType: 'ASSIGNMENT',
Expand All @@ -231,7 +240,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: benMatlock,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

const caseIdTwo = randomUUID();
Expand All @@ -242,7 +252,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};
const testCaseAttorneyAssignment4: CaseAssignment = {
documentType: 'ASSIGNMENT',
Expand All @@ -251,7 +262,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: perryMason,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

const caseIdThree = randomUUID();
Expand All @@ -262,7 +274,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};
const testCaseAttorneyAssignment6: CaseAssignment = {
documentType: 'ASSIGNMENT',
Expand All @@ -271,7 +284,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: benMatlock,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await repository.createAssignment(testCaseAttorneyAssignment1);
Expand Down Expand Up @@ -362,7 +376,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: clairHuxtable,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await expect(repository.createAssignment(existingCaseAttorneyAssignment)).rejects.toThrow(
Expand All @@ -379,7 +394,8 @@ describe('Test case assignment cosmosdb repository tests', () => {
name: benMatlock,
role: CamsRole.TrialAttorney,
assignedOn: currentDate,
changedBy: MockData.getCamsUserReference(),
updatedOn: currentDate,
updatedBy: MockData.getCamsUserReference(),
};

await expect(repository.updateAssignment(testCaseAttorneyAssignment)).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { AggregateAuthenticationError } from '@azure/identity';
import { CaseAssignmentHistory } from '../../../../../common/src/cams/history';
import { MockData } from '../../../../../common/src/cams/test-utilities/mock-data';
import { SYSTEM_USER_REFERENCE } from '../../../../../common/src/cams/auditable';

describe('Runtime State Repo', () => {
const caseId1 = '111-11-11111';
Expand Down Expand Up @@ -122,7 +123,8 @@ describe('Test case history cosmosdb repository tests', () => {
const testCaseAssignmentHistory: CaseAssignmentHistory = {
caseId,
documentType: 'AUDIT_ASSIGNMENT',
occurredAtTimestamp: new Date().toISOString(),
updatedOn: new Date().toISOString(),
updatedBy: SYSTEM_USER_REFERENCE,
before: [],
after: [],
};
Expand All @@ -137,7 +139,8 @@ describe('Test case history cosmosdb repository tests', () => {
const testCaseAssignmentHistory: CaseAssignmentHistory = {
caseId,
documentType: 'AUDIT_ASSIGNMENT',
occurredAtTimestamp: new Date().toISOString(),
updatedBy: SYSTEM_USER_REFERENCE,
updatedOn: new Date().toISOString(),
before: [],
after: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export class CasesCosmosDbRepository implements CasesRepository {

async createCaseHistory(context: ApplicationContext, history: CaseHistory): Promise<string> {
try {
if (!history.occurredAtTimestamp) {
history.occurredAtTimestamp = new Date().toISOString();
}
const { resource } = await this.cosmosDbClient
.database(this.cosmosConfig.databaseName)
.container(this.containerName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OrdersSearchPredicate } from '../../../../../common/src/api/search';
import { ConsolidationOrder } from '../../../../../common/src/cams/orders';
import { ConsolidationOrdersRepository } from '../../use-cases/gateways.types';
import { ApplicationContext } from '../types/basic';
Expand All @@ -13,11 +14,30 @@ export default class ConsolidationOrdersCosmosDbRepository
constructor(context: ApplicationContext) {
super(context, CONTAINER_NAME, MODULE_NAME);
}
public async getAll(context: ApplicationContext): Promise<Array<ConsolidationOrder>> {
const querySpec = {
query: 'SELECT * FROM c ORDER BY c.orderDate ASC',
parameters: [],
};
public async search(
context: ApplicationContext,
predicate?: OrdersSearchPredicate,
): Promise<Array<ConsolidationOrder>> {
let querySpec;
if (!predicate) {
querySpec = {
query: 'SELECT * FROM c ORDER BY c.orderDate ASC',
parameters: [],
};
} else {
// TODO: Sanitize the inputs
// Group designator comes from local-storage-gateway and is store in the user session cache.
// We get associated division codes from DXTR and also store that in the session cache.
// We are not ever trusting the client with this information as of 9 Sept 2024.
const whereClause =
'WHERE ' +
predicate.divisionCodes.map((dCode) => `c.courtDivisionCode='${dCode}'`).join(' OR ') +
' ORDER BY c.orderDate ASC';
querySpec = {
query: 'SELECT * FROM c ' + whereClause,
parameters: [],
};
}
return await this.query(context, querySpec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export class DxtrOrdersGateway implements OrdersGateway {
CS.CS_SHORT_TITLE AS caseTitle,
CS.CS_CHAPTER AS chapter,
C.COURT_NAME AS courtName,
CS.CS_DIV as courtDivisionCode,
O.OFFICE_NAME_DISPLAY AS courtDivisionName,
G.REGION_ID AS regionId,
R.REGION_NAME AS regionName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Test case assignment cosmosdb repository tests', () => {
resources: mockOrders,
});

const testResult = await repository.getOrders(applicationContext);
const testResult = await repository.search(applicationContext);

expect(testResult).toEqual(mockOrders);
expect(mockFetchAll).toHaveBeenCalled();
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('Test case assignment cosmosdb repository tests', () => {
jest.spyOn(MockHumbleItems.prototype, 'create').mockRejectedValue(aggregateError);
jest.spyOn(MockHumbleItem.prototype, 'read').mockRejectedValue(aggregateError);

await expect(repository.getOrders(applicationContext)).rejects.toThrow(serverConfigError);
await expect(repository.search(applicationContext)).rejects.toThrow(serverConfigError);
await expect(
repository.getOrder(applicationContext, testNewOrderData.id, testNewOrderData.caseId),
).rejects.toThrow(serverConfigError);
Expand All @@ -245,7 +245,7 @@ describe('Test case assignment cosmosdb repository tests', () => {
jest.spyOn(MockHumbleItem.prototype, 'read').mockRejectedValue(error);
jest.spyOn(MockHumbleItems.prototype, 'create').mockRejectedValue(error);

await expect(repository.getOrders(applicationContext)).rejects.toThrow(error);
await expect(repository.search(applicationContext)).rejects.toThrow(error);
await expect(
repository.getOrder(applicationContext, testNewOrderData.id, testNewOrderData.caseId),
).rejects.toThrow(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Order, TransferOrder, TransferOrderAction } from '../../../../../common
import CosmosClientHumble from '../../cosmos-humble-objects/cosmos-client-humble';
import { MockHumbleClient } from '../../testing/mock.cosmos-client-humble';
import { QueryOptions } from '../../cosmos-humble-objects/cosmos-items-humble';
import { OrdersSearchPredicate } from '../../../../../common/src/api/search';

const MODULE_NAME: string = 'COSMOS_DB_REPOSITORY_ORDERS';
const CONTAINER_NAME: string = 'orders';
Expand All @@ -32,12 +33,27 @@ export class OrdersCosmosDbRepository implements OrdersRepository {
this.moduleName = moduleName;
}

async getOrders(context: ApplicationContext): Promise<Order[]> {
const query = 'SELECT * FROM c ORDER BY c.orderDate ASC';
const querySpec = {
query,
parameters: [],
};
async search(context: ApplicationContext, predicate?: OrdersSearchPredicate): Promise<Order[]> {
let querySpec;
if (!predicate) {
querySpec = {
query: 'SELECT * FROM c ORDER BY c.orderDate ASC',
parameters: [],
};
} else {
// TODO: Sanitize the inputs
// Group designator comes from local-storage-gateway and is store in the user session cache.
// We get associated division codes from DXTR and also store that in the session cache.
// We are not ever trusting the client with this information as of 9 Sept 2024.
const whereClause =
'WHERE ' +
predicate.divisionCodes.map((dCode) => `c.courtDivisionCode='${dCode}'`).join(' OR ') +
' ORDER BY c.orderDate ASC';
querySpec = {
query: 'SELECT * FROM c ' + whereClause,
parameters: [],
};
}
const response = await this.queryData<Order>(context, querySpec);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import LocalStorageGateway, { OFFICE_MAPPING_PATH } from './local-storage-gateway';
import LocalStorageGateway, {
OFFICE_MAPPING_PATH,
ROLE_MAPPING_PATH,
} from './local-storage-gateway';
import { CamsRole } from '../../../../../../common/src/cams/roles';

describe('map get', () => {
test('should return appropriate string for valid path', () => {
Expand All @@ -8,4 +12,19 @@ describe('map get', () => {
test('should return null for invalid path', () => {
expect(LocalStorageGateway.get('INVALID_PATH')).toBeNull();
});

test('should include case assignment manager role', () => {
const roleMap = LocalStorageGateway.get(ROLE_MAPPING_PATH);
expect(roleMap).toContain(CamsRole.CaseAssignmentManager);
});

test('should include trial attorney role', () => {
const roleMap = LocalStorageGateway.get(ROLE_MAPPING_PATH);
expect(roleMap).toContain(CamsRole.TrialAttorney);
});

test('should include data verification role', () => {
const roleMap = LocalStorageGateway.get(ROLE_MAPPING_PATH);
expect(roleMap).toContain(CamsRole.DataVerifier);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const ROLE_MAPPING_PATH = '/rolemapping.csv';
const ROLE_MAPPING =
'ad_group_name,idp_group_name,cams_role\n' +
'USTP_CAMS_Case_assignment_Manager,USTP CAMS Case Assignment Manager,CaseAssignmentManager\n' +
'USTP_CAMS_Trial_Attorney,USTP CAMS Trial Attorney,TrialAttorney\n';
'USTP_CAMS_Trial_Attorney,USTP CAMS Trial Attorney,TrialAttorney\n' +
'USTP_CAMS_Data_Verifier,USTP CAMS Data Verifier,DataVerifier\n';

export const OFFICE_MAPPING_PATH = '/officemapping.csv';
const OFFICE_MAPPING =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class OrdersController implements CamsController {
return this.handleConsolidations(context);
case 'orders':
return this.handleOrders(context);
case 'order-manual-sync':
case 'orders-sync':
return this.handleOrderSync(context);
case 'orders-suggestions':
return this.handleOrdersSuggestions(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default class FakeAssignmentsCosmosClientHumble {
name: 'Test Attorney',
role: 'TrialAttorney',
assignedOn: '2024-03-05',
changedBy: MockData.getCamsUserReference(),
updatedOn: '2024-03-05',
updatedBy: MockData.getCamsUserReference(),
};
}
assignment.id = `assignment-id-${Math.round(Math.random() * 1000)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { ConsolidationOrder } from '../../../../../common/src/cams/orders';
import { ApplicationContext } from '../../adapters/types/basic';
import { ConsolidationOrdersRepository } from '../../use-cases/gateways.types';
import { LocalCosmosDbRepository } from './local-cosmos-db-repository';
import { OrdersSearchPredicate } from '../../../../../common/src/api/search';

export class LocalConsolidationOrdersRepository
extends LocalCosmosDbRepository<ConsolidationOrder>
implements ConsolidationOrdersRepository
{
async getAll(_context: ApplicationContext): Promise<ConsolidationOrder[]> {
async search(
_context: ApplicationContext,
_predicate?: OrdersSearchPredicate,
): Promise<ConsolidationOrder[]> {
return [...this.container];
}
}
Loading

0 comments on commit 927208e

Please sign in to comment.