From c71040fb8adde7740e8842f607e51311c45cf4c1 Mon Sep 17 00:00:00 2001 From: yulixing Date: Fri, 31 May 2019 11:37:13 +0800 Subject: [PATCH] test --- config/config.js.example | 35 +++++++++++++++++++----------- fixtures/roles.js | 2 +- init-data.js | 22 ++++++++++++------- src/controllers/games/games.js | 30 ++++++++++++++++++++----- src/controllers/games/platforms.js | 1 - src/controllers/sys/users.js | 2 -- 6 files changed, 62 insertions(+), 30 deletions(-) diff --git a/config/config.js.example b/config/config.js.example index 1471f53..614f768 100644 --- a/config/config.js.example +++ b/config/config.js.example @@ -7,16 +7,15 @@ const config = { development: { root: rootPath, app: { - name: 'garfield' + name: 'pikachu' }, host: 'http://192.168.199.210:3000', port: process.env.PORT || 2333, - secret: 'garfield_sd*3,Jd32-xd..q(jd,vHdklx2z;3', - session_name: 'sessionId_garfield', - + secret: 'pikachu_sd*3,Jd32-xd..q(jd,vHdklx2z;3', + session_name: 'sessionId_pikachu', special_sid: '58c939a11c2c7cf2653d7f07', empty_user: '000000000000000000000000', - db_admin: 'mongodb://localhost/garfield-development', + db_admin: 'mongodb://localhost/pikachu-development', db_snoopy: 'mongodb://localhost/snoopy-development', db_dalmatian: 'mongodb://localhost/dalmatian-development', db_beagle: 'mongodb://localhost/beagle-development', @@ -29,7 +28,7 @@ const config = { host: '127.0.0.1', password: '' }, - redisPublish: { + redisPublish: { port: 6379, host: '192.144.140.87', password: '' @@ -63,24 +62,29 @@ const config = { user: 'cn=admin,dc=kingsome,dc=cn', password: 'milesQWE321' }, + minigame: { + api: 'http://192.168.100.206:8000/api/', + username: 'ops-apiuser', + password: 'hhsxafTuUtVV' + }, jwtSecret: 'OA3A$0X6*OsD*6oE', pay_record: 'http://192.168.100.23:7051/webapp/index.php', - logs_path: '/Users/zhl/Documents/logs/garfield' + logs_path: 'E:logsgarfield' }, production: { root: rootPath, app: { - name: 'garfield' + name: 'pikachu' }, host: 'http://192.168.199.210:3000', - port: process.env.PORT || 3000, + port: process.env.PORT || 2333, secret: 'garfield_sd*3,Jd32-xd..q(jd,vHdklx2z;3', session_name: 'sessionId_garfield', special_sid: '58c939a11c2c7cf2653d7f07', empty_user: '000000000000000000000000', - db_admin: 'mongodb://localhost/garfield-production', + db_admin: 'mongodb://localhost/pikachu-production', db_snoopy: 'mongodb://localhost/snoopy-production', db_dalmatian: 'mongodb://localhost/dalmatian-production', db_beagle: 'mongodb://localhost/beagle-production', @@ -90,12 +94,12 @@ const config = { short_url_base: 'https://wechat-test.kingsome.cn/s/', redis: { port: 6379, - host: '127.0.0.1', + host: '10.10.9.3', password: '' }, redisPublish: { port: 6379, - host: '192.144.140.87', + host: '10.10.9.3', password: '' }, cos: { @@ -127,9 +131,14 @@ const config = { user: 'cn=admin,dc=kingsome,dc=cn', password: 'milesQWE321' }, + minigame: { + api: 'http://192.168.100.206:8000/api/', + username: 'ops-apiuser', + password: 'hhsxafTuUtVV' + }, jwtSecret: 'OA3A$0X6*OsD*6oE', pay_record: 'http://192.168.100.23:7051/webapp/index.php', - logs_path: '/var/logs' + logs_path: 'E:logsgarfield' } }; diff --git a/fixtures/roles.js b/fixtures/roles.js index 1b8b5d5..931bc6a 100644 --- a/fixtures/roles.js +++ b/fixtures/roles.js @@ -27,6 +27,6 @@ exports.roles = [ updatedAt: ISODate('2019-05-16T03:46:20.316Z'), __v: 0, basePermissionTable: - '{"games":{"name":"games","label":"游戏列表","permission":"writeable"},"settings":{"name":"settings","label":"配置项管理","permission":"writeable"},"users":{"name":"users","label":"用户列表","permission":"writeable"},"permission":{"name":"permission","label":"权限管理","permission":"writeable"},"logs":{"name":"logs","label":"操作日志","permission":"writeable"},"dics":{"name":"dics","label":"字典","permission":"writeable"},"data":{"name":"data","label":"数据查询","permission":"writeable"}}' + '{"games":{"name":"games","label":"游戏列表","permission":"writeable"},"settings":{"name":"settings","label":"配置项管理","permission":"writeable"},"platforms":{"name":"platforms","label":"平台管理","permission":"writeable"},"users":{"name":"users","label":"用户列表","permission":"writeable"},"permission":{"name":"permission","label":"权限管理","permission":"writeable"},"logs":{"name":"logs","label":"操作日志","permission":"writeable"}}' } ]; diff --git a/init-data.js b/init-data.js index 575ce37..e1d7342 100644 --- a/init-data.js +++ b/init-data.js @@ -7,12 +7,18 @@ const fixturesDir = path.join(config.root, '/fixtures'); const platforms = require('./fixtures/platforms'); -// fixtures.load(__dirname + '/fixtures/platforms.js', function(err) { -// if (err) throw err; -// }); -// fixtures.load(__dirname + '/fixtures/roles.js', function(err) { -// if (err) throw err; -// }); -fixtures.load(__dirname + '/fixtures/system_dics.js', function(err) { - if (err) throw err; +fixtures.clear(function(err) { + if (!err) { + fixtures.load(__dirname + '/fixtures/platforms.js', function(err) { + if (err) throw err; + }); + fixtures.load(__dirname + '/fixtures/roles.js', function(err) { + if (err) throw err; + }); + fixtures.load(__dirname + '/fixtures/system_dics.js', function(err) { + if (err) throw err; + }); + } else { + throw err; + } }); diff --git a/src/controllers/games/games.js b/src/controllers/games/games.js index 618fd37..c27097e 100644 --- a/src/controllers/games/games.js +++ b/src/controllers/games/games.js @@ -29,7 +29,8 @@ router.get('/list', async (req, res, next) => { return ( userPerms.includes(`${uid}-readable`) || userPerms.includes(`${uid}-edit`) || - userPerms.includes(`${uid}-publish`) + userPerms.includes(`${uid}-publish`) || + userPerms.includes(`games-writeable`) ); }); } @@ -129,7 +130,8 @@ router.post('/update', async (req, res, next) => { // 权限判断 const hasPerm = req.user.permissions.includes(`${req.body._id}-edit`) || - req.user.permissions.includes(`${req.body._id}-publish`); + req.user.permissions.includes(`${req.body._id}-publish`) || + req.user.permissions.includes(`games-writeable`); if (!hasPerm) { res.status(403).send({ errcode: 1, @@ -214,7 +216,8 @@ router.post('/create-ftp', async (req, res, next) => { // 权限判断 const hasPerm = req.user.permissions.includes(`${req.body.uid}-edit`) || - req.user.permissions.includes(`${req.body.uid}-publish`); + req.user.permissions.includes(`${req.body.uid}-publish`) || + req.user.permissions.includes(`games-writeable`); if (!hasPerm) { res.status(403).send({ errcode: 1, @@ -234,7 +237,23 @@ router.post('/create-ftp', async (req, res, next) => { errcode: 1, errmsg: '游戏已删除或不存在!' }); + return; } + + const platforms = search.platforms; + for (let i = 0; i < platforms.length; i++) { + if ( + platforms[i].platform.platform_id === + body.platformInfo.platform.platform_id + ) { + res.send({ + errcode: 1, + errmsg: '平台已存在!' + }); + return; + } + } + const save = await GameInfo.updateOne( { game_id: body.game_id, @@ -293,6 +312,7 @@ router.post('/create-ftp', async (req, res, next) => { errcode: 1, errmsg: '创建ftp账号时发生错误' }); + return; } } catch (err) { next(err); @@ -306,7 +326,8 @@ router.post('/update-ftp', async (req, res, next) => { // 权限判断 const hasPerm = req.user.permissions.includes(`${req.body.uid}-edit`) || - req.user.permissions.includes(`${req.body.uid}-publish`); + req.user.permissions.includes(`${req.body.uid}-publish`) || + req.user.permissions.includes(`games-writeable`); if (!hasPerm) { res.status(403).send({ errcode: 1, @@ -323,7 +344,6 @@ router.post('/update-ftp', async (req, res, next) => { deleted: false }); if (search) { - console.log(search); const platforms = search.platforms; for (let i = 0; i < platforms.length; i++) { if (platforms[i].platform.name_en === body.platform) { diff --git a/src/controllers/games/platforms.js b/src/controllers/games/platforms.js index 41766ae..707791d 100644 --- a/src/controllers/games/platforms.js +++ b/src/controllers/games/platforms.js @@ -68,7 +68,6 @@ router.post('/edit', async (req, res, next) => { const body = req.body; try { const search = await Platform.findOne({ platform_id: body.platform_id }); - console.log(search); if (search) { const result = await Platform.updateOne( { platform_id: body.platform_id }, diff --git a/src/controllers/sys/users.js b/src/controllers/sys/users.js index 3471077..aecffcf 100644 --- a/src/controllers/sys/users.js +++ b/src/controllers/sys/users.js @@ -147,7 +147,6 @@ router.post('/save', async (req, res, next) => { return; } const body = req.body; - console.log(body); const dn = `cn=${body.fullname},ou=people,dc=kingsome,dc=cn`; const uidNumber = randomUid(); const entry = { @@ -213,7 +212,6 @@ router.post('/del', async (req, res, next) => { return; } const body = req.body; - console.log(body); const dn = `cn=${body.fullname},ou=people,dc=kingsome,dc=cn`; const client = ldap.createClient({ url: config.ldap.url