Browse Source

code review changes

pull/5016/head
csehatt741 6 days ago
committed by Thomas Kaul
parent
commit
9531ce9ec5
  1. 5
      CHANGELOG.md
  2. 21
      apps/api/src/app/user/user.controller.ts
  3. 4
      apps/client/src/app/components/user-account-access/user-account-access.html
  4. 28
      apps/client/src/app/services/data.service.ts
  5. 4
      libs/common/src/lib/permissions.ts
  6. 7574
      package-lock.json

5
CHANGELOG.md

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Added support for generating a new _Security Token_ via the user's account access panel
### Changed ### Changed
- Renamed `Account` to `account` in the `Order` database schema - Renamed `Account` to `account` in the `Order` database schema
@ -42,7 +46,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Set up the language localization for the static portfolio analysis rule: _Account Cluster Risks_ (Current Investment) - Set up the language localization for the static portfolio analysis rule: _Account Cluster Risks_ (Current Investment)
- Extended the data providers management of the admin control panel by the online status - Extended the data providers management of the admin control panel by the online status
- Added support for generating a new _Security Token_ via the user's account access panel
### Changed ### Changed

21
apps/api/src/app/user/user.controller.ts

@ -54,7 +54,10 @@ export class UserController {
public async deleteOwnUser( public async deleteOwnUser(
@Body() data: DeleteOwnUserDto @Body() data: DeleteOwnUserDto
): Promise<UserModel> { ): Promise<UserModel> {
const user = await this.validateOwnAccessToken(data.accessToken); const user = await this.validateOwnAccessToken(
data.accessToken,
this.request.user.id
);
return this.userService.deleteUser({ return this.userService.deleteUser({
id: user.id id: user.id
@ -83,18 +86,21 @@ export class UserController {
public async updateUserAccessToken( public async updateUserAccessToken(
@Param('id') id: string @Param('id') id: string
): Promise<AccessTokenResponse> { ): Promise<AccessTokenResponse> {
return await this.rotateUserAccessToken(id); return this.rotateUserAccessToken(id);
} }
@HasPermission(permissions.updateOwnAccess) @HasPermission(permissions.updateOwnAccessToken)
@Post('access-token') @Post('access-token')
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async updateOwnAccessToken( public async updateOwnAccessToken(
@Body() data: UpdateOwnAccessTokenDto @Body() data: UpdateOwnAccessTokenDto
): Promise<AccessTokenResponse> { ): Promise<AccessTokenResponse> {
const user = await this.validateOwnAccessToken(data.accessToken); const user = await this.validateOwnAccessToken(
data.accessToken,
this.request.user.id
);
return await this.rotateUserAccessToken(user.id); return this.rotateUserAccessToken(user.id);
} }
@Get() @Get()
@ -178,7 +184,8 @@ export class UserController {
} }
private async validateOwnAccessToken( private async validateOwnAccessToken(
accessToken: string accessToken: string,
userId: string
): Promise<UserModel> { ): Promise<UserModel> {
const hashedAccessToken = this.userService.createAccessToken({ const hashedAccessToken = this.userService.createAccessToken({
password: accessToken, password: accessToken,
@ -186,7 +193,7 @@ export class UserController {
}); });
const [user] = await this.userService.users({ const [user] = await this.userService.users({
where: { accessToken: hashedAccessToken, id: this.request.user.id } where: { accessToken: hashedAccessToken, id: userId }
}); });
if (!user) { if (!user) {

4
apps/client/src/app/components/user-account-access/user-account-access.html

@ -4,8 +4,8 @@
(ngSubmit)="onGenerateAccessToken()" (ngSubmit)="onGenerateAccessToken()"
> >
<div class="container"> <div class="container">
<h1 class="d-flex align-items-center justify-content-center h3 mb-3"> <h1 class="d-flex align-items-center justify-content-center h3 mb-3" i18n>
<span i18n>Security Token</span> Security Token
</h1> </h1>
<div class="d-flex align-items-center justify-content-center"> <div class="d-flex align-items-center justify-content-center">
<mat-form-field <mat-form-field

28
apps/client/src/app/services/data.service.ts

@ -704,20 +704,6 @@ export class DataService {
return this.http.get<WatchlistResponse>('/api/v1/watchlist'); return this.http.get<WatchlistResponse>('/api/v1/watchlist');
} }
public updateUserAccessToken(aUserId: string) {
return this.http.post<AccessTokenResponse>(
`/api/v1/user/${aUserId}/access-token`,
{}
);
}
public updateOwnAccessToken(aAccessToken: UpdateOwnAccessTokenDto) {
return this.http.post<AccessTokenResponse>(
`/api/v1/user/access-token`,
aAccessToken
);
}
public loginAnonymous(accessToken: string) { public loginAnonymous(accessToken: string) {
return this.http.post<OAuthResponse>('/api/v1/auth/anonymous', { return this.http.post<OAuthResponse>('/api/v1/auth/anonymous', {
accessToken accessToken
@ -826,6 +812,20 @@ export class DataService {
}); });
} }
public updateOwnAccessToken(aAccessToken: UpdateOwnAccessTokenDto) {
return this.http.post<AccessTokenResponse>(
'/api/v1/user/access-token',
aAccessToken
);
}
public updateUserAccessToken(aUserId: string) {
return this.http.post<AccessTokenResponse>(
`/api/v1/user/${aUserId}/access-token`,
{}
);
}
public updateInfo() { public updateInfo() {
this.http.get<InfoItem>('/api/v1/info').subscribe((info) => { this.http.get<InfoItem>('/api/v1/info').subscribe((info) => {
const utmSource = window.localStorage.getItem('utm_source') as const utmSource = window.localStorage.getItem('utm_source') as

4
libs/common/src/lib/permissions.ts

@ -52,7 +52,7 @@ export const permissions = {
updateMarketData: 'updateMarketData', updateMarketData: 'updateMarketData',
updateMarketDataOfOwnAssetProfile: 'updateMarketDataOfOwnAssetProfile', updateMarketDataOfOwnAssetProfile: 'updateMarketDataOfOwnAssetProfile',
updateOrder: 'updateOrder', updateOrder: 'updateOrder',
updateOwnAccess: 'updateOwnAccess', updateOwnAccessToken: 'updateOwnAccessToken',
updatePlatform: 'updatePlatform', updatePlatform: 'updatePlatform',
updateTag: 'updateTag', updateTag: 'updateTag',
updateUserSettings: 'updateUserSettings', updateUserSettings: 'updateUserSettings',
@ -137,7 +137,7 @@ export function getPermissions(aRole: Role): string[] {
permissions.updateAuthDevice, permissions.updateAuthDevice,
permissions.updateMarketDataOfOwnAssetProfile, permissions.updateMarketDataOfOwnAssetProfile,
permissions.updateOrder, permissions.updateOrder,
permissions.updateOwnAccess, permissions.updateOwnAccessToken,
permissions.updateUserSettings, permissions.updateUserSettings,
permissions.updateViewMode permissions.updateViewMode
]; ];

7574
package-lock.json

File diff suppressed because it is too large
Loading…
Cancel
Save