Правила определения текущего пользователя вынесены в конфиг
This commit is contained in:
parent
06c98e0276
commit
daef9ccec5
6 changed files with 45 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -40,3 +40,4 @@ configs/redmine-statuses-config.jsonc
|
||||||
configs/redmine-status-changes-config.jsonc
|
configs/redmine-status-changes-config.jsonc
|
||||||
configs/eccm-versions-config.jsonc
|
configs/eccm-versions-config.jsonc
|
||||||
configs/eccm-config.jsonc
|
configs/eccm-config.jsonc
|
||||||
|
configs/current-user-rules.jsonc
|
||||||
|
|
|
||||||
4
configs/current-user-rules.jsonc.dist
Normal file
4
configs/current-user-rules.jsonc.dist
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"New": "",
|
||||||
|
"*": ""
|
||||||
|
}
|
||||||
|
|
@ -6,11 +6,13 @@ import { AppConfig } from 'src/models/app-config.model';
|
||||||
import RedmineStatusesConfigLoader from './statuses.config';
|
import RedmineStatusesConfigLoader from './statuses.config';
|
||||||
import RedmineStatusChangesConfigLoader from './status-changes.config';
|
import RedmineStatusChangesConfigLoader from './status-changes.config';
|
||||||
import RedmineEccmConfig from './eccm.config';
|
import RedmineEccmConfig from './eccm.config';
|
||||||
|
import RedmineCurrentUserRulesConfig from './current-user-rules.config';
|
||||||
|
|
||||||
const redmineIssueEventEmitterConfig = RedmineIssueEventEmitterConfigLoader();
|
const redmineIssueEventEmitterConfig = RedmineIssueEventEmitterConfigLoader();
|
||||||
const redmineStatusesConfig = RedmineStatusesConfigLoader();
|
const redmineStatusesConfig = RedmineStatusesConfigLoader();
|
||||||
const redmineStatusChanges = RedmineStatusChangesConfigLoader();
|
const redmineStatusChanges = RedmineStatusChangesConfigLoader();
|
||||||
const redmineEccm = RedmineEccmConfig();
|
const redmineEccm = RedmineEccmConfig();
|
||||||
|
const redmineCurrentUserRules = RedmineCurrentUserRulesConfig();
|
||||||
|
|
||||||
let appConfig: AppConfig;
|
let appConfig: AppConfig;
|
||||||
|
|
||||||
|
|
@ -33,6 +35,7 @@ export default (): AppConfig => {
|
||||||
redmineIssueEventEmitterConfig: redmineIssueEventEmitterConfig,
|
redmineIssueEventEmitterConfig: redmineIssueEventEmitterConfig,
|
||||||
redmineStatusChanges: redmineStatusChanges,
|
redmineStatusChanges: redmineStatusChanges,
|
||||||
redmineEccm: redmineEccm,
|
redmineEccm: redmineEccm,
|
||||||
|
redmineCurrentUserRules: redmineCurrentUserRules,
|
||||||
};
|
};
|
||||||
|
|
||||||
return appConfig;
|
return appConfig;
|
||||||
|
|
|
||||||
23
src/configs/current-user-rules.config.ts
Normal file
23
src/configs/current-user-rules.config.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { join } from 'path';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { parse } from 'jsonc-parser';
|
||||||
|
|
||||||
|
let currentUserRules: Record<string, string>;
|
||||||
|
|
||||||
|
export default (): Record<string, string> => {
|
||||||
|
if (currentUserRules) {
|
||||||
|
return currentUserRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userDefinedConfigPath =
|
||||||
|
process.env['ELTEX_REDMINE_HELPER_CURRENT_USER_RULES_CONFIG_PATH'];
|
||||||
|
const defaultConfigPath = join('configs', 'current-user-rules.jsonc');
|
||||||
|
|
||||||
|
const configPath = userDefinedConfigPath || defaultConfigPath;
|
||||||
|
|
||||||
|
const rawData = readFileSync(configPath, { encoding: 'utf-8' });
|
||||||
|
|
||||||
|
currentUserRules = parse(rawData);
|
||||||
|
|
||||||
|
return currentUserRules;
|
||||||
|
};
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface';
|
import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface';
|
||||||
import { RedmineTypes } from '@app/event-emitter/models/redmine-types';
|
import { RedmineTypes } from '@app/event-emitter/models/redmine-types';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
||||||
name = 'current-user';
|
name = 'current-user';
|
||||||
|
|
||||||
// TODO: Переместить правила в конфиг
|
private rules: Record<string, string>;
|
||||||
|
private logger = new Logger(CurrentUserEnhancer.name);
|
||||||
|
|
||||||
private rules = {
|
constructor(private configService: ConfigService) {
|
||||||
New: 'dev',
|
this.rules = this.configService.get<Record<string, string>>(
|
||||||
'In Progress': 'dev',
|
'redmineCurrentUserRules',
|
||||||
'Re-opened': 'dev',
|
);
|
||||||
'Code Review': 'cr',
|
this.logger.debug(
|
||||||
Resolved: 'qa',
|
`Loaded rules for current user enhancer - ${JSON.stringify(this.rules)}`,
|
||||||
Testing: 'qa',
|
);
|
||||||
'Wait Release': 'dev',
|
}
|
||||||
Pending: 'dev',
|
|
||||||
Feedback: 'qa',
|
|
||||||
Closed: 'dev',
|
|
||||||
Rejected: 'dev',
|
|
||||||
};
|
|
||||||
|
|
||||||
async enhance(
|
async enhance(
|
||||||
issue: RedmineTypes.Issue,
|
issue: RedmineTypes.Issue,
|
||||||
|
|
@ -29,7 +26,7 @@ export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
||||||
|
|
||||||
const status = issue.status.name;
|
const status = issue.status.name;
|
||||||
|
|
||||||
const fieldName = this.rules[status];
|
const fieldName = this.rules[status] || this.rules['*'] || null;
|
||||||
if (fieldName) {
|
if (fieldName) {
|
||||||
res.current_user = { ...res[fieldName] };
|
res.current_user = { ...res[fieldName] };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ export type AppConfig = {
|
||||||
redmineStatuses: StatusesConfig.Config;
|
redmineStatuses: StatusesConfig.Config;
|
||||||
redmineStatusChanges: StatusChangesConfig.Config;
|
redmineStatusChanges: StatusChangesConfig.Config;
|
||||||
redmineEccm: EccmConfig.Config;
|
redmineEccm: EccmConfig.Config;
|
||||||
|
redmineCurrentUserRules: Record<string, string>;
|
||||||
couchDb: {
|
couchDb: {
|
||||||
dbs: {
|
dbs: {
|
||||||
changes: string;
|
changes: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue