-
Notifications
You must be signed in to change notification settings - Fork 115
/
createCuratorGroup.ts
54 lines (49 loc) · 2.08 KB
/
createCuratorGroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
import chalk from 'chalk'
import { flags } from '@oclif/command'
import { ModerationPermissionsByLevelInputParameters } from '../../Types'
import { getInputJson } from '../../helpers/InputOutput'
import { ModerationPermissionsByLevelInputSchema } from '../../schemas/ContentDirectory'
import { createType } from '@joystream/types'
const CURATOR_GROUP_CREATION_CONTEXTS = ['ACTIVE', 'INACTIVE'] as const
export default class CreateCuratorGroupCommand extends ContentDirectoryCommandBase {
static description = 'Create new Curator Group.'
static flags = {
status: flags.enum({
required: true,
description: `Status of newly created Curator Group: (${CURATOR_GROUP_CREATION_CONTEXTS.join('/')})`,
options: [...CURATOR_GROUP_CREATION_CONTEXTS],
}),
permissions: flags.string({
char: 'p',
description: `Path to JSON file containing moderation permissions by channel privilege level to use as input`,
}),
...ContentDirectoryCommandBase.flags,
}
async run(): Promise<void> {
const { status, permissions } = this.parse(CreateCuratorGroupCommand).flags
const lead = await this.getRequiredLeadContext()
const keypair = await this.getDecodedPair(lead.roleAccount)
const moderationPermissionsByLevelInput = permissions
? await getInputJson<ModerationPermissionsByLevelInputParameters>(
permissions,
ModerationPermissionsByLevelInputSchema
)
: []
const moderationPermissionsByLevel = createType(
'BTreeMap<u8,BTreeSet<PalletContentPermissionsCuratorGroupIterableEnumsContentModerationAction>>',
new Map(
moderationPermissionsByLevelInput.map(({ channelPrivilegeLevel, permissions }) => [
channelPrivilegeLevel,
permissions,
])
)
)
await this.sendAndFollowNamedTx(keypair, 'content', 'createCuratorGroup', [
status === 'ACTIVE',
moderationPermissionsByLevel,
])
// TODO: Get id from event?
console.log(chalk.green(`New group successfully created!`))
}
}