javascript - 如何禁用 YouTrack 工作流程中修改工作项?

标签 javascript youtrack

我想阻止 YouTrack 中的用户修改添加过去的工作项。他们应该只在当天添加/修改工作项目。

在 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('Disable editing workitems'),

  guard: function(ctx) {
    return ctx.issue.fields.isChanged(ctx.ST);
  },

  action: function(ctx) {
    workflow.check(ctx.issue.workItems.added.isEmpty(), workflow.i18n('You can add/modify workitems only in current day.'));
  },

  requirements: {
    ST: {
      type: entities.Field.periodType,
      name: 'Spent Time'
    }
  }
});

省略日期时间条件...

最佳答案

不确定它是否仍然相关,但我有完整的示例:

/**
 * This is a template for an on-change rule. This rule defines what
 * happens when a change is applied to an issue.
 *
 * For details, read the Quick Start Guide:
 * https://www.jetbrains.com/help/youtrack/server/2022.2/Quick-Start-Guide-Workflows-JS.html
 */

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

exports.rule = entities.Issue.onChange({
  title: 'Prevent-workitem-updates-past',
  guard: (ctx) => {
    const issue = ctx.issue;
    const fs = issue.fields;
    
    // NOT using issue.workItems.added.isEmpty() , because we also want to detect EDITS as well as ADDS to the WorkItems array.
    return fs.isChanged(ctx.ST) && !issue.becomesReported;
  },
  action: (ctx) => {
    const issue = ctx.issue;
   
    function checkWorkItemDate(currentWorkItem, currentEpochTimeStamp){
        workflow.check(currentWorkItem.date == currentEpochTimeStamp, workflow.i18n('You can add/modify workitems only in current day.'));
    }

    //const splittedDate = new Date().toISOString().slice(0, 10).split('-');
    //const currentEpoch = new Date(splittedDate[0], splittedDate[1] - 1, splittedDate[2]).valueOf();

    const currentDate = new Date();
    const currentEpoch = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()).valueOf();
     
    // Check newly added elements
    issue.workItems.added.forEach(workItem => {
        checkWorkItemDate(workItem, currentEpoch);
    });
    
    // Check edited elements
    issue.editedWorkItems.forEach(workItem => {
        checkWorkItemDate(workItem, currentEpoch);
    });
    
    workflow.check(true);
  },
  requirements: {
    ST: {
      type: entities.Field.periodType,
      name: 'Spent Time'
    }
  }
});

关于javascript - 如何禁用 YouTrack 工作流程中修改工作项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48766799/

相关文章:

intellij-idea - 如何使用 Google 帐户将 YouTrack 与 IntelliJ 集成?

java - 永久代内存不足。怎么增加内存?

git - 从 GIT 提交消息中删除的 YouTrack 命令

javascript - 在 Node red 中设置全局变量

javascript - 请求 Google Maps API 街景时排除 "Business View"全景图

javascript - Twilio 任务路由器 : change worker activity when disconnected

gitlab - 我应该使用专用用户进行 GitLab 集成吗?

YouTrack Windows 服务启动然后停止

javascript - 使用 ava 进行 React Native 单元测试

javascript - JavaScript 框架中的 Widget 封装