From ee280786eed5b1c4ec7428b02f0357781b666615 Mon Sep 17 00:00:00 2001 From: Denis Natusch Date: Wed, 15 Nov 2023 01:44:12 +0100 Subject: [PATCH] Make only customers able to delete their own account --- src/main/java/catering/users/User.java | 5 +++++ src/main/resources/templates/profile.html | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/catering/users/User.java b/src/main/java/catering/users/User.java index 870986c..2d1bf24 100644 --- a/src/main/java/catering/users/User.java +++ b/src/main/java/catering/users/User.java @@ -5,6 +5,7 @@ import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.OneToOne; +import org.salespointframework.useraccount.Role; import org.salespointframework.useraccount.UserAccount; import org.salespointframework.core.AbstractAggregateRoot; @@ -63,6 +64,10 @@ public class User extends AbstractAggregateRoot { return userAccount.isEnabled(); } + public boolean hasRole(String role) { + return userAccount.getRoles().stream().toList().contains(Role.of(role)); + } + @Embeddable public static final class UserIdentifier implements Identifier, Serializable { diff --git a/src/main/resources/templates/profile.html b/src/main/resources/templates/profile.html index 99ebf19..9f22da7 100644 --- a/src/main/resources/templates/profile.html +++ b/src/main/resources/templates/profile.html @@ -35,7 +35,7 @@