Skip to content

Commit

Permalink
Merge branch 'master' into fix/email-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
BogoCvetkov committed Dec 11, 2023
2 parents 74e12ae + 3a41008 commit e74faff
Show file tree
Hide file tree
Showing 104 changed files with 2,456 additions and 226 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@

# Setup Development Environment (recommended)

To run and develop the module NodeJS 16 is required. In this section 2 ways of configuring a development environment are described.
To run and develop the module NodeJS 20 is required. In this section 2 ways of configuring a development environment are described.

## Installing the prerequisites

The following prerequisites are required in order to be able to run the project:

- [Node.js 16 LTS](https://nodejs.org/en/download/)
- [Node.js v20](https://nodejs.org/en/download/)
- [Yarn v3.x](https://yarnpkg.com/getting-started/install)
- [Docker](https://www.docker.com/get-started) with [Docker Compose](https://docs.docker.com/compose/) (to easily run a local database instance)

Expand Down
23 changes: 19 additions & 4 deletions apps/api/src/account/account.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CredentialRepresentation from '@keycloak/keycloak-admin-client/lib/defs/credentialRepresentation'
import { Body, Controller, Get, Put, Logger, Delete } from '@nestjs/common'
import { Body, Controller, Get, Put, Logger, Delete, Patch, Param } from '@nestjs/common'
import { RealmViewSupporters, ViewSupporters } from '@podkrepi-bg/podkrepi-types'
import { AuthenticatedUser, Public, RoleMatchingMode, Roles } from 'nest-keycloak-connect'

Expand Down Expand Up @@ -69,11 +69,11 @@ export class AccountController {
}

@Delete('me')
async disableUser(@AuthenticatedUser() user: KeycloakTokenParsed) {
async deleteUser(@AuthenticatedUser() user: KeycloakTokenParsed) {
try {
return await this.accountService.disableUser(user)
return await this.accountService.deleteUser(user)
} catch (err) {
Logger.error(`Failed to disable user with keycloakId ${user.sub}. Error is: ${err}`)
Logger.error(`Failed to delete user with keycloakId ${user.sub}. Error is: ${err}`)
throw err
}
}
Expand Down Expand Up @@ -114,4 +114,19 @@ export class AccountController {
adminRole() {
return { status: 'OK' }
}

@Patch(':keycloakId/status')
@Roles({
roles: [RealmViewSupporters.role, ViewSupporters.role],
mode: RoleMatchingMode.ANY,
})
async changeProfileStatus(
@Param('keycloakId') keycloakId: string,
@Body() data: UpdatePersonDto,
) {
return await this.accountService.changeProfileActivationStatus(
keycloakId,
!!data.profileEnabled,
)
}
}
10 changes: 9 additions & 1 deletion apps/api/src/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export class AccountService {
}

async disableUser(user: KeycloakTokenParsed) {
return await this.authService.disableUser(user.sub)
return await this.authService.changeEnabledStatus(user.sub, false)
}

async deleteUser(user: KeycloakTokenParsed) {
return await this.authService.deleteUser(user.sub)
}

async changeProfileActivationStatus(keycloakId: string, newStatus: boolean) {
return await this.authService.changeEnabledStatus(keycloakId, newStatus)
}
}
Loading

0 comments on commit e74faff

Please sign in to comment.