diff --git a/models/problem.js b/models/problem.js index 29b0e98..731c96f 100644 --- a/models/problem.js +++ b/models/problem.js @@ -164,6 +164,13 @@ let model = db.define('problem', { key: 'id' } }, + publicizer_id: { + type: Sequelize.INTEGER, + references: { + model: 'user', + key: 'id' + } + }, description: { type: Sequelize.TEXT }, input_format: { type: Sequelize.TEXT }, @@ -208,6 +215,7 @@ class Problem extends Model { return Problem.fromRecord(Problem.model.build(Object.assign({ title: '', user_id: '', + publicizer_id: '', description: '', input_format: '', @@ -230,6 +238,7 @@ class Problem extends Model { async loadRelationships() { this.user = await User.fromID(this.user_id); + this.publicizer = await User.fromID(this.publicizer_id); this.testdata = await TestData.fromID(this.testdata_id); } diff --git a/modules/problem.js b/modules/problem.js index b6e8d6f..371f443 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -200,6 +200,7 @@ app.get('/problem/:id', async (req, res) => { let state = await problem.getJudgeState(res.locals.user, false); problem.tags = await problem.getTags(); + await problem.loadRelationships(); res.render('problem', { problem: problem, @@ -293,6 +294,7 @@ app.post('/problem/:id/edit', async (req, res) => { } else if (id) problem.id = id; problem.user_id = res.locals.user.id; + problem.publicizer_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); if (!await problem.isAllowedEditBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); @@ -347,6 +349,7 @@ app.get('/problem/:id/import', async (req, res) => { problem.id = id; problem.new = true; problem.user_id = res.locals.user.id; + problem.publicizer_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); if (!await problem.isAllowedEditBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); @@ -379,6 +382,7 @@ app.post('/problem/:id/import', async (req, res) => { } else if (id) problem.id = id; problem.user_id = res.locals.user.id; + problem.publicizer_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); if (!await problem.isAllowedEditBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); @@ -504,6 +508,7 @@ async function setPublic(req, res, is_public) { if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。'); problem.is_public = is_public; + problem.publicizer_id = res.locals.user.id; await problem.save(); res.redirect(syzoj.utils.makeUrl(['problem', id])); diff --git a/views/problem.ejs b/views/problem.ejs index 2c60881..0c5b669 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -41,6 +41,16 @@ if (contest) { <% } %> +
@@ -74,6 +84,28 @@ if (contest) { <% } %> <% } %>
+
+ + <% if (problem.is_public) { %> + <% if (problem.publicizer) { %> + + <% } else { %> +
+ + LibreOJ 管理员 +
公开
+
+ <% } %> + <% } %> +
<% } %>