Browse Source

Show problem authors

Migration (SQLite):
`ALTER TABLE problem ADD COLUMN publicizer_id INTEGER REFERENCES user (id);`
master
Pisces000221 8 years ago
parent
commit
084a23208a
  1. 9
      models/problem.js
  2. 5
      modules/problem.js
  3. 32
      views/problem.ejs

9
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);
}

5
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]));

32
views/problem.ejs

@ -41,6 +41,16 @@ if (contest) {
<% } %>
</div>
</div>
<!--<p>
<img style="vertical-align: middle;" src="//cn.gravatar.com/avatar/098be10e0980598d81978267ac70c1fd?s=64&amp;d=mm" width="32" height="32">
<a href="/user/1">Menci</a>
上传
,由
<img style="vertical-align: middle;" src="//cn.gravatar.com/avatar/7d3767f80c1d98af3197062a55d1a6ee?s=64&amp;d=mm" width="32" height="32">
<a href="/user/1">samzhang</a>
公开
</p>-->
<div class="ui grid">
<div class="row">
<div class="column">
@ -74,6 +84,28 @@ if (contest) {
<% } %>
<% } %>
</div>
<div class="ui large labels" style="float: right; vertical-align: middle">
<div class="ui basic image label" style="font-size: 1.1em; margin-right: 0;">
<img src="<%= syzoj.utils.gravatar(problem.user.email, 64) %>">
<a href="<%= syzoj.utils.makeUrl(['user', problem.user_id]) %>"><%= problem.user.username %></a>
<div class="detail">上传</div>
</div>
<% if (problem.is_public) { %>
<% if (problem.publicizer) { %>
<div class="ui basic image label" style="font-size: 1.1em; margin-left: 0.3em; margin-right: 0;">
<img src="<%= syzoj.utils.gravatar(problem.publicizer.email, 64) %>">
<a href="<%= syzoj.utils.makeUrl(['user', problem.publicizer_id]) %>"><%= problem.publicizer.username %></a>
<div class="detail">公开</div>
</div>
<% } else { %>
<div class="ui basic image label" style="font-size: 1.1em; margin-left: 0.3em; margin-right: 0;">
<img src="<%= syzoj.utils.gravatar('', 64) %>">
<a>LibreOJ 管理员</a>
<div class="detail">公开</div>
</div>
<% } %>
<% } %>
</div>
<% } %>
</div>
</div>

Loading…
Cancel
Save