use super::*;
use frame_support::pallet_prelude::*;
pub type CID = BoundedVec<u8, ConstU32<100>>;
pub type PublicKey = [u8; 32];
pub type UserId = [u8; 32];
pub type DocName<T> = BoundedVec<u8, <T as Config>::DocNameMaxLen>;
pub type DocDesc<T> = BoundedVec<u8, <T as Config>::DocDescMaxLen>;
pub type GroupName<T> = BoundedVec<u8, <T as Config>::GroupNameMaxLen>;
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct Vault<T: Config> {
pub cid: CID,
pub owner: T::AccountId,
}
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct OwnedDoc<T: Config> {
pub cid: CID,
pub name: DocName<T>,
pub description: DocDesc<T>,
pub owner: T::AccountId,
}
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct SharedDoc<T: Config> {
pub cid: CID,
pub name: DocName<T>,
pub description: DocDesc<T>,
pub from: T::AccountId,
pub to: T::AccountId,
}
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub enum GroupRole {
Admin,
#[default]
Member,
Owner,
}
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct Group<T: Config> {
pub group: T::AccountId,
pub creator: T::AccountId,
pub name: GroupName<T>,
}
#[derive(
CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen, PartialEq,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct GroupMember<T: Config> {
pub cid: CID,
pub group: T::AccountId,
pub member: T::AccountId,
pub authorizer: T::AccountId,
pub role: GroupRole,
}
impl<T: Config> GroupMember<T> {
pub fn can_add_group_member(&self) -> bool {
self.role == GroupRole::Admin || self.role == GroupRole::Owner
}
pub fn can_remove_group_member(&self, group_member: &GroupMember<T>) -> bool {
group_member.role != GroupRole::Owner
&& (self.role == GroupRole::Owner
|| (self.role == GroupRole::Admin && group_member.authorizer == self.member))
}
}