core: add maintainer field for doc (#101)

This commit is contained in:
undefined committed 2021-05-01 12:14:11 +08:00
1 parent 7bde6a922c
commit da32c79f21
24 files changed
+85 -74

No files matched your search

+5 -5
View File
@@ -100,7 +100,7 @@ class ContestDetailHandler extends ContestHandler {
@param('tid', Types.ObjectID)
async postDelete(domainId: string, tid: ObjectID) {
const tdoc = await contest.get(domainId, tid);
if (tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_CONTEST);
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_CONTEST);
await contest.del(domainId, tid);
this.response.redirect = this.url('contest_main');
}
@@ -110,7 +110,7 @@ class ContestBoardcastHandler extends ContestHandler {
@param('tid', Types.ObjectID)
async get(domainId: string, tid: ObjectID) {
const tdoc = await contest.get(domainId, tid);
if (tdoc.owner !== this.user._id) throw new PermissionError('Boardcast Message');
if (!this.user.own(tdoc)) throw new PermissionError('Boardcast Message');
const path = [
['Hydro', 'homepage'],
['contest_main', 'contest_main'],
@@ -125,7 +125,7 @@ class ContestBoardcastHandler extends ContestHandler {
@param('content', Types.Content)
async post(domainId: string, tid: ObjectID, content: string) {
const tdoc = await contest.get(domainId, tid);
if (tdoc.owner !== this.user._id) throw new PermissionError('Boardcast Message');
if (!this.user.own(tdoc)) throw new PermissionError('Boardcast Message');
const tsdocs = await contest.getMultiStatus(domainId, { docId: tid }).toArray();
const uids: number[] = Array.from(new Set(tsdocs.map((tsdoc) => tsdoc.uid)));
await Promise.all(
@@ -176,7 +176,7 @@ class ContestEditHandler extends ContestHandler {
@param('tid', Types.ObjectID)
async prepare(domainId: string, tid: ObjectID) {
this.tdoc = await contest.get(domainId, tid);
if (this.tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_CONTEST);
if (!this.user.own(this.tdoc)) this.checkPerm(PERM.PERM_EDIT_CONTEST);
else this.checkPerm(PERM.PERM_EDIT_CONTEST_SELF);
}
@@ -294,7 +294,7 @@ export class ContestProblemFileDownloadHandler extends ContestProblemHandler {
@param('filename', Types.Name)
@param('noDisposition', Types.Boolean)
async get(domainId: string, type = 'additional_file', filename: string, noDisposition = false) {
if (type === 'testdata' && this.user._id !== this.pdoc.owner) this.checkPerm(PERM.PERM_READ_PROBLEM_DATA);
if (type === 'testdata' && !this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_READ_PROBLEM_DATA);
this.response.redirect = await storage.signDownloadLink(
`problem/${this.pdoc.domainId}/${this.pdoc.docId}/${type}/${filename}`,
noDisposition ? undefined : filename, false, 'user',
+8 -8
View File
@@ -230,7 +230,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
await this.limitRate('add_discussion', 3600, 60);
await discussion.addTailReply(domainId, drid, this.user._id, content, this.request.ip);
const str = JSON.stringify({ message: '{0} replied to discussion reply {1}/{2}.', params: [this.user._id, domainId, drid] });
if (this.drdoc.owner !== this.user._id) await message.send(1, this.drdoc.owner, str);
if (!this.user.own(this.drdoc)) await message.send(1, this.drdoc.owner, str);
this.back();
}
@@ -238,7 +238,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
@param('content', Types.Content)
async postEditReply(domainId: string, drid: ObjectID, content: string) {
this.checkPerm(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
if (this.drdoc.owner !== this.user._id) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
if (!this.user.own(this.drdoc)) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
await discussion.editReply(domainId, drid, content);
await oplog.add({
...this.drdoc, operator: this.user._id, operateIp: this.request.ip, type: 'edit',
@@ -248,9 +248,9 @@ class DiscussionDetailHandler extends DiscussionHandler {
@param('drid', Types.ObjectID)
async postDeleteReply(domainId: string, drid: ObjectID) {
if (!(this.ddoc.owner === this.user._id
if (!(this.user.own(this.ddoc)
&& this.user.hasPerm(PERM.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION))) {
if (this.drdoc.owner !== this.user._id) {
if (!this.user.own(this.drdoc)) {
this.checkPerm(PERM.PERM_DELETE_DISCUSSION_REPLY);
} else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF);
}
@@ -266,7 +266,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
@param('content', Types.Content)
async postEditTailReply(domainId: string, drid: ObjectID, drrid: ObjectID, content: string) {
this.checkPerm(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
if (this.drrdoc.owner !== this.user._id) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
if (!this.user.own(this.drrdoc)) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
await discussion.editTailReply(domainId, drid, drrid, content);
// TODO: history?
await oplog.add({
@@ -278,7 +278,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
@param('drid', Types.ObjectID)
@param('drrid', Types.ObjectID)
async postDeleteTailReply(domainId: string, drid: ObjectID, drrid: ObjectID) {
if (this.drrdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION_REPLY);
if (!this.user.own(this.drrdoc)) this.checkPerm(PERM.PERM_DELETE_DISCUSSION_REPLY);
await discussion.delTailReply(domainId, drid, drrid);
await oplog.add({
...this.drrdoc, operator: this.user._id, operateIp: this.request.ip, type: 'delete',
@@ -342,7 +342,7 @@ class DiscussionEditHandler extends DiscussionHandler {
domainId: string, did: ObjectID, title: string, content: string,
highlight = false, pin = false,
) {
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_DISCUSSION);
if (!this.user.own(this.ddoc)) this.checkPerm(PERM.PERM_EDIT_DISCUSSION);
else this.checkPerm(PERM.PERM_EDIT_DISCUSSION_SELF);
if (!this.user.hasPerm(PERM.PERM_HIGHLIGHT_DISCUSSION)) highlight = this.ddoc.highlight;
if (!this.user.hasPerm(PERM.PERM_PIN_DISCUSSION)) pin = this.ddoc.pin;
@@ -356,7 +356,7 @@ class DiscussionEditHandler extends DiscussionHandler {
@param('did', Types.ObjectID)
async postDelete(domainId: string, did: ObjectID) {
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION);
if (!this.user.own(this.ddoc)) this.checkPerm(PERM.PERM_DELETE_DISCUSSION);
else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF);
await discussion.del(domainId, did);
await oplog.add({
+3 -3
View File
@@ -112,7 +112,7 @@ class HomeworkDetailHandler extends HomeworkHandler {
@param('tid', Types.ObjectID)
async postDelete(domainId: string, tid: ObjectID) {
const tdoc = await contest.get(domainId, tid, document.TYPE_HOMEWORK);
if (tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
await contest.del(domainId, tid, document.TYPE_HOMEWORK);
this.response.redirect = this.url('homework_main');
}
@@ -268,7 +268,7 @@ class HomeworkEditHandler extends HomeworkHandler {
@param('tid', Types.ObjectID)
async get(domainId: string, tid: ObjectID) {
const tdoc = await contest.get(domainId, tid, document.TYPE_HOMEWORK);
if (tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
else this.checkPerm(PERM.PERM_EDIT_HOMEWORK_SELF);
const extensionDays = Math.round(
(tdoc.endAt.getTime() - tdoc.penaltySince.getTime()) / 36000 / 24,
@@ -316,7 +316,7 @@ class HomeworkEditHandler extends HomeworkHandler {
return i;
});
const tdoc = await contest.get(domainId, tid, document.TYPE_HOMEWORK);
if (tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
if (!this.user.own(this.tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
else this.checkPerm(PERM.PERM_EDIT_HOMEWORK_SELF);
let beginAt;
let penaltySince;
+15 -15
View File
@@ -124,7 +124,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid);
if (pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop
await problem.del(domainId, pid);
}
@@ -136,7 +136,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid);
if (pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop
await problem.edit(domainId, pid, { hidden: true });
}
@@ -148,7 +148,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid);
if (pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop
await problem.edit(domainId, pid, { hidden: false });
}
@@ -183,7 +183,7 @@ export class ProblemDetailHandler extends ProblemHandler {
this.response.template = 'problem_detail.html';
this.pdoc = await problem.get(domainId, pid, this.user._id);
if (!this.pdoc) throw new ProblemNotFoundError(domainId, pid);
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
if (this.pdoc.hidden && !this.user.own(this.pdoc)) {
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
}
await bus.serial('problem/get', this.pdoc, this);
@@ -230,7 +230,7 @@ export class ProblemDetailHandler extends ProblemHandler {
}
async postDelete() {
if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
await problem.del(this.pdoc.domainId, this.pdoc.docId);
this.response.redirect = this.url('problem_main');
}
@@ -338,7 +338,7 @@ export class ProblemStatisticsHandler extends ProblemDetailHandler {
export class ProblemManageHandler extends ProblemDetailHandler {
async prepare() {
if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
else this.checkPerm(PERM.PERM_EDIT_PROBLEM_SELF);
}
}
@@ -379,7 +379,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@param('testdata', Types.Boolean)
@param('additional_file', Types.Boolean)
async get(domainId: string, getTestdata = true, getAdditionalFile = true) {
const canReadData = this.user._id === this.pdoc.owner || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
const canReadData = !this.user.own(this.pdoc) || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
this.response.body.testdata = (getTestdata && canReadData) ? this.pdoc.data : [];
this.response.body.additional_file = (getAdditionalFile ? this.pdoc.additional_file : []);
this.response.template = 'problem_files.html';
@@ -388,7 +388,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@post('files', Types.Set)
@post('type', Types.Range(['testdata', 'additional_file']), true)
async postGetLinks(domainId: string, files: Set<string>, type = 'testdata') {
if (type === 'testdata' && this.user._id !== this.pdoc.owner) {
if (type === 'testdata' && !this.user.own(this.pdoc)) {
this.checkPerm(PERM.PERM_READ_PROBLEM_DATA);
}
const links = {};
@@ -408,7 +408,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
if (!this.request.files.file) throw new ValidationError('file');
if (!filename) filename = this.request.files.file.name || String.random(16);
if (filename.includes('/')) throw new ValidationError('filename', 'Bad filename');
if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (filename.endsWith('.zip')) {
const zip = new AdmZip(this.request.files.file.path);
const entries = zip.getEntries();
@@ -433,7 +433,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@post('files', Types.Array)
@post('type', Types.Range(['testdata', 'additional_file']), true)
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (type === 'testdata') await problem.delTestdata(domainId, this.pdoc.docId, files);
else await problem.delAdditionalFile(domainId, this.pdoc.docId, files);
this.back();
@@ -445,7 +445,7 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler {
@param('filename', Types.Name)
@param('noDisposition', Types.Boolean)
async get(domainId: string, type = 'additional_file', filename: string, noDisposition = false) {
if (type === 'testdata' && this.user._id !== this.pdoc.owner) this.checkPerm(PERM.PERM_READ_PROBLEM_DATA);
if (type === 'testdata' && !this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_READ_PROBLEM_DATA);
this.response.redirect = await storage.signDownloadLink(
`problem/${this.pdoc.domainId}/${this.pdoc.docId}/${type}/${filename}`,
noDisposition ? undefined : filename, false, 'user',
@@ -496,7 +496,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
@param('psid', Types.ObjectID)
async postEditSolution(domainId: string, content: string, psid: ObjectID) {
let psdoc = await solution.get(domainId, psid);
if (psdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION);
if (!this.user.own(psdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION);
else this.checkPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION_SELF);
psdoc = await solution.edit(domainId, psdoc.docId, content);
this.back({ psdoc });
@@ -505,7 +505,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
@param('psid', Types.ObjectID)
async postDeleteSolution(domainId: string, psid: ObjectID) {
const psdoc = await solution.get(domainId, psid);
if (psdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_PROBLEM_SOLUTION);
if (!this.user.own(psdoc)) this.checkPerm(PERM.PERM_DELETE_PROBLEM_SOLUTION);
else this.checkPerm(PERM.PERM_DELETE_PROBLEM_SOLUTION_SELF);
await solution.del(domainId, psdoc.docId);
this.back();
@@ -526,7 +526,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
async postEditReply(domainId: string, psid: ObjectID, psrid: ObjectID, content: string) {
const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid);
if ((!psdoc) || psdoc.parentId !== this.pdoc.docId) throw new SolutionNotFoundError(domainId, psid);
if (!(psrdoc.owner === this.user._id
if (!(!this.user.own(psrdoc)
&& this.user.hasPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION_REPLY_SELF))) {
throw new PermissionError(PERM.PERM_EDIT_PROBLEM_SOLUTION_REPLY_SELF);
}
@@ -539,7 +539,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
async postDeleteReply(domainId: string, psid: ObjectID, psrid: ObjectID) {
const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid);
if ((!psdoc) || psdoc.parentId !== this.pdoc.docId) throw new SolutionNotFoundError(psid);
if (!(psrdoc.owner === this.user._id
if (!(!this.user.own(psrdoc)
&& this.user.hasPerm(PERM.PERM_DELETE_PROBLEM_SOLUTION_REPLY_SELF))) {
this.checkPerm(PERM.PERM_DELETE_PROBLEM_SOLUTION_REPLY);
}
+1 -1
View File
@@ -99,7 +99,7 @@ class RecordDetailHandler extends RecordHandler {
if (!(pdoc && this.user.hasPerm(PERM.PERM_VIEW_PROBLEM))) {
pdoc = problem.create(pdoc?.docId || 0, pdoc?.pid || '*');
}
if (!rdoc.contest && pdoc.hidden && pdoc.owner !== this.user._id) {
if (!rdoc.contest && pdoc.hidden && !this.user.own(pdoc)) {
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) {
pdoc = problem.create(pdoc.docId, pdoc.pid);
}
+2 -2
View File
@@ -34,10 +34,10 @@ export class ProblemSendHandler extends Handler {
const pids = new Set<number>();
for (const key in pdocs) {
pids.add(pdocs[key].docId);
if (pdocs[key].hidden && !getHidden && pdocs[key].owner !== this.user._id) {
if (pdocs[key].hidden && !getHidden && !this.user.own(pdocs[key])) {
throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
}
if (!getData && pdocs[key].owner !== this.user._id) {
if (!getData && !this.user.own(pdocs[key])) {
throw new PermissionError(PERM.PERM_READ_PROBLEM_DATA);
}
}
+2 -2
View File
@@ -161,7 +161,7 @@ class TrainingDetailHandler extends Handler {
@param('tid', Types.ObjectID)
async postDelete(domainId: string, tid: ObjectID) {
const tdoc = await training.get(domainId, tid);
if (tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_TRAINING);
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_TRAINING);
await training.del(domainId, tid);
this.response.redirect = this.url('training_main');
}
@@ -205,7 +205,7 @@ class TrainingEditHandler extends Handler {
@param('tid', Types.ObjectID)
async prepare(domainId: string, tid: ObjectID) {
this.tdoc = await training.get(domainId, tid);
if (this.tdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_TRAINING);
if (!this.user.own(this.tdoc)) this.checkPerm(PERM.PERM_EDIT_TRAINING);
else this.checkPerm(PERM.PERM_EDIT_TRAINING_SELF);
}
+7 -5
View File
@@ -89,6 +89,7 @@ export interface User extends Record<string, any> {
perm: bigint,
scope: bigint,
role: string,
own<T extends { owner: number, maintainer?: number[] }>(doc: T): boolean;
hasPerm: (...perm: bigint[]) => boolean,
hasPriv: (...priv: number[]) => boolean,
checkPassword: (password: string) => void,
@@ -171,11 +172,12 @@ export type ContentNode = PlainContentNode | TextContentNode | SampleContentNode
export type Content = string | ContentNode[] | Record<string, ContentNode[]>;
export interface Document {
_id: ObjectID,
docId: any,
docType: number,
domainId: string,
owner: number,
_id: ObjectID;
docId: any;
docType: number;
domainId: string;
owner: number;
maintainer?: number[];
}
declare module './model/problem' {
+14 -5
View File
@@ -65,8 +65,17 @@ class User implements _User {
for (const key in setting.DOMAIN_USER_SETTINGS_BY_KEY) {
this[key] = dudoc[key] ?? setting.DOMAIN_USER_SETTINGS_BY_KEY[key].value;
}
}
bus.serial('user/get', this);
async init() {
await bus.serial('user/get', this);
return this;
}
own<T extends { owner: number, maintainer?: number[] }>(doc: T, exact = false) {
return exact
? doc.owner === this._id
: doc.owner === this._id || (doc.maintainer || []).includes(this._id);
}
hasPerm(...perm: bigint[]) {
@@ -122,7 +131,7 @@ class UserModel {
if (!udoc) return null;
const dudoc = await domain.getDomainUser(domainId, udoc);
if (typeof scope === 'string') scope = BigInt(scope);
return new User(udoc, dudoc, scope);
return new UserModel.User(udoc, dudoc, scope).init();
}
static async getList(domainId: string, uids: number[]): Promise<Udict> {
@@ -143,7 +152,7 @@ class UserModel {
: await coll.findOne({ unameLower });
if (!udoc) return null;
const dudoc = await domain.getDomainUser(domainId, udoc);
return new UserModel.User(udoc, dudoc);
return new UserModel.User(udoc, dudoc).init();
}
@ArgMethod
@@ -156,7 +165,7 @@ class UserModel {
: await coll.findOne({ mailLower });
if (!udoc) return null;
const dudoc = await domain.getDomainUser(domainId, udoc);
return new UserModel.User(udoc, dudoc);
return new UserModel.User(udoc, dudoc).init();
}
@ArgMethod
@@ -233,7 +242,7 @@ class UserModel {
@ArgMethod
static async getPrefixList(domainId: string, prefix: string, limit: number = 50) {
prefix = prefix.toLowerCase();
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
const $regex = new RegExp(`^${escapeRegExp(prefix)}`, 'gmi');
const uids = await coll.find({ unameLower: { $regex } })
.limit(limit).map((doc) => doc._id).toArray();
const users = [];
@@ -86,12 +86,12 @@
data-form="{{ {operation: reply_post_op, drid: doc._id}|json }}"
><span class="icon icon-reply"></span></a>
{% endif %}
{% if (handler.user.hasPerm(comment_edit_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(comment_edit_perm) %}
{% if (handler.user.hasPerm(comment_edit_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(comment_edit_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Edit') }}" name="dczcomments__op-edit-comment"
data-form="{{ {operation: comment_edit_op, drid: doc._id}|json }}"
><span class="icon icon-edit"></span></a>
{% endif %}
{% if (handler.user.hasPerm(comment_delete_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(comment_delete_perm) %}
{% if (handler.user.hasPerm(comment_delete_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(comment_delete_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Delete') }}" name="dczcomments__op-delete-comment"
data-form="{{ {operation: comment_delete_op, drid: doc._id}|json }}"
><span class="icon icon-delete"></span></a>
@@ -120,12 +120,12 @@
{% if handler.user.hasPerm(reply_post_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Reply') }}" name="dczcomments__op-reply-reply"><span class="icon icon-reply"></span></a>
{% endif %}
{% if doc.owner == handler.user._id or handler.user.hasPerm(reply_edit_perm) %}
{% if handler.user.own(doc) or handler.user.hasPerm(reply_edit_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Edit') }}" name="dczcomments__op-edit-reply"
data-form="{{ {operation: reply_edit_op, drid: doc._id, drrid: rdoc._id}|json }}"
><span class="icon icon-edit"></span></a>
{% endif %}
{% if doc.owner == handler.user._id or handler.user.hasPerm(reply_delete_perm) %}
{% if handler.user.own(doc) or handler.user.hasPerm(reply_delete_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Delete') }}" name="dczcomments__op-delete-reply"
data-form="{{ {operation: reply_delete_op, drid: doc._id, drrid: rdoc._id}|json }}"
><span class="icon icon-delete"></span></a>
@@ -118,12 +118,12 @@
data-form="{{ {operation: reply_post_op, psid: doc._id}|json }}"
><span class="icon icon-reply"></span></a>
{% endif %}
{% if (handler.user.hasPerm(comment_edit_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(comment_edit_perm) %}
{% if (handler.user.hasPerm(comment_edit_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(comment_edit_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Edit') }}" name="dczcomments__op-edit-comment"
data-form="{{ {operation: comment_edit_op, psid: doc._id}|json }}"
><span class="icon icon-edit"></span></a>
{% endif %}
{% if (handler.user.hasPerm(comment_delete_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(comment_delete_perm) %}
{% if (handler.user.hasPerm(comment_delete_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(comment_delete_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Delete') }}" name="dczcomments__op-delete-comment"
data-form="{{ {operation: comment_delete_op, psid: doc._id}|json }}"
><span class="icon icon-delete"></span></a>
@@ -148,12 +148,12 @@
{% if handler.user.hasPerm(reply_post_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Reply') }}" name="dczcomments__op-reply-reply"><span class="icon icon-reply"></span></a>
{% endif %}
{% if (handler.user.hasPerm(reply_edit_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(reply_edit_perm) %}
{% if (handler.user.hasPerm(reply_edit_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(reply_edit_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Edit') }}" name="dczcomments__op-edit-reply"
data-form="{{ {operation: reply_edit_op, psid: doc._id, psrid: rdoc._id}|json }}"
><span class="icon icon-edit"></span></a>
{% endif %}
{% if (handler.user.hasPerm(reply_delete_self_perm) and doc.owner == handler.user._id) or handler.user.hasPerm(reply_delete_perm) %}
{% if (handler.user.hasPerm(reply_delete_self_perm) and handler.user.own(doc)) or handler.user.hasPerm(reply_delete_perm) %}
<a href="javascript:;" data-tooltip="{{ _('Delete') }}" name="dczcomments__op-delete-reply"
data-form="{{ {operation: reply_delete_op, psid: doc._id, psrid: rdoc._id}|json }}"
><span class="icon icon-delete"></span></a>
@@ -79,7 +79,7 @@
<button type="submit" class="rounded primary button">
{{ _('Update') }}
</button>
{% if tdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_CONTEST) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_CONTEST) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>
@@ -29,7 +29,7 @@
</div>
</div>
<ul class="section__footer supplementary dot list">
{% if handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION) or (ddoc.owner == handler.user._id and handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION_SELF)) %}
{% if handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION) or (handler.user.own(ddoc) and handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION_SELF)) %}
<li>
<a href="{{ url('discussion_edit', did=ddoc.docId) }}"><span class="icon icon-edit"></span> {{ _('Edit') }}</a>
</li>
@@ -71,12 +71,12 @@
reply_delete_op = 'delete_tail_reply',
comment_post_perm = perm.PERM_REPLY_DISCUSSION,
comment_edit_perm = perm.PERM_NEVER,
comment_delete_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION if ddoc.owner == handler.user._id else perm.PERM_DELETE_DISCUSSION_REPLY,
comment_delete_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION if handler.user.own(ddoc) else perm.PERM_DELETE_DISCUSSION_REPLY,
comment_edit_self_perm = perm.PERM_EDIT_DISCUSSION_REPLY_SELF,
comment_delete_self_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF,
reply_post_perm = perm.PERM_REPLY_DISCUSSION,
reply_edit_perm = perm.PERM_NEVER,
reply_delete_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION if ddoc.owner == handler.user._id else perm.PERM_DELETE_DISCUSSION_REPLY,
reply_delete_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION if handler.user.own(ddoc) else perm.PERM_DELETE_DISCUSSION_REPLY,
reply_edit_self_perm = perm.PERM_EDIT_DISCUSSION_REPLY_SELF,
reply_delete_self_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF
) }}
@@ -11,7 +11,7 @@
<button name="operation" value="update" type="submit" class="rounded primary button">
{{ _('Update') }} (Ctrl+Enter)
</button>
{% if ddoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_DELETE_DISCUSSION) %}
{% if handler.user.own(ddoc) or handler.user.hasPerm(perm.PERM_DELETE_DISCUSSION) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>
@@ -85,7 +85,7 @@
<button type="submit" class="rounded primary button">
{{ _('Update') }}
</button>
{% if tdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_HOMEWORK) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_HOMEWORK) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>
@@ -52,7 +52,7 @@
<span class="icon icon-statistics"></span> {{ _('Scoreboard (Hidden)') }}
</a></li>
{% endif %}
{% if user._id == tdoc.owner or handler.user.hasPerm(perm.PERM_EDIT_CONTEST) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_CONTEST) %}
<li class="menu__item"><a class="menu__link" href="{{ url('contest_edit', tid=tdoc.docId) }}">
<span class="icon icon-edit"></span> {{ _('Edit Contest') }}
</a></li>
@@ -52,7 +52,7 @@
<span class="icon icon-statistics"></span> {{ _('Scoreboard (Hidden)') }}
</a></li>
{% endif %}
{% if tdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_HOMEWORK) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_HOMEWORK) %}
<li class="menu__item"><a class="menu__link" href="{{ url('homework_edit', tid=tdoc.docId) }}">
<span class="icon icon-edit"></span> {{ _('Edit Homework') }}
</a></li>
@@ -28,7 +28,7 @@
<span class="icon icon-send"></span> {{ _('Open in Problem Set') }}
</a></li>
{% endif %}
{% if pdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li>
<li class="menu__item"><a class="menu__link{% if page_name == 'problem_edit' %} active{% endif %}" href="{{ url('problem_edit', pid=pdoc.pid|default(pdoc.docId)) }}">
<span class="icon icon-edit"></span> {{ _('Edit') }}
@@ -28,7 +28,7 @@
<span class="icon icon-send"></span> {{ _('Open in Problem Set') }}
</a></li>
{% endif %}
{% if pdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li>
<li class="menu__item"><a class="menu__link{% if page_name == 'problem_edit' %} active{% endif %}" href="{{ url('problem_edit', pid=pdoc.pid|default(pdoc.docId)) }}">
<span class="icon icon-edit"></span> {{ _('Edit') }}
@@ -78,13 +78,13 @@
<li class="menu__item"><a class="menu__link{% if page_name == 'problem_files' %} active{% endif %}" href="{{ url('problem_files', pid=pdoc.pid|default(pdoc.docId)) }}">
<span class="icon icon-file"></span> {{ _('Files') }}
</a></li>
{% if (handler.user._id == pdoc.owner and handler.user.hasPerm(perm.PERM_EDIT_PROBLEM_SELF)) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if (handler.user.own(pdoc) and handler.user.hasPerm(perm.PERM_EDIT_PROBLEM_SELF)) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li>
<li class="menu__item"><a class="menu__link{% if page_name == 'problem_edit' %} active{% endif %}" href="{{ url('problem_edit', pid=pdoc.pid|default(pdoc.docId)) }}">
<span class="icon icon-edit"></span> {{ _('Edit') }}
</a></li>
{% endif %}
{% if page_name == 'problem_detail' and (handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
{% if page_name == 'problem_detail' and (handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
<div style="display: none" class="dialog__body--send-to">
<div>
<div class="row"><div class="columns">
@@ -68,7 +68,7 @@
<button type="submit" class="rounded primary button">
{{ _('Update') }}
</button>
{% if pdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>
@@ -6,7 +6,7 @@
<div class="section__header">
<h1 class="section__title">{{ _('Testdata') }}</h1>
<div class="section__tools">
{% if handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="primary rounded button" name="upload_testdata">{{ _('Add File') }}</button>
{% endif %}
</div>
@@ -48,14 +48,14 @@
</tbody>
</table>
{% else %}
{% if handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA) %}
{{ nothing.render('No testdata at current.') }}
{% else %}
{{ nothing.render("You don't have permission to read testdata.")}}
{% endif %}
{% endif %}
</div>
{% if handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if testdata.length %}
<div class="section__body">
<button class="rounded button" name="download_selected_testdata">{{ _('Download Selected') }}</button>
@@ -70,7 +70,7 @@
<div class="section__header">
<h1 class="section__title">{{ _('Additional Files') }}</h1>
<div class="section__tools">
{% if handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="primary rounded button" name="upload_file">{{ _('Add File') }}</button>
{% endif %}
</div>
@@ -117,7 +117,7 @@
{% if additional_file.length %}
<div class="section__body">
<button class="rounded button" name="download_selected_file">{{ _('Download Selected') }}</button>
{% if handler.user._id == pdoc.owner or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="rounded button" name="remove_selected_file">{{ _('Remove Selected') }}</button>
{% endif %}
</div>
@@ -171,7 +171,7 @@
</form>
</li>
{% endif %}
{% if tdoc.owner == user._id or handler.user.hasPerm(perm.PERM_EDIT_TRAINING) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_TRAINING) %}
<li class="menu__item"><a class="menu__link" href="{{ url('training_edit', tid=tdoc.docId) }}">
<span class="icon icon-edit"></span> {{ _('Edit') }}
</a></li>
@@ -38,7 +38,7 @@
<button type="submit" class="rounded primary button">
{{ _('Update') }}
</button>
{% if tdoc.owner == handler.user._id or handler.user.hasPerm(perm.PERM_EDIT_TRAINING) %}
{% if handler.user.own(tdoc) or handler.user.hasPerm(perm.PERM_EDIT_TRAINING) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>