|
@@ -24,29 +24,20 @@ const DEFAULT_GROUP = WorkingGroups.StorageProviders
|
|
|
const DRAFTS_FOLDER = 'opening-drafts'
|
|
|
|
|
|
/**
|
|
|
- * Abstract base class for commands related to working groups
|
|
|
+ * Abstract base class for commands that need to use gates based on user's roles
|
|
|
*/
|
|
|
-export default abstract class WorkingGroupsCommandBase extends AccountsCommandBase {
|
|
|
+export abstract class RolesCommandBase extends AccountsCommandBase {
|
|
|
group: WorkingGroups = DEFAULT_GROUP
|
|
|
|
|
|
- static flags = {
|
|
|
- group: flags.string({
|
|
|
- char: 'g',
|
|
|
- description:
|
|
|
- 'The working group context in which the command should be executed\n' +
|
|
|
- `Available values are: ${AvailableGroups.join(', ')}.`,
|
|
|
- required: true,
|
|
|
- default: DEFAULT_GROUP,
|
|
|
- }),
|
|
|
- }
|
|
|
-
|
|
|
// Use when lead access is required in given command
|
|
|
async getRequiredLead(): Promise<GroupMember> {
|
|
|
const selectedAccount: NamedKeyringPair = await this.getRequiredSelectedAccount()
|
|
|
const lead = await this.getApi().groupLead(this.group)
|
|
|
|
|
|
if (!lead || lead.roleAccount.toString() !== selectedAccount.address) {
|
|
|
- this.error('Lead access required for this command!', { exit: ExitCodes.AccessDenied })
|
|
|
+ this.error(`${_.startCase(this.group)} Group Lead access required for this command!`, {
|
|
|
+ exit: ExitCodes.AccessDenied,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
return lead
|
|
@@ -59,7 +50,9 @@ export default abstract class WorkingGroupsCommandBase extends AccountsCommandBa
|
|
|
const groupMembersByAccount = groupMembers.filter((m) => m.roleAccount.toString() === selectedAccount.address)
|
|
|
|
|
|
if (!groupMembersByAccount.length) {
|
|
|
- this.error('Worker access required for this command!', { exit: ExitCodes.AccessDenied })
|
|
|
+ this.error(`${_.startCase(this.group)} Group Worker access required for this command!`, {
|
|
|
+ exit: ExitCodes.AccessDenied,
|
|
|
+ })
|
|
|
} else if (groupMembersByAccount.length === 1) {
|
|
|
return groupMembersByAccount[0]
|
|
|
} else {
|
|
@@ -88,7 +81,7 @@ export default abstract class WorkingGroupsCommandBase extends AccountsCommandBa
|
|
|
|
|
|
async promptForWorker(groupMembers: GroupMember[]): Promise<GroupMember> {
|
|
|
const chosenWorkerIndex = await this.simplePrompt({
|
|
|
- message: 'Choose the intended worker context:',
|
|
|
+ message: `Choose the intended ${_.startCase(this.group)} Group Worker context:`,
|
|
|
type: 'list',
|
|
|
choices: groupMembers.map((groupMember, index) => ({
|
|
|
name: `Worker ID ${groupMember.workerId.toString()}`,
|
|
@@ -98,6 +91,24 @@ export default abstract class WorkingGroupsCommandBase extends AccountsCommandBa
|
|
|
|
|
|
return groupMembers[chosenWorkerIndex]
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Abstract base class for commands directly related to working groups
|
|
|
+ */
|
|
|
+export default abstract class WorkingGroupsCommandBase extends RolesCommandBase {
|
|
|
+ group: WorkingGroups = DEFAULT_GROUP
|
|
|
+
|
|
|
+ static flags = {
|
|
|
+ group: flags.string({
|
|
|
+ char: 'g',
|
|
|
+ description:
|
|
|
+ 'The working group context in which the command should be executed\n' +
|
|
|
+ `Available values are: ${AvailableGroups.join(', ')}.`,
|
|
|
+ required: true,
|
|
|
+ default: DEFAULT_GROUP,
|
|
|
+ }),
|
|
|
+ }
|
|
|
|
|
|
async promptForApplicationsToAccept(opening: GroupOpening): Promise<number[]> {
|
|
|
const acceptableApplications = opening.applications.filter((a) => a.stage === ApplicationStageKeys.Active)
|