aboutsummaryrefslogtreecommitdiff
path: root/back-end/src/RoleHelpers.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-02-25 01:11:06 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-02-25 01:11:06 -0500
commitbd3a7a25792b837c5f28c7580adf132abc6f35e7 (patch)
tree2a3ec046f8f76f115e648f2bc6d1576cfa0a6c6f /back-end/src/RoleHelpers.cs
parent52645b724834e669788a45edb9d135f243432540 (diff)
Squashed commit of the following:
commit 069f81fc3c87c437eceff756ddca7a4c1b58044d Author: vnugent <public@vaughnnugent.com> Date: Sat Feb 24 22:33:34 2024 -0500 feat: #3 setup mode, admin signup, fixes, and contianerize! commit 97ffede9eb312fca0257afa06969d47a12703f3b Author: vnugent <public@vaughnnugent.com> Date: Mon Feb 19 22:26:03 2024 -0500 feat: new account setup and invitation links commit 1c8f59bc0a1b25ce5013b0f1fc7fa73c0de415d6 Author: vnugent <public@vaughnnugent.com> Date: Thu Feb 15 16:49:59 2024 -0500 feat: update packages, drag/drop link, and fix some button padding
Diffstat (limited to 'back-end/src/RoleHelpers.cs')
-rw-r--r--back-end/src/RoleHelpers.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/back-end/src/RoleHelpers.cs b/back-end/src/RoleHelpers.cs
new file mode 100644
index 0000000..a49d72a
--- /dev/null
+++ b/back-end/src/RoleHelpers.cs
@@ -0,0 +1,42 @@
+// Copyright (C) 2024 Vaughn Nugent
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+using VNLib.Plugins.Essentials.Accounts;
+using VNLib.Plugins.Essentials.Users;
+using VNLib.Plugins.Essentials.Sessions;
+
+namespace SimpleBookmark
+{
+ internal static class RoleHelpers
+ {
+ public const ulong CanAddUserRoleOption = 1 << AccountUtil.OPTIONS_MSK_OFFSET;
+
+ /// <summary>
+ /// A minium user role with read/write/delete access to their own bookmarks.
+ /// </summary>
+ public const ulong MinUserRole = AccountUtil.MINIMUM_LEVEL | AccountUtil.ALLFILE_MSK;
+
+ public static bool CanAddUser(this IUser user) => (user.Privileges & CanAddUserRoleOption) != 0;
+
+ public static bool CanAddUser(this ref readonly SessionInfo session) => (session.Privilages & CanAddUserRoleOption) != 0;
+
+ /// <summary>
+ /// Adds the add-user role to the given privileges for a user.
+ /// </summary>
+ /// <param name="privs"></param>
+ /// <returns>The modified privilege level</returns>
+ public static ulong WithAddUserRole(ulong privs) => privs | CanAddUserRoleOption;
+ }
+}