Skip to content

Commit

Permalink
Merge pull request #4223 from beyondessential/release-2022-42
Browse files Browse the repository at this point in the history
Release 2022 42
  • Loading branch information
biaoli0 authored Oct 17, 2022
2 parents 595aaa9 + d27f734 commit 69d22a4
Show file tree
Hide file tree
Showing 203 changed files with 4,656 additions and 3,163 deletions.
2 changes: 1 addition & 1 deletion jest.config-js.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"clearMocks": true,
"collectCoverageFrom": ["<rootDir>/src/**/*.js)"],
"collectCoverageFrom": ["<rootDir>/src/**/*.js"],
"coveragePathIgnorePatterns": ["__tests__"],
"testMatch": ["<rootDir>/src/__tests__/**/**.test.js"],
"setupFilesAfterEnv": ["../../jest.setup.js"],
Expand Down
1 change: 1 addition & 0 deletions packages/admin-panel-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@tupaia/access-policy": "3.0.0",
"@tupaia/api-client": "3.1.0",
"@tupaia/database": "1.0.0",
"@tupaia/report-server": "0.0.0",
"@tupaia/server-boilerplate": "1.0.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/admin-panel-server/src/@types/express/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
import { AccessPolicy } from '@tupaia/access-policy';
import { TupaiaApiClient } from '@tupaia/api-client';

import { AdminPanelSessionType } from '../../models';

Expand All @@ -11,11 +12,9 @@ declare global {
export interface Request {
accessPolicy: AccessPolicy;
session: AdminPanelSessionType;
}

export interface Response {
accessPolicy: AccessPolicy;
session: AdminPanelSessionType;
ctx: {
services: TupaiaApiClient;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ describe('DashboardVisualisationExtractor', () => {
aggregations: ['SUM_EACH_WEEK'],
},
transform: ['keyValueByDataElementName'],
output: {
type: 'bar',
x: 'period',
y: 'BCD1',
},
},
permissionGroup: 'Admin',
});
Expand Down Expand Up @@ -380,6 +385,49 @@ describe('DashboardVisualisationExtractor', () => {
permissionGroup: 'Admin',
});
});

it('includes rowsAndColumns output if previewMode is data', () => {
const extractor = new DashboardVisualisationExtractor(
{
code: 'viz',
name: 'My Viz',
data: {
fetch: {
dataElements: ['BCD1', 'BCD2'],
},
transform: ['keyValueByDataElementName'],
},
presentation: {
type: 'chart',
chartType: 'bar',
output: {
type: 'bar',
x: 'period',
y: 'BCD1',
},
},
permissionGroup: 'Admin',
},
draftDashboardItemValidator,
draftReportValidator,
);

const report = extractor.getReport(PreviewMode.DATA);

expect(report).toEqual({
code: 'viz',
config: {
fetch: {
dataElements: ['BCD1', 'BCD2'],
},
transform: ['keyValueByDataElementName'],
output: {
type: 'rowsAndColumns',
},
},
permissionGroup: 'Admin',
});
});
});

describe('getDashboardItem()', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/admin-panel-server/src/app/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
FetchTransformSchemasRequest,
FetchTransformSchemasRoute,
} from '../routes';
import { authHandlerProvider } from '../auth';

const { CENTRAL_API_URL = 'http://localhost:8090/v2' } = process.env;

Expand All @@ -49,6 +50,7 @@ const { CENTRAL_API_URL = 'http://localhost:8090/v2' } = process.env;
*/
export function createApp() {
const app = new OrchestratorApiBuilder(new TupaiaDatabase(), 'admin-panel')
.attachApiClientToContext(authHandlerProvider)
.useSessionModel(AdminPanelSessionModel)
.verifyLogin(hasTupaiaAdminPanelAccess)
.get('user', handleWith(UserRoute))
Expand Down
20 changes: 20 additions & 0 deletions packages/admin-panel-server/src/auth/authHandlerProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

import { UnauthenticatedError } from '@tupaia/utils';
import { Request } from 'express';

export const authHandlerProvider = (req: Request) => {
return {
getAuthHeader: () => {
const { session } = req;

if (!session) {
throw new UnauthenticatedError('Session is not attached');
}
return session.getAuthHeader();
},
};
};
6 changes: 6 additions & 0 deletions packages/admin-panel-server/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

export { authHandlerProvider } from './authHandlerProvider';
82 changes: 0 additions & 82 deletions packages/admin-panel-server/src/connections/CentralConnection.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/admin-panel-server/src/connections/EntityConnection.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/admin-panel-server/src/connections/ReportConnection.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/admin-panel-server/src/connections/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/admin-panel-server/src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

export { attachAuthorizationHeader } from './attachAuthorizationHeader';
export { upload } from './upload';
export { verifyBESAdminAccess } from './verifyBESAdminAccess';
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@
*
*/

import { Request, Response, NextFunction } from 'express';
import { Request } from 'express';

import { Route } from '@tupaia/server-boilerplate';

import { ReportConnection } from '../connections';

export type FetchAggregationOptionsRequest = Request<
Record<string, never>,
Record<string, unknown>[],
Record<string, never>
>;

export class FetchAggregationOptionsRoute extends Route<FetchAggregationOptionsRequest> {
private readonly reportConnection: ReportConnection;

public constructor(req: FetchAggregationOptionsRequest, res: Response, next: NextFunction) {
super(req, res, next);

this.reportConnection = new ReportConnection(req.session);
}

public async buildResponse() {
return this.reportConnection.fetchAggregationOptions();
return this.req.ctx.services.report.fetchAggregationOptions();
}
}
Loading

0 comments on commit 69d22a4

Please sign in to comment.