updateClassPermissions.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import CreateClassSchema from '@joystream/cd-schemas/schemas/extrinsics/CreateClass.schema.json'
  3. import chalk from 'chalk'
  4. import { JsonSchemaCustomPrompts, JsonSchemaPrompter } from '../../helpers/JsonSchemaPrompt'
  5. import { CreateClass } from '@joystream/cd-schemas/types/extrinsics/CreateClass'
  6. import { JSONSchema } from '@apidevtools/json-schema-ref-parser'
  7. export default class UpdateClassPermissionsCommand extends ContentDirectoryCommandBase {
  8. static description = 'Update permissions in given class.'
  9. static args = [
  10. {
  11. name: 'className',
  12. required: false,
  13. description: 'Name or ID of the class (ie. Video)',
  14. },
  15. ]
  16. async run() {
  17. const account = await this.getRequiredSelectedAccount()
  18. await this.requireLead()
  19. let { className } = this.parse(UpdateClassPermissionsCommand).args
  20. if (className === undefined) {
  21. className = (await this.promptForClass()).name.toString()
  22. }
  23. const [classId, aClass] = await this.classEntryByNameOrId(className)
  24. const currentPermissions = aClass.class_permissions
  25. const customPrompts: JsonSchemaCustomPrompts = [
  26. ['class_permissions.maintainers', () => this.promptForCuratorGroups('Select class maintainers')],
  27. ]
  28. const prompter = new JsonSchemaPrompter<CreateClass>(
  29. CreateClassSchema as JSONSchema,
  30. { class_permissions: currentPermissions.toJSON() as CreateClass['class_permissions'] },
  31. customPrompts
  32. )
  33. const newPermissions = await prompter.promptSingleProp('class_permissions')
  34. await this.requestAccountDecoding(account)
  35. await this.sendAndFollowNamedTx(account, 'contentDirectory', 'updateClassPermissions', [
  36. classId,
  37. this.createType('Option<bool>', newPermissions.any_member || null),
  38. this.createType('Option<bool>', newPermissions.entity_creation_blocked || null),
  39. this.createType('Option<bool>', newPermissions.all_entity_property_values_locked || null),
  40. this.createType('Option<bool>', newPermissions.maintainers || null),
  41. ])
  42. console.log(chalk.green(`${chalk.white(className)} class permissions updated to:`))
  43. this.jsonPrettyPrint(JSON.stringify(newPermissions))
  44. }
  45. }