Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): allow oauth claim to set 0 for no quota #7581

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/src/domain/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ describe('AuthService', () => {
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
});

it('should ignore a 0 quota', async () => {
it('should not set quota for 0 quota', async () => {
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
userMock.getByEmail.mockResolvedValue(null);
userMock.getAdmin.mockResolvedValue(userStub.user1);
Expand All @@ -543,7 +543,7 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);

expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithUnsetQuotaClaim);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to remove these user objects and just assert it matches an object containing the right quota value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can make that change

});

it('should use a valid storage quota', async () => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/domain/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class AuthService {
const storageQuota = this.getClaim(profile, {
key: storageQuotaClaim,
default: defaultStorageQuota,
isValid: (value: unknown) => isNumber(value) && value > 0,
isValid: (value: unknown) => isNumber(value) && value >= 0,
});

const userName = profile.name ?? `${profile.given_name || ''} ${profile.family_name || ''}`;
Expand Down
7 changes: 7 additions & 0 deletions server/test/fixtures/user.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const userDto = {
quotaSizeInBytes: 5_368_709_120,
storageLabel: null,
},
userWithUnsetQuotaClaim: {
email: 'test@immich.com',
name: ' ',
oauthId: 'my-auth-user-sub',
quotaSizeInBytes: null,
storageLabel: null,
},
};

export const userStub = {
Expand Down
Loading