Browse Source

fix 5810 普通成员登录后查看应用异常数据范围未做限制

dev
巴林闲侠 2 years ago
parent
commit
7b6dc8cd44
  1. 67
      api/app/lib/controllers/alarm/app.js
  2. 37
      api/app/lib/utils/dataRange.js

67
api/app/lib/controllers/alarm/app.js

@ -205,21 +205,15 @@ async function apiErrorList (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
const { keyword, errType, confirmState, sustainTimeStart, sustainTimeEnd, limit, page } = ctx.query
const pepProjectSql = `
SELECT
t_pim_project.id AS id,
t_pim_project.project_name AS project_name,
t_pim_project_construction.construction_status_id AS construction_status_id,
t_pim_project_state.construction_status AS construction_status
FROM t_pim_project
LEFT JOIN t_pim_project_construction
ON t_pim_project.id = t_pim_project_construction.project_id
LEFT JOIN t_pim_project_state
ON t_pim_project_construction.construction_status_id = t_pim_project_state.id
`
const { utils: { anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs
const { keyword, errType, confirmState, sustainTimeStart, sustainTimeEnd, limit, page, pepProjectId } = ctx.query
let pomsProject = await pomsProjectRange({
ctx, pepProjectId,
keywordTarget: 'pepProject',
keyword,
})
const pomsProjectIds = pomsProject.map(p => p.id)
let findOption = {
where: {
$or: []
@ -243,16 +237,11 @@ async function apiErrorList (ctx) {
}]
}]
}
let projectRes = []
if (keyword) {
projectRes = await clickHouse.projectManage.query(`
${pepProjectSql}
WHERE project_name LIKE '%${keyword}%'`
).toPromise()
findOption.where.$or.push(
{
'$app->projectCorrelations.pep_project_id$': {
$in: projectRes.map(p => p.id)
'$app->projectCorrelations.id$': {
$in: pomsProjectIds
},
}
)
@ -263,17 +252,8 @@ async function apiErrorList (ctx) {
)
}
// if (errType) {
// if (errType == 'element') {
// findOption.where.screenshot = { $ne: null }
// } else if (errType == 'timeout') {
// } else if (errType == 'apiError') {
// findOption.where.screenshot = null
// }
// }
if (errType) {
findOption.where.type = errType
findOption.where.type = errType // element / apiError
}
if (confirmState) {
if (confirmState == 'confirmd') {
@ -306,32 +286,13 @@ async function apiErrorList (ctx) {
delete findOption.where.$or
}
const listRes = await models.AppAlarm.findAndCountAll(findOption)
if (!keyword) {
// 没有关键字筛选 查询关联的项目信息
let pepProjectIds = new Set()
for (let lr of listRes.rows) {
if (lr.app && lr.app.projectCorrelations) {
for (let p of lr.app.projectCorrelations) {
if (p.pepProjectId) {
pepProjectIds.add(p.pepProjectId)
}
}
}
}
if (pepProjectIds.size) {
projectRes = await clickHouse.projectManage.query(`
${pepProjectSql}
WHERE id IN (${[...pepProjectIds].join(',')})`
).toPromise()
}
}
for (let lr of listRes.rows) {
if (lr.app && lr.app.projectCorrelations) {
for (let p of lr.app.projectCorrelations) {
let corPepProject = projectRes.find(pr => pr.id == p.pepProjectId)
if (corPepProject) {
p.dataValues.pepProject = corPepProject
let corProjectCorrelations = pomsProject.find(pr => pr.id == p.id)
if (corProjectCorrelations) {
p.dataValues = corProjectCorrelations
}
}
}

37
api/app/lib/utils/dataRange.js

@ -14,7 +14,7 @@ module.exports = function (app, opts) {
}
}
async function anxinStrucIdRange ({ ctx, pepProjectId, keywordTarget, keyword }) {
async function pomsWithPepRangeParams ({ ctx, pepProjectId, keywordTarget, keyword }) {
const { models } = ctx.fs.dc;
const { userInfo = {} } = ctx.fs.api || {};
const { clickHouse } = ctx.app.fs
@ -82,6 +82,15 @@ module.exports = function (app, opts) {
).toPromise() :
[]
return {
pepProjectRes, bindRes,
}
}
async function anxinStrucIdRange ({ ctx, pepProjectId, keywordTarget, keyword }) {
const { clickHouse } = ctx.app.fs
const { pepProjectRes, bindRes, } = await pomsWithPepRangeParams({ ctx, pepProjectId, keywordTarget, keyword })
// 获取不重复的 安心云项目 id
const anxinProjectIds = [
@ -166,8 +175,30 @@ module.exports = function (app, opts) {
return undelStruc
}
async function pomsProjectRange ({ ctx, pepProjectId, keywordTarget, keyword }) {
const { pepProjectRes, bindRes, } = await pomsWithPepRangeParams({ ctx, pepProjectId, keywordTarget, keyword })
let pomsProject = []
for (let b of bindRes) {
if (b.pepProjectId) {
let corPepProject = pepProjectRes.find(pp => pp.id == b.pepProjectId) || {}
pomsProject.push({
...b.dataValues,
pepProject: corPepProject
})
} else {
pomsProject.push({
...b.dataValues
})
}
}
return pomsProject
}
return {
judgeSuper,
anxinStrucIdRange
judgeSuper, pomsWithPepRangeParams,
anxinStrucIdRange,
pomsProjectRange,
}
}
Loading…
Cancel
Save