Skip to content

Commit

Permalink
feat: add link user snackbar (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt authored Nov 6, 2024
1 parent e7c9ada commit 7b7f9ba
Show file tree
Hide file tree
Showing 46 changed files with 651 additions and 639 deletions.
580 changes: 223 additions & 357 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"typeorm": "typeorm-ts-node-commonjs"
},
"dependencies": {
"@aws-sdk/client-kinesis": "^3.679.0",
"@aws-sdk/client-kinesis": "^3.685.0",
"@nestjs/axios": "^3.1.1",
"@nestjs/common": "^10.4.6",
"@nestjs/common": "^10.4.7",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.6",
"@nestjs/core": "^10.4.7",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.6",
"@nestjs/platform-express": "^10.4.7",
"@nestjs/schedule": "^4.1.1",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/swagger": "^8.0.1",
"@nestjs/swagger": "^8.0.2",
"@nestjs/terminus": "^10.2.3",
"@nestjs/typeorm": "^10.0.2",
"class-transformer": "^0.5.1",
Expand Down Expand Up @@ -62,11 +62,11 @@
"uuid": "^11.0.2"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@eslint/js": "^9.14.0",
"@golevelup/ts-jest": "^0.5.6",
"@nestjs/cli": "^10.4.5",
"@nestjs/cli": "^10.4.7",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.6",
"@nestjs/testing": "^10.4.7",
"@types/cron": "^2.4.3",
"@types/deep-equal": "^1.0.4",
"@types/ejs": "^3.1.5",
Expand All @@ -76,15 +76,15 @@
"@types/jest": "^29.5.14",
"@types/libsodium-wrappers": "^0.7.14",
"@types/lodash.merge": "^4.6.9",
"@types/node": "^22.8.4",
"@types/node": "^22.9.0",
"@types/passport": "^1.0.17",
"@types/passport-http": "^0.3.11",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"eslint": "^9.13.0",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand All @@ -96,7 +96,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.12.2"
"typescript-eslint": "^8.13.0"
},
"jest": {
"moduleFileExtensions": [
Expand Down
4 changes: 2 additions & 2 deletions src/audit/audit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import merge from 'lodash.merge';
import os from 'os';
import snakecaseKeys from 'snakecase-keys';

import { AuditStreamerService } from './audit-streamer.service';
import { ActionDto } from '../intention/dto/action.dto';
import { IntentionDto } from '../intention/dto/intention.dto';
import { AuditStreamerService } from './audit-streamer.service';
import { UserDto } from '../intention/dto/user.dto';
import { EdgeDto } from '../persistence/dto/edge.dto';
import { EdgeInsertDto } from '../persistence/dto/edge-rest.dto';
import { UserDto } from '../intention/dto/user.dto';
import { VertexInsertDto } from '../persistence/dto/vertex-rest.dto';
import { VertexDto } from '../persistence/dto/vertex.dto';
import { UserRolesDto } from '../collection/dto/user-roles.dto';
Expand Down
6 changes: 6 additions & 0 deletions src/collection/dto/user-roles.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
OAUTH2_CLIENT_MAP_ROLES,
OAUTH2_CLIENT_DOMAIN,
} from '../../constants';
import { UserDto } from '../../persistence/dto/user.dto';

export class UserRolesDto extends UserImportDto {
alias?: any;
roles!: string[];

constructor(
public readonly vertex: string,
userInfo: any,
collection: UserDto | undefined = undefined,
) {
super();
// Map or use static value
Expand All @@ -27,6 +30,9 @@ export class UserRolesDto extends UserImportDto {
this.name = get(userInfo, OAUTH2_CLIENT_MAP_NAME);
this.roles = get(userInfo, OAUTH2_CLIENT_MAP_ROLES, []);
this.username = get(userInfo, OAUTH2_CLIENT_MAP_USERNAME, '').toLowerCase();
if (collection) {
this.alias = collection.alias;
}
}

toUserImportDto(): UserImportDto {
Expand Down
21 changes: 12 additions & 9 deletions src/collection/user-collection.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { Request } from 'express';

import { USER_ALIAS_DOMAIN_GITHUB } from '../constants';
Expand Down Expand Up @@ -44,7 +44,15 @@ export class UserCollectionService {
async extractUserFromRequest(req: Request): Promise<UserRolesDto> {
const loggedInUser = new UserRolesDto('', (req.user as any).userinfo);
const vertex = await this.upsertUser(req, loggedInUser.toUserImportDto());
return new UserRolesDto(vertex.toString(), (req.user as any).userinfo);
const collection = await this.collectionRepository.getCollectionByVertexId(
'user',
vertex.toString(),
);
return new UserRolesDto(
vertex.toString(),
(req.user as any).userinfo,
collection,
);
}

async upsertUser(req: Request, userInfo: UserImportDto) {
Expand Down Expand Up @@ -87,14 +95,12 @@ export class UserCollectionService {
state,
))
) {
console.log('hi');
throw new BadRequestException('Request state does not match');
}
// console.log(state);

const token = await this.githubService.getUserAccessToken(code);
const userData = await this.githubService.getUserInfo(token);

// console.log(userData);

const vertex: VertexInsertDto = {
collection: 'user',
data: {
Expand All @@ -105,16 +111,13 @@ export class UserCollectionService {
guid: userData.id,
name: userData.name,
username: userData.login,
raw: userData,
},
],
},
};
delete vertex.data.id;
delete vertex.data.vertex;

// console.log(vertex);

await this.graphService.editVertex(
req,
existingUser.vertex.toString(),
Expand Down
6 changes: 4 additions & 2 deletions src/persistence/dto/collection-config-rest.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export type CollectionEdgeInstanceConfig = Omit<
};

export class CollectionFieldConfig {
color!: string;
hint!: string;
init?: 'uuid' | 'now';
mask?: {
Expand All @@ -60,7 +59,8 @@ export class CollectionFieldConfig {
| 'url';
unique?: boolean;
uniqueParent?: boolean;
value?: string;
value?: string | boolean;
valuePath?: string;
}

export class CollectionFieldConfigMap {
Expand Down Expand Up @@ -90,8 +90,10 @@ export class CollectionConfigRestDto {
collection!: CollectionNames;
collectionMapper!: CollectionMap[];
collectionVertexName!: string;
color!: string;
edges!: CollectionEdgeConfig[];
fields!: CollectionFieldConfigMap;
hint!: string;
index!: number;
name!: string;
parent!: CollectionConfigParent;
Expand Down
1 change: 1 addition & 0 deletions src/persistence/dto/preference-rest.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface PreferenceRestDto {
graphVertexVisibility: { [key: string]: boolean };
graphEdgeSrcTarVisibility: { [key: string]: boolean };
homeSectionTab: number;
ignoreGitHubLink: boolean;
}
4 changes: 4 additions & 0 deletions src/persistence/dto/preference.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class PreferenceDto {
@Column()
homeSectionTab: number;

@Column()
ignoreGitHubLink: boolean = false;

public toRestDto(): PreferenceRestDto {
return {
browseConnectionFilter: this.browseConnectionFilter ?? 'connected',
Expand All @@ -39,6 +42,7 @@ export class PreferenceDto {
graphVertexVisibility: this.graphVertexVisibility,
graphEdgeSrcTarVisibility: this.graphEdgeSrcTarVisibility,
homeSectionTab: this.homeSectionTab ?? 0,
ignoreGitHubLink: this.ignoreGitHubLink ?? false,
};
}
}
16 changes: 11 additions & 5 deletions src/persistence/dto/user-rest.dto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { VertexPointerRestDto } from './vertex-pointer-rest.dto';

// Shared DTO: Copy in back-end and front-end should be identical
export class UserGroupRestDto {
domain?: string;
id?: string;
name?: string;

export class UserAliasRestDto {
domain!: string;
guid!: string;
name!: string;
username!: string;
}

export class UserRestDto extends VertexPointerRestDto {
id!: string;
alias?: UserAliasRestDto[];
domain!: string;
email!: string;
group?: UserGroupRestDto;
guid!: string;
name!: string;
username!: string;
}

export interface UserSelfRestDto extends Omit<UserRestDto, 'tags'> {
roles: string[];
}
8 changes: 0 additions & 8 deletions src/persistence/dto/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export class UserAliasDto {
@IsString()
@Column()
username: string;

@IsOptional()
@Column()
raw?: any;
}

export class UserGroupDto {
Expand Down Expand Up @@ -70,10 +66,6 @@ export class UserDto extends VertexPointerDto {
@Column()
email: string;

@Column(() => UserGroupDto)
@IsOptional()
group?: UserGroupDto;

@IsDefined()
@IsString()
@Column()
Expand Down
Loading

0 comments on commit 7b7f9ba

Please sign in to comment.