Skip to content

Commit

Permalink
feat: add demo user role
Browse files Browse the repository at this point in the history
  • Loading branch information
steve192 committed Mar 24, 2024
1 parent 9629375 commit 3098602
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sterul.opencookbookapiserver.controllers.responses.UserLoginResponse;
import com.sterul.opencookbookapiserver.entities.RefreshToken;
import com.sterul.opencookbookapiserver.entities.account.CookpalUser;
import com.sterul.opencookbookapiserver.entities.account.Role;
import com.sterul.opencookbookapiserver.services.EmailService;
import com.sterul.opencookbookapiserver.services.RefreshTokenService;
import com.sterul.opencookbookapiserver.services.UserDetailsServiceImpl;
Expand Down Expand Up @@ -207,8 +208,13 @@ public UserInfoResponse getOwnUserInfo() {

@Operation(summary = "Delete authenticated user account")
@DeleteMapping("/self")
public void deleteOwnUser() {
userService.deleteUser(getLoggedInUser());
public ResponseEntity deleteOwnUser() {
var user = getLoggedInUser();
if (Role.DEMO.equals(user.getRoles())) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
userService.deleteUser(user);
return ResponseEntity.ok().build();
}

@Operation(summary = "Generate a JWT token from a refresh token", description = "The JWT token is used to authenticate against all apis using the \"Authentication: Bearer < token >\" header field")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public enum Role {
ADMIN,
DEMO
}
6 changes: 6 additions & 0 deletions src/main/resources/db/migration/V6__.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE IF EXISTS public.cookpal_user
DROP CONSTRAINT cookpal_user_roles_check;


ALTER TABLE IF EXISTS public.cookpal_user
ADD CONSTRAINT cookpal_user_roles_check CHECK (roles::text = ANY (ARRAY['ADMIN'::character varying, 'DEMO'::character varying]::text[]));

0 comments on commit 3098602

Please sign in to comment.