Skip to content

Commit 6def234

Browse files
author
Daniel Bradley
authored
Merge pull request #112 from o2Labs/2.0.0-release
2.0.0 release
2 parents f3b5a2b + 1b501b9 commit 6def234

18 files changed

+46
-405
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.0.0] - 2020-09-14
11+
12+
- Re-enable API write access.
13+
- Use newly migrated DB (using officeId).
14+
- Require officeId to be specified in config (to avoid renaming issues).
15+
- Disable public Cognito registrations.
16+
1017
## [1.2.0] - 2020-09-14
1118

1219
- Migrate DB to store all bookings with office ID rather than office name.

infrastructure/index.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ const userPool = new aws.cognito.UserPool(`${serviceName}-users`, {
159159
preSignUp: preSignUp.arn,
160160
verifyAuthChallengeResponse: verifyAuthChallengeResponse.arn,
161161
},
162-
// TODO: Block public sign-ups to the user pool.
163-
// adminCreateUserConfig: {
164-
// allowAdminCreateUserOnly: true,
165-
// },
162+
adminCreateUserConfig: {
163+
allowAdminCreateUserOnly: true,
164+
},
166165
tags,
167166
});
168167

@@ -414,7 +413,6 @@ const getHttpEnv = (): aws.types.input.lambda.FunctionEnvironment['variables'] =
414413
DEFAULT_WEEKLY_QUOTA: defaultWeeklyQuota.toString(),
415414
DATA_RETENTION_DAYS: logRetention.toString(),
416415
SHOW_TEST_BANNER: showTestBanner.toString(),
417-
READONLY: 'true',
418416
};
419417
if (caseSensitiveEmail) {
420418
env.CASE_SENSITIVE_EMAIL = 'true';

server/app-config.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DynamoDB from 'aws-sdk/clients/dynamodb';
22
import { Request } from 'express';
33
import { isValidEmail } from './users/model';
44
import { assert } from 'console';
5-
import { getOfficeId, isValidOfficeId } from './getOffices';
5+
import { isValidOfficeId } from './getOffices';
66
import { Arrays } from 'collection-fns';
77
import { UserType } from 'aws-sdk/clients/cognitoidentityserviceprovider';
88

@@ -19,7 +19,7 @@ type CognitoAuthConfig = {
1919
region: string;
2020
};
2121

22-
type OfficeQuotaConfig = { id?: string; name: string; quota: number; parkingQuota?: number };
22+
type OfficeQuotaConfig = { id: string; name: string; quota: number; parkingQuota?: number };
2323
export type OfficeQuota = Required<OfficeQuotaConfig>;
2424

2525
const isOfficeQuotaConfigs = (input: any): input is OfficeQuotaConfig[] =>
@@ -30,7 +30,7 @@ const isOfficeQuotaConfigs = (input: any): input is OfficeQuotaConfig[] =>
3030
o !== null &&
3131
typeof o.name === 'string' &&
3232
typeof o.quota === 'number' &&
33-
(typeof o.id === 'undefined' || typeof o.id === 'string') &&
33+
typeof o.id === 'string' &&
3434
(typeof o.parkingQuota === 'undefined' || typeof o.parkingQuota === 'number')
3535
);
3636

@@ -54,14 +54,13 @@ export type Config = {
5454
readonly?: boolean;
5555
};
5656

57-
const parseOfficeQuotas = (OFFICE_QUOTAS: string) => {
57+
const parseOfficeQuotas = (OFFICE_QUOTAS: string): OfficeQuota[] => {
5858
const officeQuotaConfigs = JSON.parse(OFFICE_QUOTAS);
5959
if (!isOfficeQuotaConfigs(officeQuotaConfigs)) {
6060
throw new Error('Invalid office quotas in OFFICE_QUOTAS');
6161
}
6262
const officeQuotas = officeQuotaConfigs.map((o) => ({
6363
...o,
64-
id: o.id ?? getOfficeId(o.name),
6564
parkingQuota: o.parkingQuota ?? 0,
6665
}));
6766
const invalidIds = officeQuotas.map((o) => o.id).filter((id) => !isValidOfficeId(id));

server/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const configureApp = (config: Config) => {
4646
app.get('/api/config', (req, res, next) => {
4747
try {
4848
const clientConfig = {
49-
version: '1.2.0',
49+
version: '2.0.0',
5050
showTestBanner: config.showTestBanner,
5151
auth:
5252
config.authConfig.type === 'cognito'

server/bookings/createBooking.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const createBooking = async (
6969
const newBooking = <BookingsModel>{
7070
id,
7171
parking: request.parking ?? false,
72-
office: requestedOffice.name,
72+
officeId: requestedOffice.id,
7373
date: request.date,
7474
user: request.user,
7575
...('created' in request ? { id: request.id, created: request.created } : {}),
@@ -130,7 +130,7 @@ export const createBooking = async (
130130
audit('2.1:DecrementingOfficeBookingCount');
131131
await decrementOfficeBookingCount(
132132
config,
133-
requestedOffice.name,
133+
requestedOffice.id,
134134
newBooking.date,
135135
newBooking.parking
136136
);
@@ -151,7 +151,7 @@ export const createBooking = async (
151151
audit('3.1:DecremetingOfficeBookingCount');
152152
await decrementOfficeBookingCount(
153153
config,
154-
requestedOffice.name,
154+
requestedOffice.id,
155155
newBooking.date,
156156
newBooking.parking
157157
);

server/bookings/deleteBooking.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const audit = (step: string, details?: any) =>
2121
const canManageBooking = (authUser: User, booking: BookingsModel) =>
2222
authUser.permissions.canManageAllBookings ||
2323
authUser.permissions.officesCanManageBookingsFor.find(
24-
(office) => office.name === booking.office
24+
(office) => office.id === booking.officeId
2525
) !== undefined;
2626

2727
export const deleteBooking = async (
@@ -63,7 +63,7 @@ export const deleteBooking = async (
6363

6464
try {
6565
audit('2:DecrementingOfficeBookingCount');
66-
await decrementOfficeBookingCount(config, booking.office, booking.date, booking.parking);
66+
await decrementOfficeBookingCount(config, booking.officeId, booking.date, booking.parking);
6767
audit('3:DecrementingUserBookingCount');
6868
await decrementUserBookingCount(config, booking.user, startOfWeek);
6969
} catch (err) {

server/bookings/model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const mapBooking = (config: Config, booking: DbBooking): Booking => ({
4040
created: booking.created,
4141
user: booking.user,
4242
date: booking.date,
43-
office: Arrays.get(config.officeQuotas, (office) => office.name === booking.office),
43+
office: Arrays.get(config.officeQuotas, (office) => office.id === booking.officeId),
4444
lastCancellation: getBookingLastCancelTime(booking.date),
4545
parking: booking.parking,
4646
});

server/bookings/queryBookings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const queryBookings = async (config: Config, currentUser: User, query: Bo
2626
}
2727

2828
const filterBookings = (booking: BookingsModel) =>
29-
(!query.office || booking.office === query.office.name) &&
29+
(!query.office || booking.officeId === query.office.id) &&
3030
(!query.date || booking.date === query.date) &&
3131
(!query.email || booking.user === query.email);
3232

@@ -35,7 +35,7 @@ export const queryBookings = async (config: Config, currentUser: User, query: Bo
3535
return mapBookings(config, userBookings.filter(filterBookings));
3636
} else if (query.office !== undefined) {
3737
const officeBookings = await queryBookingsDb(config, {
38-
office: query.office.name,
38+
officeId: query.office.id,
3939
date: query.date,
4040
});
4141
return mapBookings(config, officeBookings.filter(filterBookings));

server/db/bookings.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export interface CreateBookingModel {
99
id: string;
1010
user: string;
1111
date: string;
12-
office: string;
12+
officeId: string;
1313
parking: boolean;
1414
}
1515

16-
@table('bookings')
16+
@table('bookings-v2')
1717
export class BookingsModel {
1818
@rangeKey()
1919
id!: string;
@@ -22,7 +22,7 @@ export class BookingsModel {
2222
@attribute({ indexKeyConfigurations: { 'office-date-bookings': 'RANGE' } })
2323
date!: string;
2424
@attribute({ indexKeyConfigurations: { 'office-date-bookings': 'HASH' } })
25-
office!: string;
25+
officeId!: string;
2626
@attribute()
2727
parking!: boolean;
2828
@attribute()
@@ -53,11 +53,11 @@ export const getUserBookings = async (
5353

5454
export const queryBookings = async (
5555
config: Config,
56-
query: { office: string; date?: string }
56+
query: { officeId: string; date?: string }
5757
): Promise<BookingsModel[]> => {
5858
const mapper = buildMapper(config);
5959
const rows: BookingsModel[] = [];
60-
const mapperQuery: Partial<BookingsModel> = { office: query.office };
60+
const mapperQuery: Partial<BookingsModel> = { officeId: query.officeId };
6161
if (query.date !== undefined) {
6262
mapperQuery.date = query.date;
6363
}

server/db/bookingsV2.ts

-137
This file was deleted.

0 commit comments

Comments
 (0)