versioned_store_permissions.rs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use crate::{AccountId, Runtime};
  2. use frame_support::{StorageMap, StorageValue};
  3. // Credential Checker that gives the sudo key holder all credentials
  4. pub struct SudoKeyHasAllCredentials {}
  5. impl versioned_store_permissions::CredentialChecker<Runtime> for SudoKeyHasAllCredentials {
  6. fn account_has_credential(
  7. account: &AccountId,
  8. _credential: <Runtime as versioned_store_permissions::Trait>::Credential,
  9. ) -> bool {
  10. <pallet_sudo::Module<Runtime>>::key() == *account
  11. }
  12. }
  13. // Allow sudo key holder permission to create classes
  14. pub struct SudoKeyCanCreateClasses {}
  15. impl versioned_store_permissions::CreateClassPermissionsChecker<Runtime>
  16. for SudoKeyCanCreateClasses
  17. {
  18. fn account_can_create_class_permissions(account: &AccountId) -> bool {
  19. <pallet_sudo::Module<Runtime>>::key() == *account
  20. }
  21. }
  22. pub struct ContentLeadOrSudoKeyCanCreateClasses {}
  23. impl versioned_store_permissions::CreateClassPermissionsChecker<Runtime>
  24. for ContentLeadOrSudoKeyCanCreateClasses
  25. {
  26. fn account_can_create_class_permissions(account: &AccountId) -> bool {
  27. ContentLeadCanCreateClasses::account_can_create_class_permissions(account)
  28. || SudoKeyCanCreateClasses::account_can_create_class_permissions(account)
  29. }
  30. }
  31. // Allow content working group lead to create classes in content directory
  32. pub struct ContentLeadCanCreateClasses {}
  33. impl versioned_store_permissions::CreateClassPermissionsChecker<Runtime>
  34. for ContentLeadCanCreateClasses
  35. {
  36. fn account_can_create_class_permissions(account: &AccountId) -> bool {
  37. // get current lead id
  38. let maybe_current_lead_id = content_working_group::CurrentLeadId::<Runtime>::get();
  39. if let Some(lead_id) = maybe_current_lead_id {
  40. let lead = content_working_group::LeadById::<Runtime>::get(lead_id);
  41. lead.role_account == *account
  42. } else {
  43. false
  44. }
  45. }
  46. }