From 78b7e1a61a32d769a57a180bf52726f9ae66f9c3 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 19 Sep 2024 09:59:06 -0400 Subject: [PATCH] fix User#addFlag and User#hasFlag --- .../cc/pulseapp/api/common/EnvironmentUtils.java | 1 + .../java/cc/pulseapp/api/model/user/User.java | 5 +++-- .../cc/pulseapp/api/model/user/UserFlag.java | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/pulseapp/api/common/EnvironmentUtils.java b/src/main/java/cc/pulseapp/api/common/EnvironmentUtils.java index ca18f30..bc02621 100644 --- a/src/main/java/cc/pulseapp/api/common/EnvironmentUtils.java +++ b/src/main/java/cc/pulseapp/api/common/EnvironmentUtils.java @@ -17,6 +17,7 @@ public final class EnvironmentUtils { * Is the app running in a "cloud" environment? */ @Getter private static final boolean cloud; + static { String appEnv = System.getenv("APP_ENV"); String cloudEnv = System.getenv("APP_CLOUD"); diff --git a/src/main/java/cc/pulseapp/api/model/user/User.java b/src/main/java/cc/pulseapp/api/model/user/User.java index accb7b3..871e8ee 100644 --- a/src/main/java/cc/pulseapp/api/model/user/User.java +++ b/src/main/java/cc/pulseapp/api/model/user/User.java @@ -75,7 +75,7 @@ public final class User { * @param flag the flag to add */ public void addFlag(@NonNull UserFlag flag) { - flags |= flag.ordinal(); + flags |= flag.bitwise(); } /** @@ -85,6 +85,7 @@ public final class User { * @return whether this user has the flag */ public boolean hasFlag(@NonNull UserFlag flag) { - return (flags & flag.ordinal()) != 0; + int bitwise = flag.bitwise(); + return (flags & bitwise) == bitwise; } } \ No newline at end of file diff --git a/src/main/java/cc/pulseapp/api/model/user/UserFlag.java b/src/main/java/cc/pulseapp/api/model/user/UserFlag.java index 0c32603..70d54e7 100644 --- a/src/main/java/cc/pulseapp/api/model/user/UserFlag.java +++ b/src/main/java/cc/pulseapp/api/model/user/UserFlag.java @@ -11,6 +11,11 @@ public enum UserFlag { */ DISABLED, + /** + * The user's email has been verified. + */ + EMAIL_VERIFIED, + /** * The user completed the onboarding process. */ @@ -24,5 +29,14 @@ public enum UserFlag { /** * The user is an administrator. */ - ADMINISTRATOR + ADMINISTRATOR; + + /** + * Get the bitwise value of this flag. + * + * @return the bitwise value + */ + public int bitwise() { + return 1 << ordinal(); + } } \ No newline at end of file