Browse Source

Content: add censorship support for videos & channels

iorveth 4 years ago
parent
commit
53748103bb

+ 15 - 21
cli/src/base/ContentDirectoryCommandBase.ts

@@ -5,8 +5,8 @@ import {
   CuratorGroup,
   CuratorGroupId,
   ContentActor,
+  Video,
 } from '@joystream/types/content'
-import { ChannelId } from '@joystream/types/common'
 import { Worker } from '@joystream/types/working-group'
 import { CLIError } from '@oclif/errors'
 import _ from 'lodash'
@@ -71,36 +71,30 @@ export default abstract class ContentDirectoryCommandBase extends RolesCommandBa
   }
 
   async promptForChannel(message = 'Select a channel'): Promise<Channel> {
-    const classes = await this.getApi().availableChannels()
-    const choices = classes.map(([id, c]) => ({ id: id.toString(), value: c }))
+    const channels = await this.getApi().availableChannels()
+    const choices = channels.map(([id, c]) => ({ id: id.toString(), value: c }))
     if (!choices.length) {
       this.warn('No channels exist to choose from!')
       this.exit(ExitCodes.InvalidInput)
     }
 
-    const selectedClass = await this.simplePrompt({ message, type: 'list', choices })
+    const selectedChannel = await this.simplePrompt({ message, type: 'list', choices })
 
-    return selectedClass
+    return selectedChannel
   }
 
-  // async channelEntryById(channelId: number): Promise<[ChannelId, Channel]> {
-  //   const foundChannel = await this.getApi().channelById(channelId)
-  //   if (!foundChannel) {
-  //     this.error(`Channel not found by channel id: "${channelId}"!`)
-  //   }
-
-  //   return [channelId, foundChannel]
-  // }
+  async promptForVideo(message = 'Select a video'): Promise<Video> {
+    const videos = await this.getApi().availableVideos()
+    const choices = videos.map(([id, c]) => ({ id: id.toString(), value: c }))
+    if (!choices.length) {
+      this.warn('No videos exist to choose from!')
+      this.exit(ExitCodes.InvalidInput)
+    }
 
-  // async videoEntryById(videoId: string): Promise<[ChannelId, Channel]> {
-  //   const videos = await this.getApi().availableVideos()
-  //   const foundVideo = channels.find(([id, ]) => id.toString() === channelId)
-  //   if (!foundChannel) {
-  //     this.error(`Channel not found by channel id: "${channelId}"!`)
-  //   }
+    const selectedVideo = await this.simplePrompt({ message, type: 'list', choices })
 
-  //   return foundChannel
-  // }
+    return selectedVideo
+  }
 
   private async curatorGroupChoices(ids?: CuratorGroupId[]) {
     const groups = await this.getApi().availableCuratorGroups()

+ 74 - 0
cli/src/commands/content/updateChannelCensorshipStatus.ts

@@ -0,0 +1,74 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+import ExitCodes from '../../ExitCodes'
+
+export default class UpdateChannelCensorshipStatusCommand extends ContentDirectoryCommandBase {
+  static description = 'Update Channel censorship status (Active/Inactive).'
+  static flags = {
+    context: ContentDirectoryCommandBase.contextFlag,
+  }
+  static args = [
+    {
+      name: 'id',
+      required: false,
+      description: 'ID of the Channel',
+    },
+    {
+      name: 'status',
+      required: false,
+      description: 'New status of the channel (1 - active, 0 - inactive)',
+    },
+    {
+      name: 'rationale',
+      required: false,
+      description: 'rationale',
+    },
+  ]
+
+  async run() {
+    let { context } = this.parse(UpdateChannelCensorshipStatusCommand).flags
+
+    let { id, status, rationale } = this.parse(UpdateChannelCensorshipStatusCommand).args
+
+    if (!context) {
+        context = await this.promptForContext()
+    }
+
+    const currentAccount = await this.getRequiredSelectedAccount()
+    await this.requestAccountDecoding(currentAccount)
+
+    const actor = await this.getActor(context)
+
+    if (id === undefined) {
+      id = await this.promptForChannel()
+    } 
+
+    if (status === undefined) {
+      status = await this.simplePrompt({
+        type: 'list',
+        message: 'Select new status',
+        choices: [
+          { name: 'Active', value: true },
+          { name: 'Inactive', value: false },
+        ],
+      })
+    } else {
+      if (status !== '0' && status !== '1') {
+        this.error('Invalid status provided. Use "1" for Active and "0" for Inactive.', {
+          exit: ExitCodes.InvalidInput,
+        })
+      }
+      status = !!parseInt(status)
+    }
+
+    await this.sendAndFollowNamedTx(currentAccount, 'content', 'updateChannelCensorshipStatus', [actor, id, status, rationale])
+
+    console.log(
+      chalk.green(
+        `Channel ${chalk.white(id)} status succesfully changed to: ${chalk.white(
+          status ? 'Active' : 'Inactive'
+        )}!`
+      )
+    )
+  }
+}

+ 74 - 0
cli/src/commands/content/updateVideoCensorshipStatus.ts

@@ -0,0 +1,74 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+import ExitCodes from '../../ExitCodes'
+
+export default class UpdateChannelCensorshipStatusCommand extends ContentDirectoryCommandBase {
+  static description = 'Update Channel censorship status (Active/Inactive).'
+  static flags = {
+    context: ContentDirectoryCommandBase.contextFlag,
+  }
+  static args = [
+    {
+      name: 'id',
+      required: false,
+      description: 'ID of the Video',
+    },
+    {
+      name: 'status',
+      required: false,
+      description: 'New status of the video (1 - active, 0 - inactive)',
+    },
+    {
+      name: 'rationale',
+      required: true,
+      description: 'rationale',
+    },
+  ]
+
+  async run() {
+    let { context } = this.parse(UpdateChannelCensorshipStatusCommand).flags
+
+    let { id, status, rationale } = this.parse(UpdateChannelCensorshipStatusCommand).args
+
+    if (!context) {
+        context = await this.promptForContext()
+    }
+
+    const currentAccount = await this.getRequiredSelectedAccount()
+    await this.requestAccountDecoding(currentAccount)
+
+    const actor = await this.getActor(context)
+
+    if (id === undefined) {
+      id = await this.promptForVideo()
+    }
+
+    if (status === undefined) {
+      status = await this.simplePrompt({
+        type: 'list',
+        message: 'Select new status',
+        choices: [
+          { name: 'Active', value: true },
+          { name: 'Inactive', value: false },
+        ],
+      })
+    } else {
+      if (status !== '0' && status !== '1') {
+        this.error('Invalid status provided. Use "1" for Active and "0" for Inactive.', {
+          exit: ExitCodes.InvalidInput,
+        })
+      }
+      status = !!parseInt(status)
+    }
+
+    await this.sendAndFollowNamedTx(currentAccount, 'content', 'updateVideoCensorshipStatus', [actor, id, status, rationale])
+
+    console.log(
+      chalk.green(
+        `Video ${chalk.white(id)} status succesfully changed to: ${chalk.white(
+          status ? 'Active' : 'Inactive'
+        )}!`
+      )
+    )
+  }
+}