1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::dispatch::{DispatchError, DispatchResult};
use pallet_permissions::{
SpacePermission,
SpacePermissions,
SpacePermissionsContext
};
use pallet_utils::{SpaceId, User};
pub mod moderation;
pub struct SpaceForRoles<AccountId> {
pub owner: AccountId,
pub permissions: Option<SpacePermissions>,
}
pub trait SpaceForRolesProvider {
type AccountId;
fn get_space(id: SpaceId) -> Result<SpaceForRoles<Self::AccountId>, DispatchError>;
}
pub trait SpaceFollowsProvider {
type AccountId;
fn is_space_follower(account: Self::AccountId, space_id: SpaceId) -> bool;
}
pub trait PermissionChecker {
type AccountId;
fn ensure_user_has_space_permission(
user: User<Self::AccountId>,
ctx: SpacePermissionsContext,
permission: SpacePermission,
error: DispatchError,
) -> DispatchResult;
fn ensure_account_has_space_permission(
account: Self::AccountId,
ctx: SpacePermissionsContext,
permission: SpacePermission,
error: DispatchError,
) -> DispatchResult {
Self::ensure_user_has_space_permission(
User::Account(account),
ctx,
permission,
error
)
}
}