Browse Source
Task/refactor canDeleteUser() helper (#7324)
Refactor canDeleteUser()
pull/7148/head^2
Thomas Kaul
6 hours ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
30 additions and
3 deletions
-
apps/client/src/app/components/admin-users/admin-users.component.ts
-
apps/client/src/app/components/admin-users/admin-users.html
-
apps/client/src/app/components/user-detail-dialog/user-detail-dialog.component.ts
-
apps/client/src/app/components/user-detail-dialog/user-detail-dialog.html
-
libs/common/src/lib/helper.ts
|
|
|
@ -8,6 +8,7 @@ import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
|
import { DEFAULT_LOCALE, DEFAULT_PAGE_SIZE } from '@ghostfolio/common/config'; |
|
|
|
import { ConfirmationDialogType } from '@ghostfolio/common/enums'; |
|
|
|
import { |
|
|
|
canDeleteUser, |
|
|
|
getCountryName, |
|
|
|
getDateFnsLocale, |
|
|
|
getDateFormatString, |
|
|
|
@ -91,6 +92,7 @@ export class GfAdminUsersComponent implements OnInit { |
|
|
|
>(); |
|
|
|
protected defaultDateFormat: string; |
|
|
|
protected displayedColumns: string[] = []; |
|
|
|
protected readonly canDeleteUser = canDeleteUser; |
|
|
|
protected readonly getCountryName = getCountryName; |
|
|
|
protected readonly getEmojiFlag = getEmojiFlag; |
|
|
|
protected hasPermissionForSubscription: boolean; |
|
|
|
|
|
|
|
@ -241,7 +241,12 @@ |
|
|
|
<hr class="m-0" /> |
|
|
|
<button |
|
|
|
mat-menu-item |
|
|
|
[disabled]="element.id === user?.id" |
|
|
|
[disabled]=" |
|
|
|
!canDeleteUser({ |
|
|
|
currentUserId: user?.id, |
|
|
|
userId: element.id |
|
|
|
}) |
|
|
|
" |
|
|
|
(click)="onDeleteUser(element.id)" |
|
|
|
> |
|
|
|
<span class="align-items-center d-flex"> |
|
|
|
|
|
|
|
@ -1,4 +1,8 @@ |
|
|
|
import { getCountryName, getSum } from '@ghostfolio/common/helper'; |
|
|
|
import { |
|
|
|
canDeleteUser, |
|
|
|
getCountryName, |
|
|
|
getSum |
|
|
|
} from '@ghostfolio/common/helper'; |
|
|
|
import { AdminUserResponse } from '@ghostfolio/common/interfaces'; |
|
|
|
import { AdminService, DataService } from '@ghostfolio/ui/services'; |
|
|
|
import { GfValueComponent } from '@ghostfolio/ui/value'; |
|
|
|
@ -50,6 +54,7 @@ import { |
|
|
|
}) |
|
|
|
export class GfUserDetailDialogComponent implements OnInit { |
|
|
|
protected readonly baseCurrency: string; |
|
|
|
protected readonly canDeleteUser = canDeleteUser; |
|
|
|
protected readonly getCountryName = getCountryName; |
|
|
|
protected readonly subscriptionsDataSource = |
|
|
|
new MatTableDataSource<Subscription>(); |
|
|
|
|
|
|
|
@ -16,7 +16,12 @@ |
|
|
|
<button |
|
|
|
mat-menu-item |
|
|
|
type="button" |
|
|
|
[disabled]="this.data.currentUserId === this.data.userId" |
|
|
|
[disabled]=" |
|
|
|
!canDeleteUser({ |
|
|
|
currentUserId: data.currentUserId, |
|
|
|
userId: data.userId |
|
|
|
}) |
|
|
|
" |
|
|
|
(click)="deleteUser()" |
|
|
|
> |
|
|
|
<ng-container i18n>Delete</ng-container> |
|
|
|
|
|
|
|
@ -163,6 +163,16 @@ export function canDeleteAssetProfile({ |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
export function canDeleteUser({ |
|
|
|
currentUserId, |
|
|
|
userId |
|
|
|
}: { |
|
|
|
currentUserId: string; |
|
|
|
userId: string; |
|
|
|
}): boolean { |
|
|
|
return currentUserId !== userId; |
|
|
|
} |
|
|
|
|
|
|
|
export function capitalize(aString: string) { |
|
|
|
return aString.charAt(0).toUpperCase() + aString.slice(1).toLowerCase(); |
|
|
|
} |
|
|
|
|