0

我正在尝试创建一个 Youtrack 工作流程,当当前问题积压时,仅允许特定角色将看板状态编辑为准备拉动。我不太能够让它正常工作,不断抛出异常,但我无法阅读完整的异常。

我试图创建当前的工作流代码:

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
    title: workflow.i18n('Block change in Kanban stage for issues that are in backlog'),
    guard: function(ctx) {
    return ctx.issue.isReported && ctx.issue.fields.isChanged(ctx.KanbanState);
  },
  action: function(ctx) {
    var issue = ctx.issue;

    if (!ctx.user.hasRole('project-admin', ctx.project)) {
        workflow.message('U dont have the correct permissions to do this'); 
        ctx.KanbanState = ctx.KanbanState.Blocked;
    }
  },
  requirements: {
    Stage: {
      type: entities.State.fieldType
    },
    KanbanState: {
      name: 'Kanban State',
      type: entities.EnumField.fieldType,
      ReadyToPull: {
        name: 'Ready to pull'
      },
      Blocked: {}
    }
  }
});

其中大部分是看板更改工作流程的副本,当看板状态未设置为“Ready-to-Pull”时,该工作流程会阻止将问题移至新阶段。我基本上想要完全相同,但我只想允许项目管理员在当前阶段为“积压”时将看板状态更改为“准备拉动”。当前代码目前仅检查权限,但我已经开始陷入困境。

4

2 回答 2

1

要实现这个任务,我建议你使用workflow.check方法,例如:

    workflow.check(ctx.user.hasRole('project-admin', ctx.project), 'U dont have the correct permissions to do this'); 

我希望这有帮助。

于 2019-08-29T15:05:10.920 回答
0

鉴于在我们目前的情况下,我们只需要禁用一个人即可在设置新票证时无法更改看板状态,我们有以下解决方案:

exports.rule = entities.Issue.onChange({
    title: workflow.i18n('Block change in Kanban stage for issues in backlog stage'),
    guard: function(ctx) {
    var issue = ctx.issue;
    return issue.fields.isChanged(ctx.KanbanState);//Runs when Kanban state changes
  },
  action: function(ctx) {
    var issue = ctx.issue;
    //Check if user has changed the kanban state to ready to pull while the current stage is backlog.

    if (issue.fields.Stage.name == 'Backlog') {
      //Current stage is backlog
      if (issue.fields.KanbanState.name === ctx.KanbanState.ReadyToPull.name) {
        //Kanban state was changed to ready to pull;

        var target = '<useremail>';

        workflow.check(ctx.currentUser.email == target,
          workflow.i18n('No permissions to change the Kanban state.'));
        issue.fields.KanbanState = ctx.KanbanState.Blocked;
      }
    }
  },
  requirements: {
    Stage: {
      type: entities.State.fieldType,
      Backlog: {},
      Development: {}
    },
    KanbanState: {
      name: 'Kanban State',
      type: entities.EnumField.fieldType,
      ReadyToPull: {
        name: 'Ready to pull'
      },
      Blocked: {}
    }
  }
});

但是我检查了@Oleg Larshun 的答案,他的答案也很有效。将电子邮件部分替换为:

workflow.check(ctx.user.hasRole('project-admin', ctx.project), 'U dont have the correct permissions to do this'); 
于 2019-08-30T09:31:40.670 回答