首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Youtrack检查用户是否有权限

Youtrack检查用户是否有权限
EN

Stack Overflow用户
提问于 2019-08-26 22:08:05
回答 2查看 820关注 0票数 0

我正在尝试创建一个Youtrack工作流,其中当当前问题处于积压状态时,只允许特定角色编辑看板状态以准备拉取。我不能让它正确工作,不断抛出异常,但我无法读取完整的异常。

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

代码语言:javascript
复制
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: {}
    }
  }
});

其中大部分是看板变更工作流程的副本,当看板状态未设置为“准备拉动”时,该工作流程会阻止将问题转移到新阶段。我基本上想要完全相同,但我想只允许项目管理员在当前阶段为"Backlog“时将看板状态更改为"ready- to -pull”。目前的代码只检查权限,但我已经开始卡在那里了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-29 23:05:11

要实现此任务,我建议您使用workflow.check方法,例如:

代码语言:javascript
复制
    workflow.check(ctx.user.hasRole('project-admin', ctx.project), 'U dont have the correct permissions to do this'); 

我希望这能帮到你。

票数 1
EN

Stack Overflow用户

发布于 2019-08-30 17:31:41

考虑到在我们当前的情况下,我们只需要禁用一个人,以便在设置新票证时无法更改看板状态,我们有以下解决方案:

代码语言:javascript
复制
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的答案,他的答案也很有效。将电子邮件部分替换为:

代码语言:javascript
复制
workflow.check(ctx.user.hasRole('project-admin', ctx.project), 'U dont have the correct permissions to do this'); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57659548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档