mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Make only customers able to delete their own account
This commit is contained in:
parent
cbb9710371
commit
9eeb25a281
|
@ -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<UserIdentifier> {
|
|||
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 {
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<div class="horizontal_center">
|
||||
<button class="danger_zone" th:text="#{profile.edit}" type="submit"></button>
|
||||
<a th:href="@{/profile/disable}">
|
||||
<button class="danger_zone" th:text="#{profile.delete}" type="button"></button>
|
||||
<button th:if="${user.hasRole('CUSTOMER')}" class="danger_zone" th:text="#{profile.delete}" type="button"></button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue