Skip to content

Commit

Permalink
fix: ordinary users can see hidden problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerminate committed Jun 11, 2018
1 parent 550ff86 commit 2ef6cca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ migrations/backup
public/uploads/*
!public/uploads/.gitkeep
package-lock.json
complete.js

# macOS

Expand Down
27 changes: 18 additions & 9 deletions complete.js
@@ -1,17 +1,26 @@
const Solution = require('./models/Solution')
// const config = require('../config')
const Problem = require('./models/Problem')
require('./config/db')

async function main () {
console.log('start')
const pid = 3335
const ac = await Solution
.find({pid, judge: 3})
.distinct('uid')
.exec()
.catch((e) => console.log(e))
console.log(ac)
console.log(ac.length)
const problems = await Problem.find({}).exec()
const arr = problems.map(async (problem, index) => {
const submit = await Solution
.find({pid: problem.pid})
.distinct('uid')
.exec()

const ac = await Solution
.find({pid: problem.pid, judge: 3})
.distinct('uid')
.exec()

problem.submit = submit.length
problem.solve = ac.length
await problem.save()
})
await Promise.all(arr)
}

main()
Expand Down
5 changes: 4 additions & 1 deletion controllers/problem.js
Expand Up @@ -5,13 +5,16 @@ const config = require('../config')
const Problem = require('../models/Problem')
const Solution = require('../models/Solution')
const logger = require('../utils/logger')
const { isLogined } = require('../utils/helper')
const { isLogined, isAdmin } = require('../utils/helper')

const preload = async (ctx, next) => {
const pid = parseInt(ctx.params.pid)
if (isNaN(pid)) ctx.throw(400, 'Pid has to be a number')
const problem = await Problem.findOne({ pid }).exec()
if (problem == null) ctx.throw(400, 'No such a problem')
if (!isAdmin(ctx.session.profile) && problem.status === config.status.Reserve) {
ctx.throw(400, 'You do not have permission to enter this problem!')
}
ctx.state.problem = problem
return next()
}
Expand Down

0 comments on commit 2ef6cca

Please sign in to comment.