|
|
@ -1,6 +1,12 @@ |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { CreateAccessDto, UpdateAccessDto } from '@ghostfolio/common/dtos'; |
|
|
import { CreateAccessDto, UpdateAccessDto } from '@ghostfolio/common/dtos'; |
|
|
import { Filter, PortfolioPosition } from '@ghostfolio/common/interfaces'; |
|
|
import { Filter, PortfolioPosition } from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
import { |
|
|
|
|
|
SCOPES_OF_READ_ACCESS, |
|
|
|
|
|
SCOPES_OF_READ_RESTRICTED_ACCESS, |
|
|
|
|
|
hasScope, |
|
|
|
|
|
scopes |
|
|
|
|
|
} from '@ghostfolio/common/scopes'; |
|
|
import { AccountWithPlatform } from '@ghostfolio/common/types'; |
|
|
import { AccountWithPlatform } from '@ghostfolio/common/types'; |
|
|
import { validateObjectForForm } from '@ghostfolio/common/utils'; |
|
|
import { validateObjectForForm } from '@ghostfolio/common/utils'; |
|
|
import { NotificationService } from '@ghostfolio/ui/notifications'; |
|
|
import { NotificationService } from '@ghostfolio/ui/notifications'; |
|
|
@ -40,7 +46,6 @@ import { |
|
|
import { MatFormFieldModule } from '@angular/material/form-field'; |
|
|
import { MatFormFieldModule } from '@angular/material/form-field'; |
|
|
import { MatInputModule } from '@angular/material/input'; |
|
|
import { MatInputModule } from '@angular/material/input'; |
|
|
import { MatSelectModule } from '@angular/material/select'; |
|
|
import { MatSelectModule } from '@angular/material/select'; |
|
|
import { AccessPermission } from '@prisma/client'; |
|
|
|
|
|
import { StatusCodes } from 'http-status-codes'; |
|
|
import { StatusCodes } from 'http-status-codes'; |
|
|
import { EMPTY, catchError } from 'rxjs'; |
|
|
import { EMPTY, catchError } from 'rxjs'; |
|
|
|
|
|
|
|
|
@ -111,10 +116,10 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
access?.grantee ?? null, |
|
|
access?.grantee ?? null, |
|
|
isPublic ? null : Validators.required |
|
|
isPublic ? null : Validators.required |
|
|
], |
|
|
], |
|
|
permissions: [ |
|
|
hasScopeToReadValues: hasScope( |
|
|
access?.permissions[0] ?? AccessPermission.READ_RESTRICTED, |
|
|
access?.scopes, |
|
|
Validators.required |
|
|
scopes.portfolioReadValues |
|
|
], |
|
|
), |
|
|
type: [ |
|
|
type: [ |
|
|
{ disabled: this.mode === 'update', value: access?.type ?? 'PRIVATE' }, |
|
|
{ disabled: this.mode === 'update', value: access?.type ?? 'PRIVATE' }, |
|
|
Validators.required |
|
|
Validators.required |
|
|
@ -139,7 +144,10 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
?.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
?.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((accessType) => { |
|
|
.subscribe((accessType) => { |
|
|
const granteeUserIdControl = this.accessForm.get('granteeUserId'); |
|
|
const granteeUserIdControl = this.accessForm.get('granteeUserId'); |
|
|
const permissionsControl = this.accessForm.get('permissions'); |
|
|
|
|
|
|
|
|
const hasScopeToReadValuesControl = this.accessForm.get( |
|
|
|
|
|
'hasScopeToReadValues' |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (accessType === 'PRIVATE') { |
|
|
if (accessType === 'PRIVATE') { |
|
|
granteeUserIdControl?.setValidators(Validators.required); |
|
|
granteeUserIdControl?.setValidators(Validators.required); |
|
|
@ -147,9 +155,9 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
} else { |
|
|
} else { |
|
|
granteeUserIdControl?.clearValidators(); |
|
|
granteeUserIdControl?.clearValidators(); |
|
|
granteeUserIdControl?.setValue(null); |
|
|
granteeUserIdControl?.setValue(null); |
|
|
permissionsControl?.setValue( |
|
|
|
|
|
access?.permissions[0] ?? AccessPermission.READ_RESTRICTED |
|
|
// A public access never exposes the monetary values
|
|
|
); |
|
|
hasScopeToReadValuesControl?.setValue(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
granteeUserIdControl?.updateValueAndValidity(); |
|
|
granteeUserIdControl?.updateValueAndValidity(); |
|
|
@ -178,6 +186,18 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* The dialog offers the read access only. The write scopes are not granted |
|
|
|
|
|
* here yet. |
|
|
|
|
|
*/ |
|
|
|
|
|
private buildScopes() { |
|
|
|
|
|
return [ |
|
|
|
|
|
...(this.accessForm.get('hasScopeToReadValues')?.value |
|
|
|
|
|
? SCOPES_OF_READ_ACCESS |
|
|
|
|
|
: SCOPES_OF_READ_RESTRICTED_ACCESS) |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async createAccess() { |
|
|
private async createAccess() { |
|
|
const filters = this.buildFilters(); |
|
|
const filters = this.buildFilters(); |
|
|
|
|
|
|
|
|
@ -185,7 +205,7 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
alias: this.accessForm.get('alias')?.value, |
|
|
alias: this.accessForm.get('alias')?.value, |
|
|
filters: filters.length > 0 ? filters : undefined, |
|
|
filters: filters.length > 0 ? filters : undefined, |
|
|
granteeUserId: this.accessForm.get('granteeUserId')?.value, |
|
|
granteeUserId: this.accessForm.get('granteeUserId')?.value, |
|
|
permissions: [this.accessForm.get('permissions')?.value] |
|
|
scopes: this.buildScopes() |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
@ -244,7 +264,7 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { |
|
|
filters: filters.length > 0 ? filters : undefined, |
|
|
filters: filters.length > 0 ? filters : undefined, |
|
|
granteeUserId: this.accessForm.get('granteeUserId')?.value, |
|
|
granteeUserId: this.accessForm.get('granteeUserId')?.value, |
|
|
id: accessId, |
|
|
id: accessId, |
|
|
permissions: [this.accessForm.get('permissions')?.value] |
|
|
scopes: this.buildScopes() |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|