Skip to content

Commit

Permalink
refactor(user): no longer expose user id and rely only on login
Browse files Browse the repository at this point in the history
  • Loading branch information
tsimbalar committed Jan 14, 2021
1 parent a868534 commit d7e378b
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 18 deletions.
3 changes: 0 additions & 3 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ components:
additionalProperties: false
WhoAmIResponse:
properties:
id:
type: string
login:
type: string
name:
Expand All @@ -299,7 +297,6 @@ components:
type: string
type: array
required:
- id
- login
- name
- scopes
Expand Down
1 change: 0 additions & 1 deletion src/api/__testTools__/Fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { User, UserWithScopes } from '../../domain/IUserRepository';
export class Fixtures {
public static userWithScopes(scopes: string[], options: Partial<User> = {}): UserWithScopes {
return {
id: options.id ?? `USER_ID_${new Date().getTime()}`,
login: options.login ?? `USER_LOGIN_${new Date().getTime()}`,
name: options.name === undefined ? `User Name ${new Date().getTime()}` : options.name,
scopes,
Expand Down
4 changes: 2 additions & 2 deletions src/api/__tests__/builds-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('/builds', () => {
const response = await agent.get('/builds').set('Authorization', `Bearer ${token}`).send();

const body = response.body as DynamicBuildInfoMetadataResponse;
expect(body.currentUser).toEqual({ id: user.id, name: user.name });
expect(body.currentUser).toEqual({ id: user.login, name: user.name });
});

test('should return login when user has no name', async () => {
Expand All @@ -99,7 +99,7 @@ describe('/builds', () => {
.send();

const body = response.body as DynamicBuildInfoMetadataResponse;
expect(body.currentUser).toEqual({ id: userWithNoName.id, name: userWithNoName.login });
expect(body.currentUser).toEqual({ id: userWithNoName.login, name: userWithNoName.login });
});

test('should return spaces of user', async () => {
Expand Down
1 change: 0 additions & 1 deletion src/api/__tests__/diagnostics-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('Public API /_/* (diagnostics)', () => {
expect(response.status).toBe(200);
expect(response.type).toBe('application/json');
expect(response.body).toEqual<WhoAmIResponse>({
id: existingUser.id,
name: existingUser.name,
login: existingUser.login,
scopes: existingUser.scopes,
Expand Down
4 changes: 2 additions & 2 deletions src/api/__tests__/dynamic-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('/dynamic', () => {
const response = await agent.get('/dynamic').set('Authorization', `Bearer ${token}`).send();

const body = response.body as DynamicBuildInfoMetadataResponse;
expect(body.currentUser).toEqual({ id: user.id, name: user.name });
expect(body.currentUser).toEqual({ id: user.login, name: user.name });
});

test('should return login when user has no name', async () => {
Expand All @@ -99,7 +99,7 @@ describe('/dynamic', () => {
.send();

const body = response.body as DynamicBuildInfoMetadataResponse;
expect(body.currentUser).toEqual({ id: userWithNoName.id, name: userWithNoName.login });
expect(body.currentUser).toEqual({ id: userWithNoName.login, name: userWithNoName.login });
});

test('should return spaces of user', async () => {
Expand Down
1 change: 0 additions & 1 deletion src/api/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface HealthCheckResponse {
}

export interface WhoAmIResponse {
readonly id: string;
readonly login: string;
readonly name: string | null;
readonly scopes: string[];
Expand Down
1 change: 0 additions & 1 deletion src/api/auth/BearerAuthenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class BearerAuthenticationProvider implements IAuthenticationProvider {
const user = await this.users.getUserFromToken(token);

return {
id: user.id,
name: user.name,
login: user.login,
token,
Expand Down
1 change: 0 additions & 1 deletion src/api/auth/IAuthentication.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Request } from 'express';

export interface IAuthenticatedUser {
readonly id: string;
readonly login: string;
readonly name: string | null;
readonly token: string;
Expand Down
2 changes: 1 addition & 1 deletion src/api/controllers/BuildInfoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class BuildInfoController extends Controller {

private mapToUser(authUser: IAuthenticatedUser): catlightCore.User {
return {
id: authUser.id,
id: authUser.login,
name: authUser.name ?? authUser.login,
};
}
Expand Down
1 change: 0 additions & 1 deletion src/api/controllers/DiagnosticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class DiagnosticsController extends Controller {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const currentUser = request.user!;
return {
id: currentUser.id,
name: currentUser.name,
login: currentUser.login,
scopes: currentUser.tokenScopes,
Expand Down
1 change: 0 additions & 1 deletion src/domain/IUserRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export interface User {
readonly login: string;
readonly name: string | null;
readonly id: string;
}

export interface UserWithScopes extends User {
Expand Down
1 change: 0 additions & 1 deletion src/infra/github/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class UserRepository implements IUserRepository {
.filter((x) => x !== '');

return {
id: response.data.id.toString(),
login: response.data.login,
name: response.data.name,
scopes: userScopes,
Expand Down
2 changes: 1 addition & 1 deletion src/infra/github/__testTools__/TestConstants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Repo, RepoName, Workflow } from '../../../domain/IRepoRepository';
import { User } from '../../../domain/IUserRepository';

export const THIS_REPO_OWNER: User = { id: '160544', login: 'tsimbalar', name: 'Thibaud Desodt' };
export const THIS_REPO_OWNER: User = { login: 'tsimbalar', name: 'Thibaud Desodt' };

export const THIS_REPO_NAME = new RepoName(THIS_REPO_OWNER.login, 'gha-build-monitor');

Expand Down
1 change: 0 additions & 1 deletion src/infra/memory/InMemoryUserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class InMemoryUserRepository implements IUserRepository {
}

return {
id: storedUser.id,
name: storedUser.name,
login: storedUser.login,
scopes: storedUser.scopes,
Expand Down

0 comments on commit d7e378b

Please sign in to comment.