Skip to content

Commit f887ce0

Browse files
committed
Drop session everywhere possible
1 parent a70ec3c commit f887ce0

File tree

222 files changed

+1321
-2685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+1321
-2685
lines changed

src/components/authentication/authentication.service.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class AuthenticationService {
6969
const users = this.moduleRef.get(userMod.UserService, { strict: false });
7070
userId = await this.gel.usingOptions(
7171
disableAccessPolicies,
72-
async () => await users.create(input, session),
72+
async () => await users.create(input),
7373
);
7474
} catch (e) {
7575
// remap field prop as `email` field is at a different location in register() than createPerson()
@@ -85,7 +85,7 @@ export class AuthenticationService {
8585
return userId;
8686
}
8787

88-
async login(input: LoginInput, session: Session): Promise<ID> {
88+
async login(input: LoginInput): Promise<ID> {
8989
const hash = await this.repo.getPasswordHash(input);
9090

9191
if (!(await this.crypto.verify(hash, input.password))) {
@@ -259,7 +259,6 @@ export class AuthenticationService {
259259
async changePassword(
260260
oldPassword: string,
261261
newPassword: string,
262-
session: Session,
263262
): Promise<void> {
264263
if (!oldPassword)
265264
throw new InputException('Old Password Required', 'oldPassword');
@@ -291,10 +290,7 @@ export class AuthenticationService {
291290
});
292291
}
293292

294-
async resetPassword(
295-
{ token, password }: ResetPasswordInput,
296-
session: Session,
297-
): Promise<void> {
293+
async resetPassword({ token, password }: ResetPasswordInput): Promise<void> {
298294
const emailToken = await this.repo.findEmailToken(token);
299295
if (!emailToken) {
300296
throw new InputException('Token is invalid', 'TokenInvalid');

src/components/authentication/login.resolver.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ export class LoginResolver {
3030
`,
3131
})
3232
@Anonymous()
33-
async login(
34-
@Args('input') input: LoginInput,
35-
@AnonSession() session: Session,
36-
): Promise<LoginOutput> {
37-
const user = await this.authentication.login(input, session);
33+
async login(@Args('input') input: LoginInput): Promise<LoginOutput> {
34+
const user = await this.authentication.login(input);
3835
await this.authentication.refreshCurrentSession();
3936
return { user };
4037
}

src/components/authentication/password.resolver.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Args, Mutation, Resolver } from '@nestjs/graphql';
22
import { stripIndent } from 'common-tags';
3-
import { AnonSession, LoggedInSession, type Session } from '~/common';
43
import { Anonymous } from './anonymous.decorator';
54
import { AuthenticationService } from './authentication.service';
65
import {
@@ -24,9 +23,8 @@ export class PasswordResolver {
2423
})
2524
async changePassword(
2625
@Args() { oldPassword, newPassword }: ChangePasswordArgs,
27-
@LoggedInSession() session: Session,
2826
): Promise<ChangePasswordOutput> {
29-
await this.authentication.changePassword(oldPassword, newPassword, session);
27+
await this.authentication.changePassword(oldPassword, newPassword);
3028
return { success: true };
3129
}
3230

@@ -49,9 +47,8 @@ export class PasswordResolver {
4947
@Anonymous()
5048
async resetPassword(
5149
@Args('input') input: ResetPasswordInput,
52-
@AnonSession() session: Session,
5350
): Promise<ResetPasswordOutput> {
54-
await this.authentication.resetPassword(input, session);
51+
await this.authentication.resetPassword(input);
5552
return { success: true };
5653
}
5754
}

src/components/authentication/register.resolver.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Resolver,
77
} from '@nestjs/graphql';
88
import { stripIndent } from 'common-tags';
9-
import { AnonSession, type Session } from '~/common';
109
import { Loader, type LoaderOf } from '~/core';
1110
import { Privileges } from '../authorization';
1211
import { Power } from '../authorization/dto';
@@ -30,12 +29,9 @@ export class RegisterResolver {
3029
`,
3130
})
3231
@Anonymous()
33-
async register(
34-
@Args('input') input: RegisterInput,
35-
@AnonSession() session: Session,
36-
): Promise<RegisterOutput> {
37-
const user = await this.authentication.register(input, session);
38-
await this.authentication.login(input, session);
32+
async register(@Args('input') input: RegisterInput): Promise<RegisterOutput> {
33+
const user = await this.authentication.register(input);
34+
await this.authentication.login(input);
3935
await this.authentication.refreshCurrentSession();
4036
return { user };
4137
}

src/components/authentication/session.resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export class SessionResolver {
123123
// They should still be able to see their own props from this field.
124124
// Otherwise, it could be that the impersonatee can't see the impersonator's roles,
125125
// and now the UI can't stop impersonating because it doesn't know the impersonator's roles.
126-
return await this.authentication.asUser(impersonator, (_) =>
127-
this.users.readOne(impersonator.userId, _),
126+
return await this.authentication.asUser(impersonator, () =>
127+
this.users.readOne(impersonator.userId),
128128
);
129129
}
130130

src/components/authorization/policy/executor/edge-privileges.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export class EdgePrivileges<
3030
this.resource = EnhancedResource.of(resource);
3131
}
3232

33-
/** @deprecated */
34-
get session() {
35-
return this.policyExecutor.sessionHost.current;
36-
}
37-
3833
get context() {
3934
return this.object;
4035
}

src/components/budget/budget-record.loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class BudgetRecordLoader extends ObjectViewAwareLoader<BudgetRecord> {
1616
}
1717

1818
async loadOne(id: ID, view?: ObjectView): Promise<BudgetRecord> {
19-
return await this.budgets.readOneRecord(id, this.session, view);
19+
return await this.budgets.readOneRecord(id, view);
2020
}
2121

2222
// Below is the same logic as SingleItemLoader

src/components/budget/budget-record.repository.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
labelForView,
88
NotFoundException,
99
type ObjectView,
10-
type Session,
1110
type UnsecuredDto,
1211
} from '~/common';
1312
import { DtoRepository } from '~/core/database';
@@ -35,7 +34,6 @@ interface BudgetRecordHydrateArgs {
3534
recordVar?: string;
3635
projectVar?: string;
3736
outputVar?: string;
38-
session: Session;
3937
view?: ObjectView;
4038
}
4139

@@ -127,11 +125,7 @@ export class BudgetRecordRepository extends DtoRepository<
127125
return result.dto;
128126
}
129127

130-
async list(
131-
input: BudgetRecordListInput,
132-
session: Session,
133-
view?: ObjectView,
134-
) {
128+
async list(input: BudgetRecordListInput, view?: ObjectView) {
135129
const { budgetId } = input.filter ?? {};
136130
const result = await this.db
137131
.query()
@@ -151,7 +145,6 @@ export class BudgetRecordRepository extends DtoRepository<
151145
recordVar = 'node',
152146
projectVar = 'project',
153147
outputVar = 'dto',
154-
session,
155148
view,
156149
}: BudgetRecordHydrateArgs) {
157150
return (query: Query) =>

src/components/budget/budget-record.resolver.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ResolveField,
66
Resolver,
77
} from '@nestjs/graphql';
8-
import { LoggedInSession, mapSecuredValue, type Session } from '~/common';
8+
import { mapSecuredValue } from '~/common';
99
import { Loader, type LoaderOf } from '~/core';
1010
import { OrganizationLoader } from '../organization';
1111
import { SecuredOrganization } from '../organization/dto';
@@ -34,14 +34,9 @@ export class BudgetRecordResolver {
3434
description: 'Update a budgetRecord',
3535
})
3636
async updateBudgetRecord(
37-
@LoggedInSession() session: Session,
3837
@Args('input') { budgetRecord: input, changeset }: UpdateBudgetRecordInput,
3938
): Promise<UpdateBudgetRecordOutput> {
40-
const budgetRecord = await this.service.updateRecord(
41-
input,
42-
session,
43-
changeset,
44-
);
39+
const budgetRecord = await this.service.updateRecord(input, changeset);
4540
return { budgetRecord };
4641
}
4742
}

src/components/budget/budget.loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export class BudgetLoader extends ObjectViewAwareLoader<Budget> {
1010
}
1111

1212
async loadManyByView(ids: readonly ID[], view?: ObjectView) {
13-
return await this.budgets.readMany(ids, this.session, view);
13+
return await this.budgets.readMany(ids, view);
1414
}
1515
}

0 commit comments

Comments
 (0)