Bläddra i källkod

Censorship fixes

Leszek Wiesner 3 år sedan
förälder
incheckning
f7008adf4b

+ 14 - 6
cli/src/Api.ts

@@ -523,9 +523,13 @@ export default class Api {
     return (await this._api.query.content.nextCuratorGroupId<CuratorGroupId>()).toNumber()
   }
 
-  async channelById(channelId: number): Promise<Channel | null> {
-    const c = await this._api.query.content.channelById<Channel>(channelId)
-    return c.isEmpty ? null : c
+  async channelById(channelId: number): Promise<Channel> {
+    const channel = await this._api.query.content.channelById<Channel>(channelId)
+    if (channel.isEmpty) {
+      throw new CLIError(`Channel by id ${channelId} not found!`)
+    }
+
+    return channel
   }
 
   async videosByChannelId(channelId: number): Promise<[VideoId, Video][]> {
@@ -541,9 +545,13 @@ export default class Api {
     }
   }
 
-  async videoById(videoId: number): Promise<Video | null> {
-    const exists = !!(await this._api.query.content.videoById.size(videoId)).toNumber()
-    return exists ? await this._api.query.content.videoById<Video>(videoId) : null
+  async videoById(videoId: number): Promise<Video> {
+    const video = await this._api.query.content.videoById<Video>(videoId)
+    if (video.isEmpty) {
+      throw new CLIError(`Video by id ${videoId} not found!`)
+    }
+
+    return video
   }
 
   async channelCategoryById(channelCategoryId: number): Promise<ChannelCategory | null> {

+ 9 - 3
cli/src/base/ContentDirectoryCommandBase.ts

@@ -1,12 +1,14 @@
 import ExitCodes from '../ExitCodes'
 import { WorkingGroups } from '../Types'
-import { CuratorGroup, CuratorGroupId, ContentActor } from '@joystream/types/content'
+import { CuratorGroup, CuratorGroupId, ContentActor, Channel } from '@joystream/types/content'
 import { Worker } from '@joystream/types/working-group'
 import { CLIError } from '@oclif/errors'
 import { RolesCommandBase } from './WorkingGroupsCommandBase'
 import { createType } from '@joystream/types'
 import { flags } from '@oclif/command'
 
+// TODO: Rework the contexts
+
 const CONTEXTS = ['Member', 'Curator', 'Lead'] as const
 const OWNER_CONTEXTS = ['Member', 'Curator'] as const
 const CATEGORIES_CONTEXTS = ['Lead', 'Curator'] as const
@@ -75,6 +77,10 @@ export default abstract class ContentDirectoryCommandBase extends RolesCommandBa
     await this.getRequiredLead()
   }
 
+  async getCurationActorByChannel(channel: Channel): Promise<ContentActor> {
+    return channel.owner.isOfType('Curators') ? await this.getActor('Lead') : await this.getActor('Curator')
+  }
+
   async getCuratorContext(): Promise<ContentActor> {
     const curator = await this.getRequiredWorker()
 
@@ -88,7 +94,7 @@ export default abstract class ContentDirectoryCommandBase extends RolesCommandBa
 
     let groupId: number
     if (!availableGroupIds.length) {
-      this.error('You do not have the curator access!', { exit: ExitCodes.AccessDenied })
+      this.error("You don't belong to any active curator group!", { exit: ExitCodes.AccessDenied })
     } else if (availableGroupIds.length === 1) {
       groupId = availableGroupIds[0].toNumber()
     } else {
@@ -106,7 +112,7 @@ export default abstract class ContentDirectoryCommandBase extends RolesCommandBa
         name:
           `Group ${id.toString()} (` +
           `${group.active.valueOf() ? 'Active' : 'Inactive'}, ` +
-          `${group.curators.toArray().length} member(s), `,
+          `${group.curators.toArray().length} member(s)), `,
         value: id.toNumber(),
       }))
   }

+ 18 - 15
cli/src/commands/content/updateChannelCensorshipStatus.ts

@@ -1,11 +1,16 @@
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
 import chalk from 'chalk'
 import ExitCodes from '../../ExitCodes'
+import { flags } from '@oclif/command'
 
 export default class UpdateChannelCensorshipStatusCommand extends ContentDirectoryCommandBase {
   static description = 'Update Channel censorship status (Censored / Not censored).'
   static flags = {
-    context: ContentDirectoryCommandBase.ownerContextFlag,
+    rationale: flags.string({
+      name: 'rationale',
+      required: false,
+      description: 'rationale',
+    }),
   }
 
   static args = [
@@ -17,29 +22,23 @@ export default class UpdateChannelCensorshipStatusCommand extends ContentDirecto
     {
       name: 'status',
       required: false,
-      description: 'New status of the channel (1 - censored, 0 - not censored)',
-    },
-    {
-      name: 'rationale',
-      required: true,
-      description: 'rationale',
+      description: 'New censorship status of the channel (1 - censored, 0 - not censored)',
     },
   ]
 
   async run() {
-    let { context } = this.parse(UpdateChannelCensorshipStatusCommand).flags
+    let {
+      args: { id, status },
+      flags: { rationale },
+    } = this.parse(UpdateChannelCensorshipStatusCommand)
 
-    let { id, status, rationale } = this.parse(UpdateChannelCensorshipStatusCommand).args
+    const currentAccount = await this.getRequiredSelectedAccount()
 
-    if (!context) {
-      context = await this.promptForOwnerContext()
-    }
+    const channel = await this.getApi().channelById(id)
+    const actor = await this.getCurationActorByChannel(channel)
 
-    const currentAccount = await this.getRequiredSelectedAccount()
     await this.requestAccountDecoding(currentAccount)
 
-    const actor = await this.getActor(context)
-
     if (status === undefined) {
       status = await this.simplePrompt({
         type: 'list',
@@ -58,6 +57,10 @@ export default class UpdateChannelCensorshipStatusCommand extends ContentDirecto
       status = !!parseInt(status)
     }
 
+    if (rationale === undefined) {
+      rationale = await this.simplePrompt({ message: 'Please provide the rationale for updating the status' })
+    }
+
     await this.sendAndFollowNamedTx(currentAccount, 'content', 'updateChannelCensorshipStatus', [
       actor,
       id,

+ 18 - 14
cli/src/commands/content/updateVideoCensorshipStatus.ts

@@ -1,11 +1,16 @@
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
 import chalk from 'chalk'
 import ExitCodes from '../../ExitCodes'
+import { flags } from '@oclif/command'
 
 export default class UpdateVideoCensorshipStatusCommand extends ContentDirectoryCommandBase {
   static description = 'Update Video censorship status (Censored / Not censored).'
   static flags = {
-    context: ContentDirectoryCommandBase.ownerContextFlag,
+    rationale: flags.string({
+      name: 'rationale',
+      required: false,
+      description: 'rationale',
+    }),
   }
 
   static args = [
@@ -19,27 +24,22 @@ export default class UpdateVideoCensorshipStatusCommand extends ContentDirectory
       required: false,
       description: 'New video censorship status (1 - censored, 0 - not censored)',
     },
-    {
-      name: 'rationale',
-      required: true,
-      description: 'rationale',
-    },
   ]
 
   async run() {
-    let { context } = this.parse(UpdateVideoCensorshipStatusCommand).flags
+    let {
+      args: { id, status },
+      flags: { rationale },
+    } = this.parse(UpdateVideoCensorshipStatusCommand)
 
-    let { id, status, rationale } = this.parse(UpdateVideoCensorshipStatusCommand).args
+    const currentAccount = await this.getRequiredSelectedAccount()
 
-    if (!context) {
-      context = await this.promptForOwnerContext()
-    }
+    const video = await this.getApi().videoById(id)
+    const channel = await this.getApi().channelById(video.in_channel.toNumber())
+    const actor = await this.getCurationActorByChannel(channel)
 
-    const currentAccount = await this.getRequiredSelectedAccount()
     await this.requestAccountDecoding(currentAccount)
 
-    const actor = await this.getActor(context)
-
     if (status === undefined) {
       status = await this.simplePrompt({
         type: 'list',
@@ -58,6 +58,10 @@ export default class UpdateVideoCensorshipStatusCommand extends ContentDirectory
       status = !!parseInt(status)
     }
 
+    if (rationale === undefined) {
+      rationale = await this.simplePrompt({ message: 'Please provide the rationale for updating the status' })
+    }
+
     await this.sendAndFollowNamedTx(currentAccount, 'content', 'updateVideoCensorshipStatus', [
       actor,
       id,