Browse Source

Merge pull request #2215 from mnaamani/content-directory/no-deletion

Content directory/no deletion
Bedeho Mender 4 years ago
parent
commit
52d97089ff

+ 0 - 3
runtime-modules/content/src/errors.rs

@@ -58,9 +58,6 @@ decl_error! {
         /// Channel does not exist
         ChannelDoesNotExist,
 
-        /// Channel must have been deleted
-        ChannelMustNotExist,
-
         /// Video does not exist
         VideoDoesNotExist,
 

+ 1 - 129
runtime-modules/content/src/lib.rs

@@ -538,33 +538,6 @@ decl_module! {
             Self::deposit_event(RawEvent::CuratorGroupCreated(curator_group_id));
         }
 
-        /// Remove curator group under given `curator_group_id` from runtime storage
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn delete_curator_group(
-            origin,
-            curator_group_id: T::CuratorGroupId,
-        ) {
-
-            // Ensure given origin is lead
-            ensure_is_lead::<T>(origin)?;
-
-            // Ensure CuratorGroup under given curator_group_id exists
-            let curator_group = Self::ensure_curator_group_exists(&curator_group_id)?;
-
-            // We should previously ensure that curator_group  owns no channels to be able to remove it
-            curator_group.ensure_curator_group_owns_no_channels()?;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            // Remove curator group under given curator group id from runtime storage
-            <CuratorGroupById<T>>::remove(curator_group_id);
-
-            // Trigger event
-            Self::deposit_event(RawEvent::CuratorGroupDeleted(curator_group_id));
-        }
-
         /// Set `is_active` status for curator group under given `curator_group_id`
         #[weight = 10_000_000] // TODO: adjust weight
         pub fn set_curator_group_status(
@@ -695,7 +668,7 @@ decl_module! {
             NextChannelId::<T>::mutate(|id| *id += T::ChannelId::one());
 
             let channel: Channel<T> = ChannelRecord {
-                owner: channel_owner.clone(),
+                owner: channel_owner,
                 videos: vec![],
                 playlists: vec![],
                 series: vec![],
@@ -704,10 +677,6 @@ decl_module! {
             };
             ChannelById::<T>::insert(channel_id, channel.clone());
 
-            if let ChannelOwner::CuratorGroup(curator_group_id) = channel_owner {
-                Self::increment_number_of_channels_owned_by_curator_group(curator_group_id);
-            }
-
             Self::deposit_event(RawEvent::ChannelCreated(actor, channel_id, channel, params));
         }
 
@@ -772,52 +741,6 @@ decl_module! {
             Self::deposit_event(RawEvent::ChannelUpdated(actor, channel_id, channel, params));
         }
 
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn delete_channel(
-            origin,
-            actor: ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
-            channel_id: T::ChannelId,
-        ) {
-            // check that channel exists
-            let channel = Self::ensure_channel_exists(&channel_id)?;
-
-            ensure_actor_authorized_update_channel_and_videos::<T>(
-                origin,
-                &actor,
-                &channel.owner,
-            )?;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            channel.videos.iter().for_each(|id| {
-                VideoById::<T>::remove(id);
-                Self::deposit_event(RawEvent::VideoDeleted(actor, *id));
-            });
-
-            channel.playlists.iter().for_each(|id| {
-                PlaylistById::<T>::remove(id);
-                Self::deposit_event(RawEvent::PlaylistDeleted(actor, *id));
-            });
-
-            channel.series.iter().for_each(|id| {
-                SeriesById::<T>::remove(id);
-                Self::deposit_event(RawEvent::SeriesDeleted(actor, *id));
-            });
-
-            // If the channel was owned by a curator group, decrement counter
-            if let ChannelOwner::CuratorGroup(curator_group_id) = channel.owner {
-                Self::decrement_number_of_channels_owned_by_curator_group(curator_group_id);
-            }
-
-            // TODO: Remove any channel transfer requests and refund requester
-            // Self::terminate_channel_transfer_requests(channel_id)
-            // Self::deposit_event(RawEvent::ChannelOwnershipTransferRequestCancelled());
-
-            Self::deposit_event(RawEvent::ChannelDeleted(actor, channel_id));
-        }
-
         /// Remove assets of a channel from storage
         #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_channel_assets(
@@ -846,41 +769,6 @@ decl_module! {
             Self::deposit_event(RawEvent::ChannelAssetsRemoved(actor, channel_id, assets));
         }
 
-        // The content directory doesn't track individual content ids of assets uploaded for a channel.
-        // A channel owner can manage their storage usage with remove_channel_assets(). However when they choose
-        // to delete their channel they may leave behind some assets if not explicitly removed.
-        // So the 'lead' can and should occasionally dispatch this call to cleanup and recover storage capacity of
-        // deleted channels.
-        /// Lead utility to remove assets of a deleted channel from storage
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn remove_deleted_channel_assets(
-            origin,
-            actor: ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
-            channel_id: T::ChannelId,
-            assets: Vec<ContentId<T>>,
-        ) {
-            ensure_actor_authorized_to_delete_stale_assets::<T>(
-                origin,
-                &actor
-            )?;
-
-            // Ensure channel does not exist
-            ensure!(
-                !ChannelById::<T>::contains_key(channel_id),
-                Error::<T>::ChannelMustNotExist
-            );
-
-            let object_owner = StorageObjectOwner::<T>::Channel(channel_id);
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            T::StorageSystem::atomically_remove_content(&object_owner, &assets)?;
-
-            Self::deposit_event(RawEvent::ChannelAssetsRemoved(actor, channel_id, assets));
-        }
-
         #[weight = 10_000_000] // TODO: adjust weight
         pub fn censor_channel(
             origin,
@@ -1423,20 +1311,6 @@ decl_module! {
 }
 
 impl<T: Trait> Module<T> {
-    /// Increment number of channels, owned by curator group
-    fn increment_number_of_channels_owned_by_curator_group(curator_group_id: T::CuratorGroupId) {
-        <CuratorGroupById<T>>::mutate(curator_group_id, |curator_group| {
-            curator_group.increment_number_of_channels_owned_count();
-        });
-    }
-
-    /// Decrement number of channels, owned by curator group
-    fn decrement_number_of_channels_owned_by_curator_group(curator_group_id: T::CuratorGroupId) {
-        <CuratorGroupById<T>>::mutate(curator_group_id, |curator_group| {
-            curator_group.decrement_number_of_channels_owned_count();
-        });
-    }
-
     /// Ensure `CuratorGroup` under given id exists
     fn ensure_curator_group_under_given_id_exists(
         curator_group_id: &T::CuratorGroupId,
@@ -1579,7 +1453,6 @@ decl_event!(
     {
         // Curators
         CuratorGroupCreated(CuratorGroupId),
-        CuratorGroupDeleted(CuratorGroupId),
         CuratorGroupStatusSet(CuratorGroupId, bool /* active status */),
         CuratorAdded(CuratorGroupId, CuratorId),
         CuratorRemoved(CuratorGroupId, CuratorId),
@@ -1597,7 +1470,6 @@ decl_event!(
             Channel,
             ChannelUpdateParameters<ContentParameters, AccountId>,
         ),
-        ChannelDeleted(ContentActor, ChannelId),
         ChannelAssetsRemoved(ContentActor, ChannelId, Vec<ContentId>),
 
         ChannelCensored(ContentActor, ChannelId, Vec<u8> /* rationale */),

+ 0 - 31
runtime-modules/content/src/permissions/curator_group.rs

@@ -9,13 +9,6 @@ pub struct CuratorGroup<T: Trait> {
 
     /// When `false`, curator in a given group is forbidden to act
     active: bool,
-
-    /// Used to count the number of Channels, given curator group owns
-    number_of_channels_owned: u32,
-    // IDEA: Give explicit permissions to:
-    // create new categories
-    // restrict censoring to subset of categories
-    // create curator group channels
 }
 
 impl<T: Trait> Default for CuratorGroup<T> {
@@ -24,7 +17,6 @@ impl<T: Trait> Default for CuratorGroup<T> {
             curators: BTreeSet::new(),
             // default curator group status right after creation
             active: false,
-            number_of_channels_owned: 0,
         }
     }
 }
@@ -40,10 +32,6 @@ impl<T: Trait> CuratorGroup<T> {
         self.active
     }
 
-    pub fn get_number_of_channels_owned(&self) -> u32 {
-        self.number_of_channels_owned
-    }
-
     /// Set `CuratorGroup` status as provided
     pub fn set_status(&mut self, is_active: bool) {
         self.active = is_active
@@ -59,25 +47,6 @@ impl<T: Trait> CuratorGroup<T> {
         &mut self.curators
     }
 
-    /// Increment number of channels `CuratorGroup` owns
-    pub fn increment_number_of_channels_owned_count(&mut self) {
-        self.number_of_channels_owned += 1;
-    }
-
-    /// Decrement number of channels `CuratorGroup` owns
-    pub fn decrement_number_of_channels_owned_count(&mut self) {
-        self.number_of_channels_owned -= 1;
-    }
-
-    /// Ensure curator group does not maintain any `Channel`
-    pub fn ensure_curator_group_owns_no_channels(&self) -> DispatchResult {
-        ensure!(
-            self.number_of_channels_owned == 0,
-            Error::<T>::CuratorGroupRemovalForbidden
-        );
-        Ok(())
-    }
-
     /// Ensure `MaxNumberOfCuratorsPerGroup` constraint satisfied
     pub fn ensure_max_number_of_curators_limit_not_reached(&self) -> DispatchResult {
         ensure!(

+ 0 - 17
runtime-modules/content/src/tests/channels.rs

@@ -176,23 +176,6 @@ fn members_can_manage_channels() {
             Error::<Test>::ActorNotAuthorized
         );
 
-        // Member cannot delete a channel they do not own
-        assert_err!(
-            Content::delete_channel(
-                Origin::signed(FIRST_MEMBER_ORIGIN),
-                ContentActor::Member(FIRST_MEMBER_ID),
-                channel_id_2
-            ),
-            Error::<Test>::ActorNotAuthorized
-        );
-
-        // Delete channel
-        assert_ok!(Content::delete_channel(
-            Origin::signed(FIRST_MEMBER_ORIGIN),
-            ContentActor::Member(FIRST_MEMBER_ID),
-            channel_id_1
-        ));
-
         // TODO: assert emitted events...
     })
 }

+ 0 - 9
types/augment-codec/augment-api-tx.ts

@@ -200,12 +200,7 @@ declare module '@polkadot/api/types/submittable' {
       createSeries: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, params: SeriesParameters | { assets?: any; seasons?: any; meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       createVideo: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, params: VideoCreationParameters | { assets?: any; meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       createVideoCategory: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, params: VideoCategoryCreationParameters | { meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      deleteChannel: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deleteChannelCategory: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, categoryId: ChannelCategoryId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      /**
-       * Remove curator group under given `curator_group_id` from runtime storage
-       **/
-      deleteCuratorGroup: AugmentedSubmittable<(curatorGroupId: CuratorGroupId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deletePerson: AugmentedSubmittable<(actor: PersonActor | { Member: any } | { Curator: any } | string | Uint8Array, person: PersonId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deletePlaylist: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, playlist: PlaylistId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deleteSeries: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, series: SeriesId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -219,10 +214,6 @@ declare module '@polkadot/api/types/submittable' {
        * Remove curator from a given curator group
        **/
       removeCuratorFromGroup: AugmentedSubmittable<(curatorGroupId: CuratorGroupId | AnyNumber | Uint8Array, curatorId: CuratorId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      /**
-       * Lead utility to remove assets of a deleted channel from storage
-       **/
-      removeDeletedChannelAssets: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, assets: Vec<ContentId> | (ContentId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
       removePersonFromVideo: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, videoId: VideoId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       requestChannelTransfer: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, request: ChannelOwnershipTransferRequest | { channel_id?: any; new_owner?: any; payment?: any; new_reward_account?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       /**

+ 1 - 2
types/augment/all/defs.json

@@ -696,8 +696,7 @@
     "CuratorGroupId": "u64",
     "CuratorGroup": {
         "curators": "Vec<CuratorId>",
-        "active": "bool",
-        "number_of_channels_owned": "u32"
+        "active": "bool"
     },
     "ContentActor": {
         "_enum": {

+ 0 - 1
types/augment/all/types.ts

@@ -324,7 +324,6 @@ export interface CuratorApplicationIdToCuratorIdMap extends Null {}
 export interface CuratorGroup extends Struct {
   readonly curators: Vec<CuratorId>;
   readonly active: bool;
-  readonly number_of_channels_owned: u32;
 }
 
 /** @name CuratorGroupId */

+ 0 - 9
types/augment/augment-api-tx.ts

@@ -200,12 +200,7 @@ declare module '@polkadot/api/types/submittable' {
       createSeries: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, params: SeriesParameters | { assets?: any; seasons?: any; meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       createVideo: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, params: VideoCreationParameters | { assets?: any; meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       createVideoCategory: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, params: VideoCategoryCreationParameters | { meta?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      deleteChannel: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deleteChannelCategory: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, categoryId: ChannelCategoryId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      /**
-       * Remove curator group under given `curator_group_id` from runtime storage
-       **/
-      deleteCuratorGroup: AugmentedSubmittable<(curatorGroupId: CuratorGroupId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deletePerson: AugmentedSubmittable<(actor: PersonActor | { Member: any } | { Curator: any } | string | Uint8Array, person: PersonId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deletePlaylist: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, playlist: PlaylistId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       deleteSeries: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, series: SeriesId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -219,10 +214,6 @@ declare module '@polkadot/api/types/submittable' {
        * Remove curator from a given curator group
        **/
       removeCuratorFromGroup: AugmentedSubmittable<(curatorGroupId: CuratorGroupId | AnyNumber | Uint8Array, curatorId: CuratorId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
-      /**
-       * Lead utility to remove assets of a deleted channel from storage
-       **/
-      removeDeletedChannelAssets: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, channelId: ChannelId | AnyNumber | Uint8Array, assets: Vec<ContentId> | (ContentId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
       removePersonFromVideo: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, videoId: VideoId | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       requestChannelTransfer: AugmentedSubmittable<(actor: ContentActor | { Curator: any } | { Member: any } | { Lead: any } | string | Uint8Array, request: ChannelOwnershipTransferRequest | { channel_id?: any; new_owner?: any; payment?: any; new_reward_account?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       /**

+ 0 - 1
types/src/content/index.ts

@@ -24,7 +24,6 @@ export class NewAsset extends JoyEnum({
 export class CuratorGroup extends JoyStructDecorated({
   curators: JoyBTreeSet(CuratorId),
   active: bool,
-  number_of_channels_owned: u32,
 }) {}
 
 export class ContentActor extends JoyEnum({