spring-boot-blog-application icon indicating copy to clipboard operation
spring-boot-blog-application copied to clipboard

Can't write more than one blogpost & only delete when the user is admin

Open thiemt-armando opened this issue 1 year ago • 1 comments

Hello,

I have got this problem where I can create only ONE blog entry and then an error is thrown on the "posts/new/" page the moment I want to create a new one. And one can only delete entries when the user is admin. Also to be mentioned: The Blog entry in the database is stored even when it was deleted on the FrontEnd.

thiemt-armando avatar Sep 06 '23 08:09 thiemt-armando

Hmm that first issue should be already addressed if you pull the latest @thiemt-armando (my apologies for not seeing this until now)

Yes, in the PostController notice how the delete mapping is guarded with a PreAuthorize with a role. I wanted to have the restriction where ONLY accounts with the ROLE_ADMIN role could delete a post. Feel free to change that on your own setup!

@GetMapping("/posts/{id}/delete")
@PreAuthorize("hasRole('ROLE_ADMIN')")

erikyuzwa avatar Oct 29 '23 21:10 erikyuzwa