|
@@ -106,6 +106,9 @@ decl_error! {
|
|
|
|
|
|
/// Contant uploading failed. Actor quota objects limit exceeded.
|
|
|
GlobalQuotaObjectsLimitExceeded,
|
|
|
+
|
|
|
+ /// Content uploading blocked.
|
|
|
+ ContentUploadingBlocked,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -260,6 +263,9 @@ decl_storage! {
|
|
|
|
|
|
/// Global quota.
|
|
|
pub GlobalQuota get(fn global_quota) config(): Quota;
|
|
|
+
|
|
|
+ /// If all new uploads blocked
|
|
|
+ pub UploadingBlocked get(fn uploading_blocked) config(): bool;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -270,7 +276,8 @@ decl_event! {
|
|
|
StorageProviderId = StorageProviderId<T>,
|
|
|
Content = Vec<ContentParameters<ContentId<T>, DataObjectTypeId<T>>>,
|
|
|
ContentId = ContentId<T>,
|
|
|
- QuotaLimit = u64
|
|
|
+ QuotaLimit = u64,
|
|
|
+ UploadingStatus = bool
|
|
|
{
|
|
|
/// Emits on adding of the content.
|
|
|
/// Params:
|
|
@@ -301,6 +308,11 @@ decl_event! {
|
|
|
/// - StorageObjectOwner enum.
|
|
|
/// - quota objects limit.
|
|
|
StorageObjectOwnerQuotaObjectsLimitUpdated(StorageObjectOwner, QuotaLimit),
|
|
|
+
|
|
|
+ /// Emits when the content uploading status update performed.
|
|
|
+ /// Params:
|
|
|
+ /// - UploadingStatus bool flag.
|
|
|
+ ContentUploadingStatusUpdated(UploadingStatus),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -324,10 +336,12 @@ decl_module! {
|
|
|
owner: StorageObjectOwner<MemberId<T>, ChannelId<T>, DAOId<T>>,
|
|
|
content: Vec<ContentParameters<ContentId<T>, DataObjectTypeId<T>>>
|
|
|
) {
|
|
|
-
|
|
|
+
|
|
|
// Ensure given origin can perform operation under specific storage object owner
|
|
|
Self::ensure_storage_object_owner_origin(origin, &owner)?;
|
|
|
|
|
|
+ Self::ensure_uploading_is_not_blocked()?;
|
|
|
+
|
|
|
Self::ensure_content_is_valid(&content)?;
|
|
|
|
|
|
let owner_quota = Self::get_quota(&owner);
|
|
@@ -440,6 +454,17 @@ decl_module! {
|
|
|
Self::deposit_event(RawEvent::ContentRejected(content_id, storage_provider_id));
|
|
|
}
|
|
|
|
|
|
+ /// Locks / unlocks content uploading
|
|
|
+ #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ fn update_content_uploading_status(origin, is_blocked: bool) {
|
|
|
+ <StorageWorkingGroup<T>>::ensure_origin_is_active_leader(origin)?;
|
|
|
+
|
|
|
+ // == MUTATION SAFE ==
|
|
|
+
|
|
|
+ <UploadingBlocked>::put(is_blocked);
|
|
|
+ Self::deposit_event(RawEvent::ContentUploadingStatusUpdated(is_blocked));
|
|
|
+ }
|
|
|
+
|
|
|
// Sudo methods
|
|
|
|
|
|
/// Removes the content id from the list of known content ids. Requires root privileges.
|
|
@@ -507,6 +532,15 @@ impl<T: Trait> Module<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Ensure content uploading is not blocked
|
|
|
+ fn ensure_uploading_is_not_blocked() -> DispatchResult {
|
|
|
+ ensure!(
|
|
|
+ !Self::uploading_blocked(),
|
|
|
+ Error::<T>::ContentUploadingBlocked
|
|
|
+ );
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
// Ensure owner quota constraints satisfied, returns total object length and total size voucher for this upload.
|
|
|
fn ensure_owner_quota_constraints_satisfied(
|
|
|
owner_quota: Quota,
|