core: restore PERM_EDIT_PROBLEM_SELF

This commit is contained in:
undefined committed 2021-05-08 22:44:04 +08:00
1 parent 5b0478fb3f
commit 866aa56f78
11 files changed
+25 -21

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.25.5", "version": "2.25.6",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+7 -8
View File
@@ -126,7 +126,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) { for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await problem.del(domainId, pid); await problem.del(domainId, pid);
} }
@@ -138,7 +138,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) { for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await problem.edit(domainId, pid, { hidden: true }); await problem.edit(domainId, pid, { hidden: true });
} }
@@ -150,7 +150,7 @@ export class ProblemMainHandler extends ProblemHandler {
for (const pid of pids) { for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
if (!this.user.own(pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await problem.edit(domainId, pid, { hidden: false }); await problem.edit(domainId, pid, { hidden: false });
} }
@@ -232,7 +232,7 @@ export class ProblemDetailHandler extends ProblemHandler {
} }
async postDelete() { async postDelete() {
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
await problem.del(this.pdoc.domainId, this.pdoc.docId); await problem.del(this.pdoc.domainId, this.pdoc.docId);
this.response.redirect = this.url('problem_main'); this.response.redirect = this.url('problem_main');
} }
@@ -340,8 +340,7 @@ export class ProblemStatisticsHandler extends ProblemDetailHandler {
export class ProblemManageHandler extends ProblemDetailHandler { export class ProblemManageHandler extends ProblemDetailHandler {
async prepare() { async prepare() {
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
else this.checkPerm(PERM.PERM_EDIT_PROBLEM_SELF);
} }
} }
@@ -413,7 +412,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
if (!this.request.files.file) throw new ValidationError('file'); if (!this.request.files.file) throw new ValidationError('file');
if (!filename) filename = this.request.files.file.name || String.random(16); if (!filename) filename = this.request.files.file.name || String.random(16);
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', 'Bad filename'); if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', 'Bad filename');
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (filename.endsWith('.zip')) { if (filename.endsWith('.zip')) {
const zip = new AdmZip(this.request.files.file.path); const zip = new AdmZip(this.request.files.file.path);
const entries = zip.getEntries(); const entries = zip.getEntries();
@@ -438,7 +437,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@post('files', Types.Array) @post('files', Types.Array)
@post('type', Types.Range(['testdata', 'additional_file']), true) @post('type', Types.Range(['testdata', 'additional_file']), true)
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') { async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
if (!this.user.own(this.pdoc)) this.checkPerm(PERM.PERM_EDIT_PROBLEM); if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (type === 'testdata') await problem.delTestdata(domainId, this.pdoc.docId, files); if (type === 'testdata') await problem.delTestdata(domainId, this.pdoc.docId, files);
else await problem.delAdditionalFile(domainId, this.pdoc.docId, files); else await problem.delAdditionalFile(domainId, this.pdoc.docId, files);
this.back(); this.back();
+5
View File
@@ -72,6 +72,8 @@ export interface Udoc extends Dictionary<any> {
loginip: string, loginip: string,
} }
export type ownerInfo = { owner: number, maintainer?: number[] };
export interface User extends Record<string, any> { export interface User extends Record<string, any> {
_id: number, _id: number,
_udoc: Udoc, _udoc: Udoc,
@@ -90,6 +92,9 @@ export interface User extends Record<string, any> {
perm: bigint, perm: bigint,
scope: bigint, scope: bigint,
role: string, role: string,
own<T extends ownerInfo>(doc: T, checkPerm: bigint): boolean
own<T extends ownerInfo>(doc: T, exact: boolean): boolean
own<T extends ownerInfo>(doc: T): boolean
own<T extends { owner: number, maintainer?: number[] }>(doc: T): boolean; own<T extends { owner: number, maintainer?: number[] }>(doc: T): boolean;
hasPerm: (...perm: bigint[]) => boolean, hasPerm: (...perm: bigint[]) => boolean,
hasPriv: (...priv: number[]) => boolean, hasPriv: (...priv: number[]) => boolean,
-1
View File
@@ -26,7 +26,6 @@ export const PERM = {
// Problem and Record // Problem and Record
PERM_CREATE_PROBLEM: 1n << 4n, PERM_CREATE_PROBLEM: 1n << 4n,
PERM_EDIT_PROBLEM: 1n << 5n, PERM_EDIT_PROBLEM: 1n << 5n,
/** @deprecated */
PERM_EDIT_PROBLEM_SELF: 1n << 6n, PERM_EDIT_PROBLEM_SELF: 1n << 6n,
PERM_VIEW_PROBLEM: 1n << 7n, PERM_VIEW_PROBLEM: 1n << 7n,
PERM_VIEW_PROBLEM_HIDDEN: 1n << 8n, PERM_VIEW_PROBLEM_HIDDEN: 1n << 8n,
+3 -2
View File
@@ -87,8 +87,9 @@ class User implements _User {
return this; return this;
} }
own<T extends { owner: number, maintainer?: number[] }>(doc: T, exact = false) { own(doc: any, arg1: any = false): boolean {
return exact if (typeof arg1 === 'bigint' && !this.hasPerm(arg1)) return false;
return (typeof arg1 === 'boolean' && arg1)
? doc.owner === this._id ? doc.owner === this._id
: doc.owner === this._id || (doc.maintainer || []).includes(this._id); : doc.owner === this._id || (doc.maintainer || []).includes(this._id);
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.8.3", "version": "4.8.4",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -28,7 +28,7 @@
<span class="icon icon-send"></span> {{ _('Open in Problem Set') }} <span class="icon icon-send"></span> {{ _('Open in Problem Set') }}
</a></li> </a></li>
{% endif %} {% endif %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li> <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)) }}"> <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') }} <span class="icon icon-edit"></span> {{ _('Edit') }}
@@ -28,7 +28,7 @@
<span class="icon icon-send"></span> {{ _('Open in Problem Set') }} <span class="icon icon-send"></span> {{ _('Open in Problem Set') }}
</a></li> </a></li>
{% endif %} {% endif %}
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li> <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)) }}"> <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') }} <span class="icon icon-edit"></span> {{ _('Edit') }}
@@ -78,7 +78,7 @@
<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)) }}"> <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') }} <span class="icon icon-file"></span> {{ _('Files') }}
</a></li> </a></li>
{% if (handler.user.own(pdoc) and handler.user.hasPerm(perm.PERM_EDIT_PROBLEM_SELF)) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<li class="menu__seperator"></li> <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)) }}"> <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') }} <span class="icon icon-edit"></span> {{ _('Edit') }}
@@ -57,7 +57,7 @@
<button type="submit" class="rounded primary button"> <button type="submit" class="rounded primary button">
{{ _('Update') }} {{ _('Update') }}
</button> </button>
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button name="operation" value="delete" type="submit" class="rounded button"> <button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }} {{ _('Delete') }}
</button> </button>
@@ -6,7 +6,7 @@
<div class="section__header"> <div class="section__header">
<h1 class="section__title">{{ _('Testdata') }}</h1> <h1 class="section__title">{{ _('Testdata') }}</h1>
<div class="section__tools"> <div class="section__tools">
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="primary rounded button" name="upload_testdata">{{ _('Add File') }}</button> <button class="primary rounded button" name="upload_testdata">{{ _('Add File') }}</button>
{% endif %} {% endif %}
</div> </div>
@@ -55,7 +55,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
{% if testdata.length %} {% if testdata.length %}
<div class="section__body"> <div class="section__body">
<button class="rounded button" name="download_selected_testdata">{{ _('Download Selected') }}</button> <button class="rounded button" name="download_selected_testdata">{{ _('Download Selected') }}</button>
@@ -70,7 +70,7 @@
<div class="section__header"> <div class="section__header">
<h1 class="section__title">{{ _('Additional Files') }}</h1> <h1 class="section__title">{{ _('Additional Files') }}</h1>
<div class="section__tools"> <div class="section__tools">
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="primary rounded button" name="upload_file">{{ _('Add File') }}</button> <button class="primary rounded button" name="upload_file">{{ _('Add File') }}</button>
{% endif %} {% endif %}
</div> </div>
@@ -117,7 +117,7 @@
{% if additional_file.length %} {% if additional_file.length %}
<div class="section__body"> <div class="section__body">
<button class="rounded button" name="download_selected_file">{{ _('Download Selected') }}</button> <button class="rounded button" name="download_selected_file">{{ _('Download Selected') }}</button>
{% if handler.user.own(pdoc) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %} {% if handler.user.own(pdoc, perm.PERM_EDIT_PROBLEM_SELF) or handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) %}
<button class="rounded button" name="remove_selected_file">{{ _('Remove Selected') }}</button> <button class="rounded button" name="remove_selected_file">{{ _('Remove Selected') }}</button>
{% endif %} {% endif %}
</div> </div>