mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 01:38:19 +08:00
fix role manage
This commit is contained in:
1 parent
15d43636c0
commit
42e534615e
34 files changed
+221
-314
No files matched your search
@@ -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
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user