desmos_bindings/subspaces/
types.rs

1//! Contains the types definitions of x/subspaces.
2
3pub use crate::proto::desmos::subspaces::v3::*;
4
5use crate::cosmos_types::Any;
6
7/// Represents the permission to perform operations inside the subspace.
8pub enum Permission {
9    /// Allows to change the information of the subspace.
10    EditSubspace,
11
12    /// Allows users to delete the subspace.
13    DeleteSubspace,
14
15    /// Allows users to manage a subspace sections.
16    ManageSections,
17
18    /// Allows users to manage user groups and members.
19    ManageGroups,
20
21    /// Allows users to set other users' permissions (except [`Permission::`SetPermissions`]).
22    /// This includes managing user groups and the associated permissions.
23    SetPermissions,
24
25    /// Allows to do everything.
26    /// This should usually be reserved only to the owner (which has it by default).
27    Everything,
28
29    /// Identifies users that can create content inside the subspace.
30    Write,
31
32    /// Allows users to interact with content inside the subspace (eg. polls).
33    InteractWithContent,
34
35    /// Allows users to edit their own content inside the subspace.
36    EditOwnContent,
37
38    /// Allows users to moderate other user's content.
39    ModerateContent,
40}
41
42impl Into<String> for Permission {
43    fn into(self) -> String {
44        match self {
45            Permission::EditSubspace => "EDIT_SUBSPACE".into(),
46
47            Permission::DeleteSubspace => "DELETE_SUBSPACE".into(),
48
49            Permission::ManageSections => "MANAGE_SECTIONS".into(),
50
51            Permission::ManageGroups => "MANAGE_GROUPS".into(),
52
53            Permission::SetPermissions => "SET_PERMISSIONS".into(),
54
55            Permission::Everything => "EVERYTHING".into(),
56
57            Permission::Write => "WRITE_CONTENT".into(),
58
59            Permission::InteractWithContent => "INTERACT_WITH_CONTENT".into(),
60
61            Permission::EditOwnContent => "EDIT_OWN_CONTENT".into(),
62
63            Permission::ModerateContent => "MODERATE_CONTENT".into(),
64        }
65    }
66}
67
68/// Represents a generic grantee.
69#[derive(Clone)]
70pub enum Grantee {
71    /// Represents a user grantee.
72    UserGrantee(UserGrantee),
73
74    /// Represents a group grantee.
75    GroupGrantee(GroupGrantee),
76}
77
78impl Grantee {
79    /// Creates a new [`Grantee::UserGrantee`] instance
80    pub fn user_grantee(user: impl Into<String>) -> Self {
81        Self::UserGrantee(UserGrantee { user: user.into() })
82    }
83
84    /// Creates a new [`Grantee::GroupGrantee`] instance
85    pub fn group_grantee(group_id: u32) -> Self {
86        Self::GroupGrantee(GroupGrantee { group_id })
87    }
88}
89
90impl Into<Any> for Grantee {
91    fn into(self) -> Any {
92        match self {
93            Grantee::UserGrantee(grantee) => grantee.into(),
94            Grantee::GroupGrantee(grantee) => grantee.into(),
95        }
96    }
97}