Skip to content

Commit

Permalink
#1612 - GTM configuration (#2660)
Browse files Browse the repository at this point in the history
* configured google tag manager, fixed bug while signing in/up with email and password

* Removed unused google analytics implementation

* Fixed bug
  • Loading branch information
maciej-zarzeczny committed Apr 20, 2022
1 parent 4918aa8 commit 1ced726
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 29,594 deletions.
6 changes: 5 additions & 1 deletion verification/curator-service/api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ module.exports = {
rules: {
'no-bitwise': ['error'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
quotes: ['error', 'single', { 'avoidEscape': true }],
semi: ['error', 'always'],
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off'
},
};
2 changes: 1 addition & 1 deletion verification/curator-service/api/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module.exports = {
trailingComma: "all",
singleQuote: true,
printWidth: 80,
tabWidth: 4
tabWidth: 4
};
4 changes: 2 additions & 2 deletions verification/curator-service/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export class AuthController {
// @ts-ignore
passport.serializeUser((user: IUser, done: any) => {
// Serializes the user id in the cookie, no user info should be in there, just the id.
done(null, user._id.toHexString());
done(null, user._id);
});

passport.deserializeUser((id: string, done: any) => {
Expand Down Expand Up @@ -746,7 +746,7 @@ export class AuthController {
});
}

done(null, userPublicFields(user));
done(null, user);
} catch (error) {
done(error);
}
Expand Down
63 changes: 36 additions & 27 deletions verification/curator-service/api/src/controllers/geocode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export default class GeocodeProxy {

suggest = async (req: Request, res: Response): Promise<void> => {
try {
const response = await axios.get(
this.locationServiceURL + req.url,
);
const response = await axios.get(this.locationServiceURL + req.url);
res.status(response.status).json(response.data);
return;
} catch (err) {
Expand All @@ -32,9 +30,7 @@ export default class GeocodeProxy {

convertUTM = async (req: Request, res: Response): Promise<void> => {
try {
const response = await axios.get(
this.locationServiceURL + req.url,
);
const response = await axios.get(this.locationServiceURL + req.url);
res.status(response.status).json(response.data);
return;
} catch (err) {
Expand All @@ -44,7 +40,7 @@ export default class GeocodeProxy {
return;
}
}
}
};

/**
* This is the only "meaty" method on this controller. It does proxy the
Expand All @@ -56,42 +52,55 @@ export default class GeocodeProxy {
*/
countryNames = async (req: Request, res: Response): Promise<void> => {
const database = db();
const locationCountryCodes = await database.collection('cases').distinct('location.country', {}, {
collation: {
locale: 'en_US',
strength: 2,
}
});
const travelHistoryCodes = await database.collection('cases').distinct('travelHistory.travel.location.country', {}, {
collation: {
locale: 'en_US',
strength: 2,
}
});
const allCodes = new Set<string>(locationCountryCodes.concat(travelHistoryCodes));
const locationCountryCodes = await database
.collection('cases')
.distinct(
'location.country',
{},
{
collation: {
locale: 'en_US',
strength: 2,
},
},
);
const travelHistoryCodes = await database.collection('cases').distinct(
'travelHistory.travel.location.country',
{},
{
collation: {
locale: 'en_US',
strength: 2,
},
},
);
const allCodes = new Set<string>(
locationCountryCodes.concat(travelHistoryCodes),
);
const namesMap: {
[key: string]: string[] | undefined
[key: string]: string[] | undefined;
} = {};
for (const code of allCodes) {
const names = countries.getName(code, 'en', { select: 'all' });
// ask the geocoding service what name it uses
try {
const res = await axios.get<string, AxiosResponse<string>>(
this.locationServiceURL + `/geocode/countryName?c=${code}`
)
this.locationServiceURL + `/geocode/countryName?c=${code}`,
);
const geocodeName = res.data;
if (names.indexOf(geocodeName) < 0) {
names.push(geocodeName);
}
}
catch (err) {
} catch (err) {
// doesn't matter, weird that geocoding service doesn't have this code though
logger.warn(`geocoding service doesn't have a name for country code ${code} found in the DB!`);
logger.warn(
`geocoding service doesn't have a name for country code ${code} found in the DB!`,
);
}
namesMap[code] = names;
}
res.status(200).json(namesMap);
}
};

seed = async (req: Request, res: Response): Promise<void> => {
const response = await axios.post(
Expand Down
2 changes: 1 addition & 1 deletion verification/curator-service/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function makeApp() {
const sourcesController = new SourcesController(
emailClient,
awsBatchClient,
env.DATASERVER_URL
env.DATASERVER_URL,
);
apiRouter.get(
'/sources',
Expand Down
1 change: 0 additions & 1 deletion verification/curator-service/api/src/model/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ export type IAutomation = {
// TODO remove this when source is no longer a Mongoose document
modifiedPaths: () => [string];
};

2 changes: 1 addition & 1 deletion verification/curator-service/api/src/model/date-filter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type IDateFilter = {
numDaysBeforeToday: number;
op: 'EQ'|'LT'|'GT';
op: 'EQ' | 'LT' | 'GT';
};
2 changes: 1 addition & 1 deletion verification/curator-service/api/src/model/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type IParser = {
awsLambdaArn: string;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ interface Field {
}

export type IRegexParsing = {
fields: [Field],
fields: [Field];
};
8 changes: 4 additions & 4 deletions verification/curator-service/api/src/model/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { IUploadSummary } from './upload-summary';
import { ObjectId } from 'mongodb';

export type IUpload = {
_id: ObjectId,
status: string,
summary: IUploadSummary,
created: Date,
_id: ObjectId;
status: string;
summary: IUploadSummary;
created: Date;
};
27 changes: 14 additions & 13 deletions verification/curator-service/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { logger } from './util/logger';
// Start Express server.
let server;

makeApp().then(app => {
server = app.listen(app.get('port'), () => {
logger.info(`Curator service listening on port ${app.get('port')}`);
logger.info(' Press CTRL-C to stop\n');
makeApp()
.then((app) => {
server = app.listen(app.get('port'), () => {
logger.info(`Curator service listening on port ${app.get('port')}`);
logger.info(' Press CTRL-C to stop\n');
});
// Set global 1-hour timeout.
// TODO: Make this more fine-grained once we fix
// https://github.com/globaldothealth/list/issues/961.
server.setTimeout(60 * 60 * 1000);
})
.catch((e) => {
logger.error('Could not start server!', e);
process.exit(1);
});
// Set global 1-hour timeout.
// TODO: Make this more fine-grained once we fix
// https://github.com/globaldothealth/list/issues/961.
server.setTimeout(60 * 60 * 1000);
})
.catch(e => {
logger.error('Could not start server!', e);
process.exit(1);
});

export default server;
49 changes: 14 additions & 35 deletions verification/curator-service/api/test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('../src/clients/aws-lambda-client', () => {
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
let mongoServer: MongoMemoryServer;
let app:any;
let app: any;

beforeAll(async () => {
mongoServer = new MongoMemoryServer();
Expand Down Expand Up @@ -257,9 +257,7 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.post('/auth/profile/apiKey')
.expect(201);
await request.post('/auth/profile/apiKey').expect(201);
});

it('must let a user retrieve their API key', async () => {
Expand All @@ -271,12 +269,8 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.post('/auth/profile/apiKey')
.expect(201);
await request
.get('/auth/profile/apiKey')
.expect(200);
await request.post('/auth/profile/apiKey').expect(201);
await request.get('/auth/profile/apiKey').expect(200);
});

it('does not find an API key where none has been set', async () => {
Expand All @@ -288,9 +282,7 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.get('/auth/profile/apiKey')
.expect(404);
await request.get('/auth/profile/apiKey').expect(404);
});

it('lets the user get their profile by API key', async () => {
Expand All @@ -302,16 +294,11 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.post('/auth/profile/apiKey')
.expect(201);
const apiKey = await request
.get('/auth/profile/apiKey');
await request.post('/auth/profile/apiKey').expect(201);
const apiKey = await request.get('/auth/profile/apiKey');
request.set('X-API-key', apiKey.body);
await request.get('/auth/logout').expect(302);
await request
.get('/auth/profile')
.expect(200, /test-curator/);
await request.get('/auth/profile').expect(200, /test-curator/);
});

it("lets an admin delete another user's API key", async () => {
Expand All @@ -323,11 +310,8 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.post('/auth/profile/apiKey')
.expect(201);
const apiKey = await request
.get('/auth/profile/apiKey');
await request.post('/auth/profile/apiKey').expect(201);
const apiKey = await request.get('/auth/profile/apiKey');
await request.get('/auth/logout').expect(302);
await request
.post('/auth/register')
Expand All @@ -343,9 +327,7 @@ describe('api keys', () => {
// now try to use the API key
await request.get('/auth/logout').expect(302);
request.set('X-API-key', apiKey.body);
await request
.get('/auth/profile')
.expect(403);
await request.get('/auth/profile').expect(403);
});

it("does not let a non-admin delete another user's API key", async () => {
Expand All @@ -357,11 +339,8 @@ describe('api keys', () => {
email: 'foo@bar.com',
})
.expect(200, /test-curator/);
await request
.post('/auth/profile/apiKey')
.expect(201);
const apiKey = await request
.get('/auth/profile/apiKey');
await request.post('/auth/profile/apiKey').expect(201);
const apiKey = await request.get('/auth/profile/apiKey');
await request.get('/auth/logout').expect(302);
await request
.post('/auth/register')
Expand All @@ -375,4 +354,4 @@ describe('api keys', () => {
.post(`/auth/deleteApiKey/${userRes.body._id}`)
.expect(403);
});
});
});
4 changes: 1 addition & 3 deletions verification/curator-service/api/test/cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ describe('Cases', () => {
.expect(200)
.expect('Content-Type', /json/);
expect(mockedAxios.put).toHaveBeenCalledTimes(1);
expect(
mockedAxios.put,
).toHaveBeenCalledWith(
expect(mockedAxios.put).toHaveBeenCalledWith(
'http://localhost:3000/api/cases/5e99f21a1c9d440000ceb088',
{ age: '42', ...creatorMetadata },
);
Expand Down
12 changes: 7 additions & 5 deletions verification/curator-service/api/test/geocode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ describe('Geocode', () => {
});
it('combines proxied and local results for resolving country names', async () => {
// add a not-real-case document
await db().collection('cases').insertOne({
location: {
country: 'EE',
},
});
await db()
.collection('cases')
.insertOne({
location: {
country: 'EE',
},
});
mockedAxios.get.mockResolvedValueOnce({
status: 200,
statusText: 'OK',
Expand Down
Loading

0 comments on commit 1ced726

Please sign in to comment.