Browse Source

删除admin

release_0.0.2
巴林闲侠 2 years ago
parent
commit
590ba7e7b7
  1. 51
      api/app/lib/controllers/organization/index.js
  2. 23
      api/app/lib/controllers/project/bind.js
  3. 3
      api/app/lib/controllers/project/index.js
  4. 6
      api/app/lib/index.js
  5. 3
      api/app/lib/routes/organization/index.js
  6. 5
      api/app/lib/routes/project/index.js
  7. 19
      api/app/lib/service/clickHouseClient.js

51
api/app/lib/controllers/organization/index.js

@ -33,6 +33,10 @@ async function editUser (ctx) {
pepUserId
}
})
if (existUserRes && !existUserRes.deleted && !pepUserId) {
// 新增已存在未删除
throw '人员账号已添加'
}
let storageData = {
pepUserId,
@ -81,8 +85,8 @@ async function putUser (ctx) {
}
})
if (existUserRes && existUserRes.role.includes('admin')) {
throw '已是管理员,请先解除管理员权限'
if (existUserRes && existUserRes.role.includes('admin') && disabled) {
throw '成员不能既是管理员又是普通成员'
}
const updateData = {
@ -110,9 +114,43 @@ async function putUser (ctx) {
}
}
async function delAdmin (ctx) {
try {
const models = ctx.fs.dc.models;
const { pomsUserId } = ctx.params
const existUserRes = await models.User.findOne({
where: {
id: pomsUserId
}
})
if (existUserRes) {
let updateValues = existUserRes.dataValues
let adminIndex = updateValues.role.findIndex(r => r == 'admin')
if (adminIndex > -1) {
updateValues.role.splice(adminIndex, 1)
}
await models.User.update(updateValues, {
where: {
id: pomsUserId
}
})
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function user (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
const { role, limit, page, } = ctx.query
const excludeField = ['lastInTime', 'inTimes', 'onlineDuration', 'lastInAddress', 'deleted', 'updateTime']
@ -151,6 +189,14 @@ async function user (ctx) {
order: [['updateTime', 'DESC']]
})
// let userIds = new Set()
// for (let u of userRes.rows.concat(adminRes)) {
// userIds.add(u.pepUserId)
// }
// let userPepRes = await clickHouse.pepEmis.query(`SELECT "user"."name" FROM department_user LEFT JOIN user ON department_user.user=user.id `).toPromise()
// const userDepRes = await clickHouse.pepEmis.query(`SELECT * FROM department`).toPromise()
ctx.status = 200
ctx.body = {
admin: adminRes,
@ -169,5 +215,6 @@ module.exports = {
allDeps,
editUser,
putUser,
delAdmin,
user,
};

23
api/app/lib/controllers/project/bind.js

@ -0,0 +1,23 @@
'use strict';
async function bindAnxin2pep (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
const { name } = ctx.request.body
ctx.status = 20;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
bindAnxin2pep
};

3
api/app/lib/controllers/project/index.js

@ -20,6 +20,7 @@ async function appList (ctx) {
}
}
module.exports = {
appList
appList,
};

6
api/app/lib/index.js

@ -9,6 +9,7 @@ const socketConect = require('./service/socket')
const mqttVideoServer = require('./service/mqttServer')
const paasRequest = require('./service/paasRequest');
const authenticator = require('./middlewares/authenticator');
const clickHouseClient = require('./service/clickHouseClient')
const schedule = require('./schedule')
// const apiLog = require('./middlewares/api-log');
@ -28,6 +29,9 @@ module.exports.entry = function (app, router, opts) {
// 实例其他平台请求方法
paasRequest(app, opts)
// clickHouse 数据库 client
clickHouseClient(app, opts)
// 工具类函数
utils(app, opts)
@ -51,7 +55,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
});
const {
} = dc.models;
};

3
api/app/lib/routes/organization/index.js

@ -12,6 +12,9 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['PUT/organization/user/:pomsUserId'] = { content: '修改成员状态', visible: true };
router.put('/organization/user/:pomsUserId', organization.putUser);
app.fs.api.logAttr['DEL/organization/admin/:pomsUserId'] = { content: '删除管理员', visible: true };
router.delete('/organization/admin/:pomsUserId', organization.delAdmin);
app.fs.api.logAttr['GET/organization/user'] = { content: '获取成员列表', visible: true };
router.get('/organization/user', organization.user);
};

5
api/app/lib/routes/project/index.js

@ -1,8 +1,13 @@
'use strict';
const project = require('../../controllers/project');
const projectBind = require('../../controllers/project/bind')
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/project/app_list'] = { content: '获取应用列表', visible: true };
router.get('/project/app_list', project.appList);
app.fs.api.logAttr['POST/project/bind'] = { content: '绑定安心云、项目管理项目', visible: true };
router.post('/project/bind', projectBind.bindAnxin2pep);
};

19
api/app/lib/service/clickHouseClient.js

@ -1,13 +1,24 @@
'use strict';
const { ClickHouse } = require('clickhouse');
function factory (app, opts) {
if (opts.clickHouse) {
try {
for (let r of opts.clickHouse) {
if (r.name && r.root) {
app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }, { dataWord: r.dataWord || 'body' })
app.fs.clickHouse = {}
const { url, port, db = [] } = opts.clickHouse
for (let d of db) {
if (d.name && d.db) {
app.fs.clickHouse[d.name] = new ClickHouse({
url: url,
port: port,
debug: true,
format: "json",
config: {
database: d.db,
},
})
} else {
throw 'opts.pssaRequest 参数错误!'
throw 'opts.clickHouse 参数错误!'
}
}
} catch (error) {

Loading…
Cancel
Save