Browse Source

Simplify curation status (isCensored)

Leszek Wiesner 4 years ago
parent
commit
9a4898629f

+ 12 - 53
cli/src/commands/media/curateContent.ts

@@ -1,12 +1,11 @@
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
-import { CurationStatusEntity } from 'cd-schemas/types/entities/CurationStatusEntity'
 import { InputParser } from 'cd-schemas'
 import { flags } from '@oclif/command'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 
 const CLASSES = ['Channel', 'Video'] as const
-const STATUSES = ['Accepted', 'Rejected'] as const
+const STATUSES = ['Accepted', 'Censored'] as const
 
 export default class CurateContentCommand extends ContentDirectoryCommandBase {
   static description = `Set the curation status of given entity (${CLASSES.join('/')}). Requires Curator access.`
@@ -23,11 +22,6 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
       options: [...STATUSES],
       required: true,
     }),
-    rationale: flags.string({
-      description: 'Optional rationale',
-      char: 'r',
-      required: false,
-    }),
     id: flags.integer({
       description: 'ID of the entity to curate',
       required: true,
@@ -35,11 +29,11 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
   }
 
   async run() {
-    const { className, status, id, rationale } = this.parse(CurateContentCommand).flags
+    const { className, status, id } = this.parse(CurateContentCommand).flags
 
     const account = await this.getRequiredSelectedAccount()
-    // Get curator actor with required maintainer access to $className and 'CurationStatus' classes
-    const actor = await this.getCuratorContext([className, 'CurationStatus'])
+    // Get curator actor with required maintainer access to $className (Video/Channel) class
+    const actor = await this.getCuratorContext([className])
 
     await this.requestAccountDecoding(account)
 
@@ -47,52 +41,17 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
 
     await this.getEntity(id, className) // Check if entity exists and is of given class
 
-    // Check if CurationStatus for this entity already exists
-    let existingStatusId: number | undefined
-    try {
-      existingStatusId = await inputParser.findEntityIdByUniqueQuery({ entityId: id }, 'CurationStatus')
-    } catch (e) {
-      /* Continue */
+    const entityUpdateInput: Partial<ChannelEntity & VideoEntity> = {
+      isCensored: status === 'Censored',
     }
 
-    if (existingStatusId) {
-      const current = await this.getAndParseKnownEntity<CurationStatusEntity>(existingStatusId)
-      const statusUpdate: Partial<CurationStatusEntity> = { approved: status === 'Accepted' }
-      if (rationale !== undefined) {
-        statusUpdate.comment = rationale
-      }
-
-      this.log(`Existing curation status found!`)
-      this.jsonPrettyPrint(JSON.stringify(current))
-      this.log('It will be updated to...')
-      this.jsonPrettyPrint(JSON.stringify({ ...current, ...statusUpdate }))
-      const confirmed = await this.simplePrompt({
-        type: 'confirm',
-        message: `Do you confirm this operation?`,
-      })
-
-      if (confirmed) {
-        const operations = await inputParser.getEntityUpdateOperations(statusUpdate, 'CurationStatus', existingStatusId)
-        await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
-      }
-    } else {
-      const curationStatus: CurationStatusEntity = {
-        entityId: id,
-        approved: status === 'Accepted',
-        comment: rationale,
-      }
-
-      const entityUpdateInput: Partial<ChannelEntity & VideoEntity> = {
-        curationStatus: { new: curationStatus },
-      }
-
-      this.jsonPrettyPrint(JSON.stringify(curationStatus))
-      const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
+    this.log(`Updating the ${className} with:`)
+    this.jsonPrettyPrint(JSON.stringify(entityUpdateInput))
+    const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
 
-      if (confirmed) {
-        const operations = await inputParser.getEntityUpdateOperations(entityUpdateInput, className, id)
-        await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
-      }
+    if (confirmed) {
+      const operations = await inputParser.getEntityUpdateOperations(entityUpdateInput, className, id)
+      await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
     }
   }
 }

+ 0 - 7
content-directory-schemas/inputs/classes/CurationStatusClass.json

@@ -1,7 +0,0 @@
-{
-  "name": "CurationStatus",
-  "description": "Curation status of a related entity (ie. Video or Channel)",
-  "maximum_entities_count": 400,
-  "default_entity_creation_voucher_upper_bound": 50,
-  "class_permissions": { "any_member": false }
-}

+ 3 - 3
content-directory-schemas/inputs/schemas/ChannelSchema.json

@@ -33,11 +33,11 @@
       "property_type": { "Single": "Bool" }
     },
     {
-      "name": "curationStatus",
-      "description": "Channel curation status set by the Curator",
+      "name": "isCensored",
+      "description": "Channel censorship status set by the Curator.",
       "required": false,
       "unique": true,
-      "property_type": { "Single": { "Reference": { "className": "CurationStatus" } } },
+      "property_type": { "Single": "Bool" },
       "locking_policy": { "is_locked_from_controller": true }
     },
     {

+ 0 - 27
content-directory-schemas/inputs/schemas/CurationStatusSchema.json

@@ -1,27 +0,0 @@
-{
-  "className": "CurationStatus",
-  "newProperties": [
-    {
-      "name": "approved",
-      "description": "Indicates whether the content was approved by the Curator",
-      "required": false,
-      "property_type": { "Single": "Bool" },
-      "locking_policy": { "is_locked_from_controller": true }
-    },
-    {
-      "name": "comment",
-      "description": "Short, optional comment from the Curator",
-      "required": false,
-      "property_type": { "Single": { "Text": 256 } },
-      "locking_policy": { "is_locked_from_controller": true }
-    },
-    {
-      "name": "entityId",
-      "description": "ID of the curated entity. It's not a relation to prevent removal lock and allow different types of entities. Used to confirm the validity of Content => CurationStatus relation.",
-      "required": true,
-      "unique": true,
-      "property_type": { "Single": "Uint64" },
-      "locking_policy": { "is_locked_from_controller": true }
-    }
-  ]
-}

+ 3 - 3
content-directory-schemas/inputs/schemas/VideoSchema.json

@@ -90,11 +90,11 @@
       "property_type": { "Single": { "Reference": { "className": "License", "sameOwner": true } } }
     },
     {
-      "name": "curationStatus",
-      "description": "Video curation status set by the Curator",
+      "name": "isCensored",
+      "description": "Video censorship status set by the Curator.",
       "required": false,
       "unique": true,
-      "property_type": { "Single": { "Reference": { "className": "CurationStatus" } } },
+      "property_type": { "Single": "Bool" },
       "locking_policy": { "is_locked_from_controller": true }
     }
   ]