Правила определения текущего пользователя вынесены в конфиг
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/eccm-versions-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 RedmineStatusChangesConfigLoader from './status-changes.config';
|
||||
import RedmineEccmConfig from './eccm.config';
|
||||
import RedmineCurrentUserRulesConfig from './current-user-rules.config';
|
||||
|
||||
const redmineIssueEventEmitterConfig = RedmineIssueEventEmitterConfigLoader();
|
||||
const redmineStatusesConfig = RedmineStatusesConfigLoader();
|
||||
const redmineStatusChanges = RedmineStatusChangesConfigLoader();
|
||||
const redmineEccm = RedmineEccmConfig();
|
||||
const redmineCurrentUserRules = RedmineCurrentUserRulesConfig();
|
||||
|
||||
let appConfig: AppConfig;
|
||||
|
||||
|
|
@ -33,6 +35,7 @@ export default (): AppConfig => {
|
|||
redmineIssueEventEmitterConfig: redmineIssueEventEmitterConfig,
|
||||
redmineStatusChanges: redmineStatusChanges,
|
||||
redmineEccm: redmineEccm,
|
||||
redmineCurrentUserRules: redmineCurrentUserRules,
|
||||
};
|
||||
|
||||
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 { 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()
|
||||
export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
||||
name = 'current-user';
|
||||
|
||||
// TODO: Переместить правила в конфиг
|
||||
private rules: Record<string, string>;
|
||||
private logger = new Logger(CurrentUserEnhancer.name);
|
||||
|
||||
private rules = {
|
||||
New: 'dev',
|
||||
'In Progress': 'dev',
|
||||
'Re-opened': 'dev',
|
||||
'Code Review': 'cr',
|
||||
Resolved: 'qa',
|
||||
Testing: 'qa',
|
||||
'Wait Release': 'dev',
|
||||
Pending: 'dev',
|
||||
Feedback: 'qa',
|
||||
Closed: 'dev',
|
||||
Rejected: 'dev',
|
||||
};
|
||||
constructor(private configService: ConfigService) {
|
||||
this.rules = this.configService.get<Record<string, string>>(
|
||||
'redmineCurrentUserRules',
|
||||
);
|
||||
this.logger.debug(
|
||||
`Loaded rules for current user enhancer - ${JSON.stringify(this.rules)}`,
|
||||
);
|
||||
}
|
||||
|
||||
async enhance(
|
||||
issue: RedmineTypes.Issue,
|
||||
|
|
@ -29,7 +26,7 @@ export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
|||
|
||||
const status = issue.status.name;
|
||||
|
||||
const fieldName = this.rules[status];
|
||||
const fieldName = this.rules[status] || this.rules['*'] || null;
|
||||
if (fieldName) {
|
||||
res.current_user = { ...res[fieldName] };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export type AppConfig = {
|
|||
redmineStatuses: StatusesConfig.Config;
|
||||
redmineStatusChanges: StatusChangesConfig.Config;
|
||||
redmineEccm: EccmConfig.Config;
|
||||
redmineCurrentUserRules: Record<string, string>;
|
||||
couchDb: {
|
||||
dbs: {
|
||||
changes: string;
|
||||
|
|
|
|||
Loading…
Reference in a new issue