fix role manage

This commit is contained in:
undefined committed 2020-04-27 19:07:56 +08:00
1 parent 15d43636c0
commit 42e534615e
34 files changed
+221 -314

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ jobs:
- uses: actions/upload-artifact@v1
with:
name: hydro
path: dist
path: .build
- run: |
cd ui
yarn
+2
View File
@@ -34,6 +34,8 @@ async function run() {
require('./handler/user');
require('./handler/contest');
require('./handler/training');
require('./handler/discussion');
require('./handler/manage');
require('./handler/import');
server.start();
}
+16 -8
View File
@@ -46,12 +46,14 @@ class DiscussionHandler extends Handler {
const pdoc = await problem.getById(docId);
if (!pdoc) throw new DiscussionNodeNotFoundError(type, docId);
if (pdoc.hidden) this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
this.title = pdoc.title;
this.vnode = pdoc;
} else if (type === 'contest') {
const tdoc = await contest.get(docId);
if (!tdoc) throw new DiscussionNodeNotFoundError(type, docId);
this.title = tdoc.title;
this.vnode = tdoc;
} else throw new DiscussionNodeNotFoundError(type, docId);
this.vnode.parentType = type;
this.vnode.parentId = docId;
}
}
}
@@ -62,7 +64,7 @@ class DiscussionMainHandler extends DiscussionHandler {
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
this.response.template = 'discussion_main_or_node.html';
this.response.body = {
ddocs, dpcount, udict, page,
ddocs, dpcount, udict, page, page_name: 'discussion_main', vnode: {},
};
}
}
@@ -77,11 +79,17 @@ class DiscussionNodeHandler extends DiscussionHandler {
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
const path = [
['discussion_main', '/discuss'],
[this.title, null, true],
[this.vnode.title, null, true],
];
this.response.template = 'discussion_main_or_node.html';
this.response.body = {
ddocs, dpcount, udict, path, page,
ddocs,
dpcount,
udict,
path,
page,
vnode: this.vnode,
page_name: 'discussion_node',
};
}
}
@@ -95,11 +103,11 @@ class DiscussionCreateHandler extends DiscussionHandler {
async get({ type, docId }) {
const path = [
['discussion_main', '/discuss'],
[this.title, `/discuss/${type}/${docId}`, true],
[this.vnode.title, `/discuss/${type}/${docId}`, true],
['discussion_create', null],
];
this.response.template = 'discussion_create.html';
this.response.body = { path, title: this.title };
this.response.body = { path, vnode: this.vnode };
}
async post({
@@ -139,7 +147,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
const udict = await user.getList(uids);
const path = [
['discussion_main', '/discuss'],
[this.title, '/discuss/{type}', true],
[this.vnode.title, '/discuss/{type}', true],
[this.ddoc.title, null, true],
];
this.response.template = 'discussion_detail.html';
+19 -12
View File
@@ -3,11 +3,12 @@ const user = require('../model/user');
const builtin = require('../model/builtin');
const { Route, Handler } = require('../service/server');
const { PERM_ADMIN } = require('../permission');
const { RoleAlreadyExistError } = require('../error');
const { RoleAlreadyExistError, ValidationError } = require('../error');
class ManageHandler extends Handler {
async prepare() {
this.checkPerm(PERM_ADMIN);
this.system = await user.getById(0);
}
}
@@ -20,20 +21,21 @@ class ManageMainHandler extends ManageHandler {
class ManageDashboardHandler extends ManageHandler {
async get() {
this.response.template = 'domain_manage_dashboard.html';
this.response.body = { system: this.system };
}
}
class ManageEditHandler extends ManageHandler {
async get() {
this.response.template = 'domain_manage_edit.html';
this.response.body = { system: this.system };
}
async post({ name, gravatar, bulletin }) {
await Promise.all([
system.set('name', name),
system.set('gravatar', gravatar),
system.set('bulletin', bulletin),
]);
async post({ uname, gravatar, bio }) {
const unameLower = uname.trim().toLowerCase();
await user.setById(0, {
uname, unameLower, gravatar, bio,
});
this.back();
}
}
@@ -92,14 +94,19 @@ class ManageRoleHandler extends ManageHandler {
}
async postAdd({ role }) {
const roles = await user.getRoles();
if (roles.includes(role)) throw new RoleAlreadyExistError(role);
await user.setRole(role, builtin.PERM_DEFAULT);
const r = await user.getRole(role);
if (r) throw new RoleAlreadyExistError(role);
await user.addRole(role, builtin.PERM_DEFAULT);
this.back();
}
async postDelete({ role }) {
await user.deleteRoles(role);
async postDelete({ roles }) {
for (const role of roles) {
if (['admin', 'default', 'guest'].includes(role)) {
throw new ValidationError('role');
}
}
await user.deleteRoles(roles);
this.back();
}
}
-3
View File
@@ -4,7 +4,6 @@ const token = require('../model/token');
const system = require('../model/system');
const { sendMail } = require('../lib/mail');
const misc = require('../lib/misc');
const validator = require('../lib/validator');
const options = require('../options');
const { PERM_REGISTER_USER, PERM_LOGGEDIN } = require('../permission');
const {
@@ -55,7 +54,6 @@ class UserRegisterHandler extends Handler {
}
async post({ mail }) {
validator.checkEmail(mail);
if (await user.getByEmail(mail, true)) throw new UserAlreadyExistError(mail);
this.limitRate('send_mail', 3600, 30);
const t = await token.add(
@@ -112,7 +110,6 @@ class UserLostPassHandler extends Handler {
}
async post({ mail }) {
validator.checkEmail(mail);
const udoc = await user.getByEmail(mail);
if (!udoc) throw new UserNotFoundError(mail);
const tid = await token.add(
+5 -28
View File
@@ -3,6 +3,7 @@ const { ValidationError } = require('../error');
const RE_UID = /^-?\d+$/i;
const RE_PID = /^([a-zA-Z]+[a-zA-Z0-9]*)|$/i;
const RE_UNAME = /[^\s\u3000](.{,254}[^\s\u3000])?$/i;
const RE_ROLE = /^[_0-9A-Za-z]{1,256}$/i;
const RE_MAIL = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/i;
const isTitle = (s) => s && s.length < 64;
@@ -11,6 +12,8 @@ const isUid = (s) => RE_UID.test(s);
const checkUid = (s) => { if (!isUid(s)) throw new ValidationError('uid'); else return s; };
const isUname = (s) => RE_UNAME.test(s);
const checkUname = (s) => { if (!isUname(s)) throw new ValidationError('uname'); else return s; };
const isRole = (s) => RE_ROLE.test(s);
const checkRole = (s) => { if (!isRole(s)) throw new ValidationError('role'); else return s; };
const isPassword = (s) => s.length >= 5;
const checkPassword = (s) => { if (!isPassword(s)) throw new ValidationError('password'); else return s; };
const isEmail = (s) => RE_MAIL.test(s);
@@ -33,6 +36,8 @@ module.exports = {
checkUid,
isUname,
checkUname,
isRole,
checkRole,
isPassword,
checkPassword,
isEmail,
@@ -50,8 +55,6 @@ module.exports = {
};
/*
ID_RE = re.compile(r'[^\\/\s\u3000]([^\\/\n\r]*[^\\/\s\u3000])?')
ROLE_RE = re.compile(r'[_0-9A-Za-z]{1,256}')
def is_id(s):
return bool(ID_RE.fullmatch(s))
@@ -67,14 +70,6 @@ def check_node_name(s):
raise error.ValidationError('node_name')
def is_role(s):
return bool(ROLE_RE.fullmatch(s))
def check_role(s):
if not is_role(s):
raise error.ValidationError('role')
def is_intro(s):
return isinstance(s, str) and 0 < len(s.strip()) < 500
@@ -93,15 +88,6 @@ def check_description(s):
raise error.ValidationError('description')
def is_bulletin(s):
return isinstance(s, str) and len(s) < 65536
def check_bulletin(s):
if not is_bulletin(s):
raise error.ValidationError('bulletin')
def is_lang(i):
return i in constant.language.LANG_TEXTS
@@ -110,13 +96,4 @@ def check_lang(i):
if not is_lang(i):
raise error.ValidationError('lang')
def is_domain_invitation_code(s):
return bool(DOMAIN_INVITATION_CODE_RE.fullmatch(s))
def check_domain_invitation_code(s):
if not is_domain_invitation_code(s):
raise error.ValidationError('invitation_code')
*/
+2 -2
View File
@@ -2,8 +2,8 @@ const perm = require('../permission');
const BUILTIN_ROLES = [
{ _id: 'guest', perm: perm.PERM_BASIC },
{ _id: 'default', perm: perm.PERM_DEFAULT },
{ _id: 'admin', perm: perm.PERM_ADMIN },
{ _id: 'default', perm: perm.PERM_DEFAULT, count: 0 },
{ _id: 'admin', perm: perm.PERM_ADMIN, count: 0 },
];
const CATEGORIES = {
动态规划: [
+1 -1
View File
@@ -41,7 +41,7 @@ function count(query) {
}
function getMulti(query) {
return coll.find(query).sort([{ updateAt: -1 }, { _id: -1 }]);
return coll.find(query).sort('updateAt', -1);
}
async function addReply(did, owner, content, ip) {
+56 -25
View File
@@ -1,7 +1,6 @@
const system = require('./system');
const { UserNotFoundError, UserAlreadyExistError } = require('../error');
const pwhash = require('../lib/pwhash');
const validator = require('../lib/validator');
const db = require('../service/db');
const coll = db.collection('user');
@@ -33,6 +32,7 @@ class USER {
return pwhash.check(password, this.salt, this.hash);
}
}
async function getById(_id) {
const udoc = await coll.findOne({ _id });
if (!udoc) throw new UserNotFoundError(_id);
@@ -40,11 +40,13 @@ async function getById(_id) {
udoc.perm = role.perm;
return new USER(udoc);
}
async function getList(uids) {
const r = {};
for (const uid of uids) r[uid] = await getById(uid); // eslint-disable-line no-await-in-loop
return r;
}
async function getByUname(uname) {
const unameLower = uname.trim().toLowerCase();
const udoc = await coll.findOne({ unameLower });
@@ -53,6 +55,7 @@ async function getByUname(uname) {
udoc.perm = role.perm;
return new USER(udoc);
}
async function getByEmail(mail, ignoreMissing = false) {
const mailLower = mail.trim().toLowerCase();
const udoc = await coll.findOne({ mailLower });
@@ -64,22 +67,23 @@ async function getByEmail(mail, ignoreMissing = false) {
udoc.perm = role.perm;
return new USER(udoc);
}
function setPassword(uid, password) {
validator.checkPassword(password);
const salt = pwhash.salt();
return coll.findOneAndUpdate({ _id: uid }, {
$set: { salt, hash: pwhash.hash(password, salt) },
});
}
function setById(uid, args) {
coll.findOneAndUpdate({ _id: uid }, { $set: args });
return coll.findOneAndUpdate({ _id: uid }, { $set: args });
}
function setEmail(uid, mail) {
validator.checkEmail(mail);
return setById(uid, { mail, mailLower: mail.trim().toLowerCase() });
}
async function changePassword(uid, currentPassword, newPassword) {
validator.checkPassword(newPassword);
const udoc = await getById(uid);
udoc.checkPassword(currentPassword);
const salt = pwhash.salt();
@@ -89,59 +93,86 @@ async function changePassword(uid, currentPassword, newPassword) {
$set: { salt, hash: pwhash.hash(newPassword, salt) },
});
}
async function inc(_id, field, n) {
await coll.findOneAndUpdate({ _id }, { $inc: { [field]: n } });
const udoc = await getById(_id);
return udoc;
}
async function create({
uid, mail, uname, password, regip = '127.0.0.1', role = 'default',
}) {
validator.checkUname(uname);
validator.checkPassword(password);
validator.checkEmail(mail);
const salt = pwhash.salt();
if (!uid) uid = system.inc('user');
try {
await coll.insertOne({
_id: uid,
mail,
mailLower: mail.trim().toLowerCase(),
uname,
unameLower: uname.trim().toLowerCase(),
password: pwhash.hash(password, salt),
salt,
regat: new Date(),
regip,
loginat: new Date(),
loginip: regip,
role,
gravatar: mail,
});
await Promise.all([
coll.insertOne({
_id: uid,
mail,
mailLower: mail.trim().toLowerCase(),
uname,
unameLower: uname.trim().toLowerCase(),
password: pwhash.hash(password, salt),
salt,
regat: new Date(),
regip,
loginat: new Date(),
loginip: regip,
role,
gravatar: mail,
}),
collRole.updateOne({ _id: role }, { $inc: { count: 1 } })
]);
} catch (e) {
throw new UserAlreadyExistError([uid, uname, mail]);
}
}
function getMany(params) {
function getMulti(params) {
return coll.find(params);
}
async function setRole(uid, role) {
const udoc = await getById(uid);
return await Promise.all([
coll.findOneAndUpdate({ _id: uid }, { role }),
collRole.updateOne({ _id: udoc.role }, { $inc: { count: -1 } }),
collRole.updateOne({ _id: role }, { $inc: { count: 1 } }),
]);
}
function getRoles() {
return collRole.find().toArray();
}
function getRole(name) {
return collRole.findOne({ _id: name });
}
function addRole(name, perm) {
return collRole.insertOne({ _id: name, perm, count: 0 });
}
function deleteRoles(roles) {
return collRole.deleteMany({ _id: { $in: roles } });
}
module.exports = {
changePassword,
create,
getByEmail,
getById,
getByUname,
getMany,
getMulti,
inc,
setById,
setEmail,
setPassword,
setRole,
getRole,
getList,
getRoles,
addRole,
deleteRoles,
};
+1
View File
@@ -43,6 +43,7 @@ let options = {
SOLUTION_PER_PAGE: 20,
CONTEST_PER_PAGE: 20,
TRAINING_PER_PAGE: 10,
DISCUSSION_PER_PAGE: 50,
CONTESTS_ON_MAIN: 5,
TRAININGS_ON_MAIN: 5,
DISCUSSIONS_ON_MAIN: 20,
+1 -1
View File
@@ -1,5 +1,5 @@
const Mongo = require('mongodb');
const bus = require('../service/bus');
const bus = require('./bus');
const options = require('../options');
let mongourl = 'mongodb://';
+29 -14
View File
@@ -113,6 +113,7 @@ class Handler {
back(body) {
if (body) this.response.body = body;
else if (this.preferJson) this.response.body = {};
this.response.redirect = this.request.headers.referer || '/';
}
@@ -165,17 +166,19 @@ class Handler {
}
async renderBody() {
if (!(this.response.body || this.response.template)) {
this.response.body = { error: new NotFoundError() };
this.response.template = 'error.html';
}
if (!this.preferJson) {
if (this.response.body || this.response.template) {
if (this.request.query.noTemplate || this.preferJson) return;
const templateName = this.request.query.template || this.response.template;
if (templateName) {
this.response.body = this.response.body || {};
await this.render(templateName, this.response.body);
if (!this.response.redirect) {
if (!(this.response.body || this.response.template)) {
this.response.body = { error: new NotFoundError() };
this.response.template = 'error.html';
}
if (!this.preferJson) {
if (this.response.body || this.response.template) {
if (this.request.query.noTemplate || this.preferJson) return;
const templateName = this.request.query.template || this.response.template;
if (templateName) {
this.response.body = this.response.body || {};
await this.render(templateName, this.response.body);
}
}
}
}
@@ -192,7 +195,11 @@ class Handler {
this.ctx.response.body = this.response.body;
this.ctx.response.status = this.response.status || 200;
}
if (this.response.type) this.ctx.response.type = this.response.type;
this.ctx.response.type = this.preferJson
? 'application/json'
: this.response.type
? this.response.type
: this.ctx.response.type;
}
}
@@ -233,7 +240,7 @@ class Handler {
console.error(error.message, error.params);
console.error(error.stack);
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
this.response.body = { error };
this.response.body = { error: { message: error.message, params: error.params, stack: error.stack } };
await this.___cleanup().catch(() => { });
}
}
@@ -247,6 +254,8 @@ function Route(route, RouteHandler) {
const method = ctx.method.toLowerCase();
const args = { ...ctx.params, ...ctx.query, ...ctx.request.body };
if (h.___prepare) await h.___prepare(args);
for (const l of check) {
if (args[l]) {
args[l] = new ObjectID(args[l]);
@@ -256,11 +265,17 @@ function Route(route, RouteHandler) {
if (args.content) validator.checkContent(args.content);
if (args.title) validator.checkContent(args.title);
if (args.uid) args.uid = parseInt(validator.checkUid(args.uid));
if (args.password) validator.checkPassword(args.password);
if (args.mail) validator.checkEmail(args.mail);
if (args.uname) validator.checkUname(args.uname);
if (args.page) args.page = parseInt(args.page);
if (args.duration) args.duration = parseFloat(args.duration);
if (args.pids) args.pids = args.pids.split(',').map((i) => i.trim());
if (args.role) validator.checkRole(args.role);
if (args.roles) {
for (const i of args.roles) validator.checkRole(i);
}
if (h.___prepare) await h.___prepare(args);
if (h.__prepare) await h.__prepare(args);
if (h._prepare) await h._prepare(args);
if (h.prepare) await h.prepare(args);
+1 -1
View File
@@ -386,7 +386,7 @@ Solve: 解决
Time: 时间
required: 必填
Name: 名称
Will be used as the domain icon.: 将被用作域图标。
Will be used as the system icon.: 将被用作系统图标。
My Role: 我的角色
What's domain?: 什么是域?
Visit: 查看
+1 -1
View File
@@ -375,7 +375,7 @@ Solve: 解決
Time: 時間
required: 必填
Name: 名稱
Will be used as the domain icon.: 將被用作域圖示。
Will be used as the system icon.: 將被用作圖示。
My Role: 我的角色
What's domain?: 什麼是域?
Visit: 檢視
+2 -3
View File
@@ -1,7 +1,6 @@
{% macro render_item(icon_name, page_name, label=none) %}
{% macro render_item(icon_name, page_name, target_url, label=none) %}
<li class="menu__item" id="menu-item-{{ page_name }}">
{% set target_url = reverse_url(page_name, args) %}
<a href="{{ target_url }}" class="menu__link{% if handler.request.path_qs == target_url %} active{% endif %}">
<a href="{{ target_url }}" class="menu__link{% if handler.request.path == target_url %} active{% endif %}">
{% if icon_name %}
<span class="icon icon-{{ icon_name }}"></span>
{% endif %}
+14 -18
View File
@@ -7,10 +7,10 @@
<div class="section__body">
<ul class="supplementary list">
<li>
<a class="discussion-node-tag" href="{{ vj4.handler.discussion.node_url(handler, 'discussion_node', vj4.model.adaptor.discussion.node_id(ddoc)) }}">
{% if ddoc['parent_doc_type'] == vj4.model.document.TYPE_DISCUSSION_NODE %}
<a class="discussion-node-tag" href="/discuss/{{ ddoc.parentType }}/{{ ddoc.parentId }}">
{% if ddoc.parentType == 'node' %}
<span class="v-center icon icon-tag"></span>
{% elif ddoc['parent_doc_type'] == vj4.model.document.TYPE_CONTEST %}
{% elif ddoc.parentType == 'contest' %}
<span class="v-center icon icon-award"></span>
{% else %}
<span class="v-center icon icon-flag"></span>
@@ -19,19 +19,19 @@
</a>
</li>
<li>
{{ user.render_inline(udict[ddoc['owner']]) }}
{{ user.render_inline(udict[ddoc.owner]) }}
@
{{ datetime_span(ddoc['_id'].generationTime) }}
{{ datetime_span(ddoc['_id'].generationTime)|safe }}
</li>
</ul>
<div class="typo topic__content" data-emoji-enabled data-raw-url="{{ reverse_url('discussion_detail_raw', did=ddoc['_id']) }}">
{{ ddoc['content']|markdown }}
<div class="typo topic__content" data-emoji-enabled data-raw-url="/discuss/{{ ddoc._id }}/raw">
{{ ddoc['content']|markdown|safe }}
</div>
</div>
<ul class="section__footer supplementary dot list">
{% if handler.own(ddoc, perm.PERM_EDIT_DISCUSSION_SELF) or handler.hasPerm(perm.PERM_EDIT_DISCUSSION) %}
{% if ddoc.owner == handler.user._id or handler.hasPerm(perm.PERM_EDIT_DISCUSSION) %}
<li>
<a href="{{ reverse_url('discussion_edit', did=ddoc['doc_id']) }}"><span class="icon icon-edit"></span> {{ _('Edit') }}</a>
<a href="/discuss/{{ ddoc._id }}/edit"><span class="icon icon-edit"></span> {{ _('Edit') }}</a>
</li>
{% endif %}
<li>
@@ -48,7 +48,7 @@
</form></li>
{% endif %}
<li>
<a href="{{ reverse_url('about') }}#contact"><span class="icon icon-warning"></span> {{ _('Report') }}</a>
<a href="/wiki/about#contact"><span class="icon icon-warning"></span> {{ _('Report') }}</a>
</li>
</ul>
</div>
@@ -64,15 +64,11 @@
comment_ref = 'drid',
reply_ref = 'drrid',
comment_post_perm = perm.PERM_REPLY_DISCUSSION,
comment_edit_perm = perm.PERM_NONE if handler.own(ddoc, perm.PERM_EDIT_DISCUSSION_REPLY_SELF_DISCUSSION) else perm.PERM_EDIT_DISCUSSION_REPLY,
comment_edit_self_perm = perm.PERM_EDIT_DISCUSSION_REPLY_SELF,
comment_delete_perm = perm.PERM_NONE if handler.own(ddoc, perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION) else perm.PERM_DELETE_DISCUSSION_REPLY,
comment_delete_self_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF,
comment_edit_perm = perm.PERM_LOGGEDIN if ddoc.owner == handler.user._id else perm.PERM_EDIT_DISCUSSION_REPLY,
comment_delete_perm = perm.PERM_LOGGEDIN if ddoc.owner == handler.user._id else perm.PERM_DELETE_DISCUSSION_REPLY,
reply_post_perm = perm.PERM_REPLY_DISCUSSION,
reply_edit_perm = perm.PERM_NONE if handler.own(ddoc, perm.PERM_EDIT_DISCUSSION_REPLY_SELF_DISCUSSION) else perm.PERM_EDIT_DISCUSSION_REPLY,
reply_edit_self_perm = perm.PERM_EDIT_DISCUSSION_REPLY_SELF,
reply_delete_perm = perm.PERM_NONE if handler.own(ddoc, perm.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION) else perm.PERM_DELETE_DISCUSSION_REPLY,
reply_delete_self_perm = perm.PERM_DELETE_DISCUSSION_REPLY_SELF
reply_edit_perm = perm.PERM_LOGGEDIN if ddoc.owner == handler.user._id else perm.PERM_EDIT_DISCUSSION_REPLY,
reply_delete_perm = perm.PERM_LOGGEDIN if ddoc.owner == handler.user._id else perm.PERM_DELETE_DISCUSSION_REPLY,
) }}
{{ paginator.render(page, pcount) }}
{% if drcount == 0 %}
+1 -1
View File
@@ -11,7 +11,7 @@
<button name="operation" value="update" type="submit" class="rounded primary button">
{{ _('Update') }} (Ctrl+Enter)
</button>
{% if handler.own(ddoc, perm.PERM_DELETE_DISCUSSION_SELF) or handler.hasPerm(perm.PERM_DELETE_DISCUSSION) %}
{% if ddoc.owner == handler.user._id or handler.hasPerm(perm.PERM_DELETE_DISCUSSION) %}
<button name="operation" value="delete" type="submit" class="rounded button">
{{ _('Delete') }}
</button>
+8 -9
View File
@@ -7,17 +7,17 @@
</div>
</div>
<div class="medium-3 columns">
{% if vnode['doc_type'] == vj4.model.document.TYPE_PROBLEM %}
{% with pdoc=vnode, owner_udoc=udict[vnode['owner']] %}
{% if vnode.parentType == 'problem' %}
{% set pdoc = vnode %}
{% set owner_udoc = udict[vnode.owner] %}
{% include "partials/problem_sidebar.html" %}
{% endwith %}
{% elif vnode['doc_type'] == vj4.model.document.TYPE_CONTEST %}
{% with tdoc=vnode, owner_udoc=udict[vnode['owner']] %}
{% elif vnode.parentType == 'contest' %}
{% set tdoc = vnode %}
{% set owner_udoc = udict[vnode.owner] %}
{% include "partials/contest_sidebar.html" %}
{% endwith %}
{% elif vnode['doc_type'] == vj4.model.document.TYPE_DISCUSSION_NODE %}
{% elif vnode.parentType == 'node' %}
<div class="section side">
{% if vnode['pic'] %}<div class="discussion-node__bg {{ vnode['pic'] }}"></div>{% endif %}
{% if vnode.pic %}<div class="discussion-node__bg {{ vnode.pic }}"></div>{% endif %}
<div class="section__header">
<h1 class="section__title">{{ vnode['title'] or _('Create Discussion') }}</h1>
</div>
@@ -38,7 +38,6 @@
</div>
</div>
{% endif %}
{% include 'discussion_nodes_widget.html' %}
</div>
</div>
{% endblock %}
-17
View File
@@ -1,17 +0,0 @@
<div class="section side">
<div class="section__header">
<h1 class="section__title">{{ _('Discussion Nodes') }}</h1>
</div>
<div class="section__body"><ul class="group-list">
{% for category, nodes in discussionNodes.items() %}
<li class="group-list__item">
<h2 class="section__title">{{ category }}</h2>
<ol class="chip-list">
{% for node in nodes %}
<li class="chip-list__item"><a class="typo-a" href="{{ reverse_url('discussion_node', doc_id=node['name']) }}">{{ node['name'] }}</a></li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ul></div>
</div>
-26
View File
@@ -1,26 +0,0 @@
{% extends "layout/basic.html" %}
{% block content %}
<div class="domain_join__container">
<div class="row columns">
<div class="section">
<div class="section__header">
<h1 class="section__title">
{{ _('Join {0}').format(handler.domain['name']) }}
</h1>
</div>
<div class="section__body typo">
<p>{{ _('By clicking the button, you will become a member of the domain {0}.').format(handler.domain['name']) }}</p>
</div>
<div class="section__body typo">
<form method="post">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
{% if join_settings['method'] == vj4.constant.domain.JOIN_METHOD_CODE %}
{{ form.form_text(columns=None, label='Invitation Code', name='code', required=true, help_text='You need to enter the invitation code to join the domain.', value=code, autofocus=True) }}
{% endif %}
<button type="submit" class="primary rounded button">{{ _('Join') }}</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
+6 -5
View File
@@ -1,10 +1,11 @@
{% set page_name = "domain_manage_dashboard" %}
{% import "components/user.html" as user %}
{% extends "domain_base.html" %}
{% extends "manage_base.html" %}
{% block domain_content %}
{% if handler.domain['bulletin'] %}
{% if system.bio %}
<div class="section">
<div class="section__body typo">
{{ handler.domain['bulletin']|markdown }}
{{ system.bio|markdown|safe }}
</div>
</div>
{% endif %}
@@ -14,8 +15,8 @@
</div>
<div class="section__body typo">
<dl class="large horizontal">
<dt>{{ _('Gravatar') }}</dt><dd><img src="{{ handler.domain['gravatar']|gravatar_url }}" width="32" height="32"></dd>
<dt>{{ _('Name') }}</dt><dd>{{ handler.domain['name'] }}</dd>
<dt>{{ _('Gravatar') }}</dt><dd><img src="{{ system.gravatar|gravatar_url }}" width="32" height="32"></dd>
<dt>{{ _('Name') }}</dt><dd>{{ system.uname }}</dd>
</dl>
</div>
</div>
-22
View File
@@ -1,22 +0,0 @@
{% extends "domain_base.html" %}
{% block domain_content %}
<div class="section">
<div class="section__header">
<h1 class="section__title">{{ _('Initialize') }}</h1>
<div class="section__tools">
<form method="post">
<div class="row"><div class="columns">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
<button type="submit" class="rounded primary button">
<span class="icon icon-add"></span> {{ _('Initialize') }}
</button>
</div></div>
</form>
</div>
</div>
<div class="section__body">
</div>
</div>
{% include 'discussion_nodes_widget.html' %}
{% endblock %}
+24 -4
View File
@@ -1,11 +1,31 @@
{% extends "domain_base.html" %}
{% set page_name = "domain_manage_edit" %}
{% import "components/form.html" as form with context %}
{% extends "manage_base.html" %}
{% block domain_content %}
<div class="section">
<div class="section__body">
<form method="post">
{% with ddoc=handler.domain %}
{% include "partials/domain_edit_form.html" %}
{% endwith %}
{{ form.form_text({
label:'Name',
name:'uname',
value:system.uname,
autofocus:true,
required:true
}) }}
{{ form.form_text({
label:'Gravatar Email',
help_text:'Will be used as the system icon.',
name:'gravatar',
value:system.gravatar
}) }}
{{ form.form_textarea({
columns:12,
label:'Bulletin',
name:'bio',
value:system.bio,
markdown:true,
required:false
}) }}
<div class="row"><div class="columns">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
<button type="submit" class="rounded primary button">
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends "domain_base.html" %}
{% extends "manage_base.html" %}
{% block domain_content %}
<form method="post">
<div class="section">
+20 -27
View File
@@ -1,4 +1,5 @@
{% extends "domain_base.html" %}
{% set page_name = "domain_manage_role" %}
{% extends "manage_base.html" %}
{% block domain_content %}
<div style="display: none" class="dialog__body--create-role">
<div>
@@ -42,12 +43,26 @@
</label>
</th>
<th class="col--id">{{ _('Role') }}</th>
<th class="col--description">{{ _('Description') }}</th>
<th class="col--users">{{ _('Users') }}</th>
</tr>
</thead>
<tbody>
{% for role, rd in vj4.model.builtin.BUILTIN_ROLE_DESCRIPTORS.items() %}
{% for role in roles %}
{% if role._id not in ['default', 'guest', 'admin'] %}
<tr data-role="{{ role._id }}">
<td class="col--checkbox">
<label class="compact checkbox">
<input type="checkbox" data-checkbox-group="role" data-checkbox-range>
</label>
</td>
<td class="col--id">
{{ _('User-defined role') }}: {{ role._id }}
</td>
<td class="col--users">
{{ role.count }}
</td>
</tr>
{% else %}
<tr>
<td class="col--checkbox">
<label class="compact checkbox">
@@ -55,32 +70,10 @@
</label>
</td>
<td class="col--id">
{{ role }}
</td>
<td class="col--description">
{{ _('Built-in') }}: {{ _(rd.description) }}
{{ _('Built-in') }}: {{ role._id }}
</td>
<td class="col--users">
{{ rucounts.get(role, '--') }}
</td>
</tr>
{% endfor %}
{% for role in roles %}
{% if role not in vj4.model.builtin.BUILTIN_ROLE_DESCRIPTORS %}
<tr data-role="{{ role }}">
<td class="col--checkbox">
<label class="compact checkbox">
<input type="checkbox" data-checkbox-group="role" data-checkbox-range>
</label>
</td>
<td class="col--id">
{{ role }}
</td>
<td class="col--description">
{{ _('User-defined role') }}
</td>
<td class="col--users">
{{ rucounts[role] }}
{{ role.count|default('--') }}
</td>
</tr>
{% endif %}
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends "domain_base.html" %}
{% extends "manage_base.html" %}
{% block domain_content %}
<div style="display: none" class="dialog__body--add-user">
<div>
-36
View File
@@ -1,36 +0,0 @@
{% extends "layout/home_base.html" %}
{% block home_content %}
<div data-heading-extract-to="#menu-item-home_domain">
<div class="section">
<div class="section__header">
<h1 class="section__title" id="create" data-heading>{{ _('Create Domain') }}</h1>
</div>
<div class="section__body">
<blockquote class="note typo">
<p>{{ _('A domain ID cannot be changed after creation. It is supposed to be:') }}</p>
<ul>
<li>{{ _('Unique') }}</li>
<li>{{ _('At least 4 characters') }}</li>
<li>{{ _('Not wrapped with space') }}</li>
<li>{{ _('Not started with a number') }}</li>
<li>{{ _('Only A-Z, a-z, 0-9 and _ are accepted') }}</li>
</ul>
</blockquote>
<form method="post">
{% with ddoc={} %}
{% include "partials/domain_edit_form.html" %}
{% endwith %}
<div class="row"><div class="columns">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
<button type="submit" class="rounded primary button">
{{ _('Create') }}
</button>
<button type="button" class="rounded button" onclick="window.history.go(-1)">
{{ _('Cancel') }}
</button>
</div></div>
</form>
</div>
</div>
</div>
{% endblock %}
-1
View File
@@ -37,7 +37,6 @@
<!--[if lte IE 8]>
<script type="text/javascript" src="{{ static_url('shim.js') }}"></script>
<![endif]-->
<script type="text/javascript" src="{{ static_url('manifest.js') }}"></script>
<script type="text/javascript" src="{{ static_url('locale/{0}.js'.format(handler.user.lang)) }}"></script>
<script type="text/javascript" src="{{ static_url('vj4.js') }}"></script>
</body>
@@ -12,27 +12,20 @@
<span class="icon icon-info"></span> {{ _('Properties') }}
</div>
<ol class="menu collapsed">
{{ sidemenu.render_item(null, 'domain_manage_dashboard') }}
{% if handler.hasPerm(perm.PERM_EDIT_DESCRIPTION) %}
{{ sidemenu.render_item(null, 'domain_manage_edit') }}
{{ sidemenu.render_item(null, 'domain_manage_join_applications') }}
{{ sidemenu.render_item(null, 'domain_manage_discussion') }}
{% endif %}
<!-- Ranking Settings -->
{{ sidemenu.render_item(null, 'domain_manage_dashboard', '/manage/dashboard') }}
{{ sidemenu.render_item(null, 'domain_manage_edit', '/manage/edit') }}
</ol>
</li>
{% if handler.hasPerm(perm.PERM_EDIT_PERM) %}
<li class="menu__item">
<div class="menu__link expandable">
<span class="icon icon-user"></span> {{ _('Access Control') }}
</div>
<ol class="menu collapsed">
{{ sidemenu.render_item(null, 'domain_manage_role') }}
{{ sidemenu.render_item(null, 'domain_manage_user') }}
{{ sidemenu.render_item(null, 'domain_manage_permission') }}
{{ sidemenu.render_item(null, 'domain_manage_role', '/manage/role') }}
{{ sidemenu.render_item(null, 'domain_manage_user', '/manage/user') }}
{{ sidemenu.render_item(null, 'domain_manage_permission', '/manage/permission') }}
</ol>
</li>
{% endif %}
</ol>
</div>
</div></div>
+1 -9
View File
@@ -1,9 +1 @@
{% import "components/form.html" as form with context %}
{% if page_name == 'domain_manage_edit' %}
{{ form.form_text(label='ID', name='id', value=ddoc['_id'], disabled=true) }}
{% elif page_name == 'home_domain_create' %}
{{ form.form_text(label='ID', name='id', autofocus=true, required=true) }}
{% endif %}
{{ form.form_text(label='Name', name='name', value=ddoc['name']|default(''), autofocus=(page_name == 'domain_manage_edit'), required=true) }}
{{ form.form_text(label='Gravatar Email', help_text='Will be used as the domain icon.', name='gravatar', value=ddoc['gravatar']|default('')) }}
{{ form.form_textarea(columns=12, label='Bulletin', name='bulletin', value=ddoc['bulletin']|default(''), markdown=true, required=false) }}
+2 -2
View File
@@ -18,13 +18,13 @@
{{ nav_item('/t', 'training_main', 'training') }}
{% endif %}
{% if handler.hasPerm(perm.PERM_VIEW_DISCUSSION) %}
{{ nav_item('/d', 'discussion_main', 'discussion') }}
{{ nav_item('/discuss', 'discussion_main', 'discussion') }}
{% endif %}
{% if handler.hasPerm(perm.PERM_VIEW_CONTEST) %}
{{ nav_item('/c', 'contest_main', 'contest') }}
{% endif %}
{% if handler.hasPerm(perm.PERM_EDIT_DESCRIPTION) or handler.hasPerm(perm.PERM_EDIT_PERM) %}
{{ nav_item('/d', 'domain_manage', 'domain_manage') }}
{{ nav_item('/manage', 'domain_manage', 'domain_manage') }}
{% endif %}
</ol>
<ol class="nav__list nav__list--secondary clearfix">
@@ -1,19 +0,0 @@
import { NamedPage } from 'vj/misc/PageLoader';
import * as domainEnum from 'vj/constant/domain';
const page = new NamedPage('domain_manage_join_applications', () => {
const $role = $('[name="role"]');
const $expire = $('[name="expire"]');
const $code = $('[name="invitation_code"]');
function updateFormState() {
const method = parseInt($('[name="method"]:checked').val(), 10);
$role.prop('disabled', method === domainEnum.JOIN_METHOD_NONE).trigger('vjFormDisableUpdate');
$expire.prop('disabled', method === domainEnum.JOIN_METHOD_NONE).trigger('vjFormDisableUpdate');
$code.prop('disabled', method !== domainEnum.JOIN_METHOD_CODE).trigger('vjFormDisableUpdate');
}
updateFormState();
$('[name="method"]').change(() => updateFormState());
});
export default page;
+1 -1
View File
@@ -73,7 +73,7 @@ const page = new NamedPage('domain_manage_role', () => {
try {
await request.post('', {
operation: 'delete',
role: selectedRoles,
roles: selectedRoles,
});
Notification.success(i18n('Selected roles have been deleted.'));
await delay(2000);
-3
View File
@@ -2,8 +2,5 @@
.col--checkbox
width: 60px
.col--id
width: 140px
.col--users
width: 100px