Browse Source

Extend user account deletion to users without security token

pull/8093/head
Thomas Kaul 7 days ago
parent
commit
a8fa33f98d
  1. 1
      apps/api/src/app/user/user.controller.ts
  2. 3
      apps/api/src/app/user/user.service.ts
  3. 18
      apps/client/src/app/components/user-account-settings/user-account-settings.component.ts
  4. 2
      apps/client/src/app/components/user-account-settings/user-account-settings.html

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

@ -75,7 +75,6 @@ export class UserController {
public async deleteOwnUser( public async deleteOwnUser(
@Body() data: DeleteOwnUserDto @Body() data: DeleteOwnUserDto
): Promise<UserModel> { ): Promise<UserModel> {
// Only users of the anonymous provider have a security token
const user = const user =
this.request.user.provider === 'ANONYMOUS' this.request.user.provider === 'ANONYMOUS'
? await this.validateAccessToken(data.accessToken, this.request.user.id) ? await this.validateAccessToken(data.accessToken, this.request.user.id)

3
apps/api/src/app/user/user.service.ts

@ -439,9 +439,8 @@ export class UserService {
currentPermissions.push(permissions.enableSubscriptionInterstitial); currentPermissions.push(permissions.enableSubscriptionInterstitial);
} }
// Users without a security token (e.g. Google) can close their user
// account themselves only within a period after the registration
if ( if (
!hasRole(user, Role.DEMO) &&
user.provider !== 'ANONYMOUS' && user.provider !== 'ANONYMOUS' &&
isBefore( isBefore(
new Date(), new Date(),

18
apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

@ -277,14 +277,20 @@ export class GfUserAccountSettingsComponent implements OnInit {
this.notificationService.confirm({ this.notificationService.confirm({
confirmFn: () => { confirmFn: () => {
this.dataService this.dataService
.deleteOwnUser({ .deleteOwnUser(
accessToken: this.deleteOwnUserForm.controls.accessToken.value this.hasPermissionToUpdateOwnAccessToken
}) ? {
accessToken: this.deleteOwnUserForm.controls.accessToken.value
}
: {}
)
.pipe( .pipe(
catchError(() => { catchError(() => {
this.notificationService.alert({ if (this.hasPermissionToUpdateOwnAccessToken) {
title: $localize`Oops! Incorrect Security Token.` this.notificationService.alert({
}); title: $localize`Oops! Incorrect Security Token.`
});
}
return EMPTY; return EMPTY;
}), }),

2
apps/client/src/app/components/user-account-settings/user-account-settings.html

@ -366,7 +366,7 @@
Close Account Close Account
</button> </button>
</form> </form>
} @else if (hasPermissionToDeleteOwnUser) { } @else if (hasPermissionToDeleteOwnUser && !hasImpersonationId) {
<button <button
color="warn" color="warn"
i18n i18n

Loading…
Cancel
Save