Skip to content

Commit

Permalink
fix(*): update access by worklogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedorrychkov committed Dec 25, 2024
1 parent 9b2e1ec commit e8fb9a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/guards/jira.telegraf.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export class JiraTelegrafGuard extends SafeGuardInterceptor {
const request = context.switchToHttp().getRequest()

const from = update?.from || update?.message?.from
const username = from?.username

const superAdminAvailabilityList = this.customConfigService.superAdminList
.map((nickname) => nickname.toLowerCase().trim())
.filter((usernameOrId) => {
if (usernameOrId.toLowerCase().trim() === from?.username?.toLowerCase().trim()) {
if (usernameOrId.toLowerCase().trim() === username?.toLowerCase().trim()) {
return true
}

Expand All @@ -46,7 +47,7 @@ export class JiraTelegrafGuard extends SafeGuardInterceptor {
})

const jiraAvailabilityListKeys = this.customConfigService.availabilityUsersByKeys.filter((values) => {
if (values.nicknamesOrIds.includes(from?.username?.toLowerCase().trim())) {
if (values.nicknamesOrIds.includes(username?.toLowerCase().trim())) {
return true
}

Expand All @@ -61,7 +62,7 @@ export class JiraTelegrafGuard extends SafeGuardInterceptor {

const relationUserNameOrIdWithJira = this.customConfigService.relationUserNameOrIdWithJira
.filter((values) => {
if (values.nickNameOrId.toLowerCase().trim() === from?.username?.toLowerCase().trim()) {
if (values.nickNameOrId.toLowerCase().trim() === username?.toLowerCase().trim()) {
return true
}

Expand All @@ -75,7 +76,7 @@ export class JiraTelegrafGuard extends SafeGuardInterceptor {
.flatMap((value) => value)

const salaryRelationByTgAndProjectByUsername =
this.customConfigService.salaryRelationByTgAndProject?.[from?.username?.toLowerCase().trim()]
this.customConfigService.salaryRelationByTgAndProject?.[username?.toLowerCase().trim()]
const salaryRelationByTgAndProjectById =
this.customConfigService.salaryRelationByTgAndProject?.[`${from?.id}`?.toLowerCase().trim()]

Expand Down
25 changes: 23 additions & 2 deletions src/scenes/main/main.jira.scene.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,17 @@ export class MainJiraSceneService {
>,
issue: (typeof issues)[0],
) => {
const worklogs = issue.fields.worklog.worklogs
const worklogs = issue.fields.worklog.worklogs?.filter((log) => {
if (jiraConfig.isSuperAdmin) {
return true
}

const availableByEmail = jiraConfig.relationNames.includes(log.author.emailAddress)
const availableByName = jiraConfig.relationNames.includes(log.author.displayName)

return availableByEmail || availableByName
})

const projectKey = issue.fields.project.key

worklogs.forEach((log) => {
Expand Down Expand Up @@ -321,7 +331,18 @@ export class MainJiraSceneService {
.reduce((parsedIssues: any[], issue) => {
const link = `${this.jiraService.baseURL}/browse/${issue.key}`

const issuesByWorklogAuthor: Record<string, any> = issue.fields.worklog.worklogs.reduce(
const worklogs = issue.fields.worklog.worklogs?.filter((log) => {
if (jiraConfig.isSuperAdmin) {
return true
}

const availableByEmail = jiraConfig.relationNames.includes(log.author.emailAddress)
const availableByName = jiraConfig.relationNames.includes(log.author.displayName)

return availableByEmail || availableByName
})

const issuesByWorklogAuthor: Record<string, any> = worklogs.reduce(
(acc: Record<string, any>, log) => {
const author = log.author.displayName

Expand Down

0 comments on commit e8fb9a0

Please sign in to comment.