rive_models/
permission.rs

1use serde::{Deserialize, Serialize};
2
3bitflags::bitflags! {
4    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
5    /// Permission
6    pub struct Permission: u64 {
7        // * Generic permissions
8        /// Manage the channel or channels on the server
9        const ManageChannel = 1 << 0;
10        /// Manage the server
11        const ManageServer = 1 << 1;
12        /// Manage permissions on servers or channels
13        const ManagePermissions = 1 << 2;
14        /// Manage roles on server
15        const ManageRole = 1 << 3;
16        /// Manage server customisation (includes emoji)
17        const ManageCustomisation = 1 << 4;
18
19        // % 1 bits reserved
20
21        // * Member permissions
22        /// Kick other members below their ranking
23        const KickMembers = 1 << 6;
24        /// Ban other members below their ranking
25        const BanMembers = 1 << 7;
26        /// Timeout other members below their ranking
27        const TimeoutMembers = 1 << 8;
28        /// Assign roles to members below their ranking
29        const AssignRoles = 1 << 9;
30        /// Change own nickname
31        const ChangeNickname = 1 << 10;
32        /// Change or remove other's nicknames below their ranking
33        const ManageNicknames = 1 << 11;
34        /// Change own avatar
35        const ChangeAvatar = 1 << 12;
36        /// Remove other's avatars below their ranking
37        const RemoveAvatars = 1 << 13;
38
39        // % 7 bits reserved
40
41        // * Channel permissions
42        /// View a channel
43        const ViewChannel = 1 << 20;
44        /// Read a channel's past message history
45        const ReadMessageHistory = 1 << 21;
46        /// Send a message in a channel
47        const SendMessage = 1 << 22;
48        /// Delete messages in a channel
49        const ManageMessages = 1 << 23;
50        /// Manage webhook entries on a channel
51        const ManageWebhooks = 1 << 24;
52        /// Create invites to this channel
53        const InviteOthers = 1 << 25;
54        /// Send embedded content in this channel
55        const SendEmbeds = 1 << 26;
56        /// Send attachments and media in this channel
57        const UploadFiles = 1 << 27;
58        /// Masquerade messages using custom nickname and avatar
59        const Masquerade = 1 << 28;
60        /// React to messages with emojis
61        const React = 1 << 29;
62
63        // * Voice permissions
64        /// Connect to a voice channel
65        const Connect = 1 << 30;
66        /// Speak in a voice call
67        const Speak = 1 << 31;
68        /// Share video in a voice call
69        const Video = 1 << 32;
70        /// Mute other members with lower ranking in a voice call
71        const MuteMembers = 1 << 33;
72        /// Deafen other members with lower ranking in a voice call
73        const DeafenMembers = 1 << 34;
74        /// Move members between voice channels
75        const MoveMembers = 1 << 35;
76
77        // * Misc. permissions
78        // % Bits 36 to 52: free area
79        // % Bits 53 to 64: do not use
80    }
81}
82crate::impl_serde_bitflags!(Permission);
83
84bitflags::bitflags! {
85    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
86    /// User permission
87    pub struct UserPermission: u64 {
88        const Access = 1 << 0;
89        const ViewProfile = 1 << 1;
90        const SendMessage = 1 << 2;
91        const Invite = 1 << 3;
92    }
93}
94crate::impl_serde_bitflags!(UserPermission);
95
96/// Representation of a single permission override
97/// as it appears on models and in the database
98#[derive(Serialize, Deserialize, Debug, Clone, Default)]
99pub struct OverrideField {
100    /// Allow bit flags
101    a: Permission,
102    /// Disallow bit flags
103    d: Permission,
104}
105
106/// Representation of a single permission override
107#[derive(Serialize, Deserialize, Debug, Clone, Default)]
108pub struct Override {
109    /// Allow bit flags
110    allow: Permission,
111    /// Disallow bit flags
112    deny: Permission,
113}