From 498ec0cf9a2c736950a82d8f4a5980eb80149ee8 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 6 Sep 2023 20:44:28 +0000 Subject: [PATCH] Merge SharpChat permission set into the Misuzu permission system directly. --- src/Perm.php | 78 ++++++++++++++++++++++++++++++- src/SharpChat/SharpChatPerms.php | 56 ---------------------- src/SharpChat/SharpChatRoutes.php | 3 +- 3 files changed, 78 insertions(+), 59 deletions(-) delete mode 100644 src/SharpChat/SharpChatPerms.php diff --git a/src/Perm.php b/src/Perm.php index 1d744c8..d7c4346 100644 --- a/src/Perm.php +++ b/src/Perm.php @@ -85,11 +85,37 @@ final class Perm { public const F_POST_DELETE_OWN = 0b00000_00000000_00000000_00000000_10000000_00000000_00000000; public const F_POST_DELETE_ANY = 0b00000_00000000_00000000_00000001_00000000_00000000_00000000; - public const INFO_FOR_USER = ['global', 'user']; + // CHAT ALLOCATION: + // 0bXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXMA_MMUMUUMT_ATATAMMM + // U -> Normal user permissions + // T -> Tenshi permissions + // M -> Moderator permissions + // A -> Administrator permissions + // no staircase here because it's a mess + public const C_USER_KICK = 0b00000_00000000_00000000_00000000_00000000_00000000_00000001; + public const C_USER_BAN = 0b00000_00000000_00000000_00000000_00000000_00000000_00000010; + //public const C_USER_SILENCE = 0b00000_00000000_00000000_00000000_00000000_00000000_00000100; // deprecated: silencing is no longer a thing + public const C_MESSAGE_BROADCAST = 0b00000_00000000_00000000_00000000_00000000_00000000_00001000; + public const C_NICK_SET_OWN = 0b00000_00000000_00000000_00000000_00000000_00000000_00010000; + public const C_NICK_SET_ANY = 0b00000_00000000_00000000_00000000_00000000_00000000_00100000; + public const C_CHANNEL_CREATE = 0b00000_00000000_00000000_00000000_00000000_00000000_01000000; + public const C_CHANNEL_SET_PERSIST = 0b00000_00000000_00000000_00000000_00000000_00000000_10000000; + public const C_CHANNEL_SET_PASSWORD = 0b00000_00000000_00000000_00000000_00000000_00000001_00000000; + public const C_CHANNEL_SET_MIN_RANK = 0b00000_00000000_00000000_00000000_00000000_00000010_00000000; + public const C_MESSAGE_SEND = 0b00000_00000000_00000000_00000000_00000000_00000100_00000000; + public const C_MESSAGE_DELETE_OWN = 0b00000_00000000_00000000_00000000_00000000_00001000_00000000; + public const C_MESSAGE_DELETE_ANY = 0b00000_00000000_00000000_00000000_00000000_00010000_00000000; + public const C_MESSAGE_EDIT_OWN = 0b00000_00000000_00000000_00000000_00000000_00100000_00000000; + public const C_MESSAGE_EDIT_ANY = 0b00000_00000000_00000000_00000000_00000000_01000000_00000000; + public const C_USER_VIEW_ADDR = 0b00000_00000000_00000000_00000000_00000000_10000000_00000000; + public const C_CHANNEL_DELETE = 0b00000_00000000_00000000_00000000_00000001_00000000_00000000; + public const C_CHANNEL_JOIN_ANY = 0b00000_00000000_00000000_00000000_00000010_00000000_00000000; + + public const INFO_FOR_USER = ['global', 'user', 'chat']; public const INFO_FOR_ROLE = self::INFO_FOR_USER; // just alias for now, no clue if this will ever desync public const INFO_FOR_FORUM_CATEGORY = ['forum']; - public const LISTS_FOR_USER = ['global:general', 'global:changelog', 'global:news', 'global:forum', 'global:comments', 'user:personal', 'user:manage']; + public const LISTS_FOR_USER = ['global:general', 'global:changelog', 'global:news', 'global:forum', 'global:comments', 'user:personal', 'user:manage', 'chat:general']; public const LISTS_FOR_ROLE = self::LISTS_FOR_USER; // idem public const LISTS_FOR_FORUM_CATEGORY = ['forum:category', 'forum:topic', 'forum:post']; @@ -213,6 +239,33 @@ final class Perm { self::F_POST_DELETE_ANY, ], ], + + 'chat:general' => [ + 'title' => 'Chat Permissions', + 'perms' => [ + 'chat', + self::C_MESSAGE_SEND, + self::C_MESSAGE_BROADCAST, + self::C_MESSAGE_EDIT_OWN, + self::C_MESSAGE_EDIT_ANY, + self::C_MESSAGE_DELETE_OWN, + self::C_MESSAGE_DELETE_ANY, + + self::C_NICK_SET_OWN, + self::C_NICK_SET_ANY, + + self::C_USER_KICK, + self::C_USER_BAN, + self::C_USER_VIEW_ADDR, + + self::C_CHANNEL_CREATE, + self::C_CHANNEL_SET_PERSIST, + self::C_CHANNEL_SET_PASSWORD, + self::C_CHANNEL_SET_MIN_RANK, + self::C_CHANNEL_JOIN_ANY, + self::C_CHANNEL_DELETE, + ], + ], ]; public const LABELS = [ @@ -286,6 +339,27 @@ final class Perm { self::F_POST_DELETE_OWN => 'Can delete own forum posts.', self::F_POST_DELETE_ANY => 'Can delete ANY forum post.', ], + + 'chat' => [ + self::C_USER_KICK => 'Can kick other users.', + self::C_USER_BAN => 'Can ban other users.', + //self::C_USER_SILENCE => 'Can silence other users.', + self::C_MESSAGE_BROADCAST => 'Can broadcast messages across all channels.', + self::C_NICK_SET_OWN => 'Can change own nickname.', + self::C_NICK_SET_ANY => 'Can change ANYONE\'s nickname.', + self::C_CHANNEL_CREATE => 'Can create channels.', + self::C_CHANNEL_SET_PERSIST => 'Can set channels to persist after all users leave it.', + self::C_CHANNEL_SET_PASSWORD => 'Can set passwords for own channel.', + self::C_CHANNEL_SET_MIN_RANK => 'Can set minimum requires rank to join channel.', + self::C_MESSAGE_SEND => 'Can send messages.', + self::C_MESSAGE_DELETE_OWN => 'Can delete own messages.', + self::C_MESSAGE_DELETE_ANY => 'Can delete ANY message.', + self::C_MESSAGE_EDIT_OWN => 'Can edit own messages.', + self::C_MESSAGE_EDIT_ANY => 'Can edit ANY message.', + self::C_USER_VIEW_ADDR => 'Can view IP addresses of other users.', + self::C_CHANNEL_DELETE => 'Can delete own channels.', + self::C_CHANNEL_JOIN_ANY => 'Can join any channel regardless of join requirements.', + ], ]; public static function label(string $category, int $permission): string { diff --git a/src/SharpChat/SharpChatPerms.php b/src/SharpChat/SharpChatPerms.php deleted file mode 100644 index d83699c..0000000 --- a/src/SharpChat/SharpChatPerms.php +++ /dev/null @@ -1,56 +0,0 @@ -getPermissions(['global', 'user'], $userInfo); - $convert = self::PERMS_DEFAULT; - - if($perms->user->check(Perm::U_USERS_MANAGE)) - $convert |= self::PERMS_MANAGE_USERS; - - if($perms->user->check(Perm::U_WARNINGS_MANAGE)) - $convert |= self::P_KICK_USER; - - if($perms->user->check(Perm::U_BANS_MANAGE)) - $convert |= self::P_BAN_USER; - - if($perms->user->check(Perm::U_PROFILE_BACKGROUND_CHANGE)) - $convert |= self::PERMS_CHANGE_BACKG; - - if($perms->global->check(Perm::G_FORUM_CATEGORIES_MANAGE)) - $convert |= self::PERMS_MANAGE_FORUM; - - return $convert; - } -} diff --git a/src/SharpChat/SharpChatRoutes.php b/src/SharpChat/SharpChatRoutes.php index 7c4a475..01688f0 100644 --- a/src/SharpChat/SharpChatRoutes.php +++ b/src/SharpChat/SharpChatRoutes.php @@ -249,6 +249,7 @@ final class SharpChatRoutes implements IRouteHandler { $this->usersCtx->getUsers()->recordUserActivity($userInfo, remoteAddr: $ipAddress); $userColour = $this->usersCtx->getUsers()->getUserColour($userInfo); $userRank = $this->usersCtx->getUsers()->getUserRank($userInfo); + $chatPerms = $this->perms->getPermissions('chat', $userInfo); return [ 'success' => true, @@ -257,7 +258,7 @@ final class SharpChatRoutes implements IRouteHandler { 'colour_raw' => Colour::toMisuzu($userColour), 'rank' => $userRank, 'hierarchy' => $userRank, - 'perms' => SharpChatPerms::convert($this->perms, $userInfo), + 'perms' => $chatPerms->getCalculated(), ]; }