mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
加域申请管理
This commit is contained in:
1 parent
16108993cf
commit
c3ff5856e4
16 files changed
+165
-33
No files matched your search
@@ -24,7 +24,7 @@ const ContestHandler = contest.ContestHandlerMixin(Handler);
|
||||
|
||||
class ContestListHandler extends ContestHandler {
|
||||
@param('rule', Types.String, true)
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, rule = '', page = 1) {
|
||||
this.response.template = 'contest_main.html';
|
||||
let tdocs;
|
||||
@@ -55,7 +55,7 @@ class ContestListHandler extends ContestHandler {
|
||||
|
||||
class ContestDetailHandler extends ContestHandler {
|
||||
@param('tid', Types.ObjectID)
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, tid: ObjectID, page = 1) {
|
||||
const tdoc = await contest.get(domainId, tid);
|
||||
this.response.template = 'contest_detail.html';
|
||||
|
||||
@@ -71,7 +71,7 @@ class DiscussionHandler extends Handler {
|
||||
}
|
||||
|
||||
class DiscussionMainHandler extends Handler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
const [ddocs, dpcount] = await paginate(
|
||||
discussion.getMulti(domainId),
|
||||
@@ -99,7 +99,7 @@ class DiscussionMainHandler extends Handler {
|
||||
class DiscussionNodeHandler extends DiscussionHandler {
|
||||
@param('type', Types.String)
|
||||
@param('name', Types.String)
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, type: string, _name: string, page = 1) {
|
||||
let name: ObjectID | string | number;
|
||||
if (ObjectID.isValid(_name)) name = new ObjectID(_name);
|
||||
@@ -177,7 +177,7 @@ class DiscussionCreateHandler extends DiscussionHandler {
|
||||
|
||||
class DiscussionDetailHandler extends DiscussionHandler {
|
||||
@param('did', Types.ObjectID)
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, did: ObjectID, page = 1) {
|
||||
const dsdoc = this.user.hasPriv(PRIV.PRIV_USER_PROFILE)
|
||||
? await discussion.getStatus(domainId, did, this.user._id)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { RoleAlreadyExistError, ValidationError } from '../error';
|
||||
import moment from 'moment-timezone';
|
||||
import {
|
||||
RoleAlreadyExistError, ValidationError, DomainJoinForbiddenError,
|
||||
DomainJoinAlreadyMemberError, InvalidJoinInvitationCodeError,
|
||||
} from '../error';
|
||||
import * as user from '../model/user';
|
||||
import * as domain from '../model/domain';
|
||||
import { DOMAIN_SETTINGS, DOMAIN_SETTINGS_BY_KEY } from '../model/setting';
|
||||
@@ -10,7 +14,7 @@ import {
|
||||
} from '../service/server';
|
||||
|
||||
class DomainRankHandler extends Handler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
const [dudocs, upcount, ucount] = await paginate(
|
||||
domain.getMultiInDomain(domainId).sort({ rp: -1 }),
|
||||
@@ -184,6 +188,75 @@ class DomainRoleHandler extends ManageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
class DomainJoinApplicationsHandler extends ManageHandler {
|
||||
async get() {
|
||||
const r = await domain.getRoles(this.domain);
|
||||
const roles = r.map((role) => role._id).sort();
|
||||
const rolesWithText = roles.map((role) => [role, role]);
|
||||
const joinSettings = domain.getJoinSettings(this.domain, roles);
|
||||
const expirations = { ...domain.JOIN_EXPIRATION_RANGE };
|
||||
if (!joinSettings) delete expirations[domain.JOIN_EXPIRATION_KEEP_CURRENT];
|
||||
this.response.template = 'domain_join_applications.html';
|
||||
this.response.body = { rolesWithText, joinSettings, expirations };
|
||||
}
|
||||
|
||||
@param('method', Types.UnsignedInt)
|
||||
@param('role', Types.String, true)
|
||||
@param('expire', Types.UnsignedInt, true)
|
||||
@param('invitationCode', Types.String, true)
|
||||
async post(domainId: string, method: number, role: string, expire: number, invitationCode = '') {
|
||||
const r = await domain.getRoles(this.domain);
|
||||
const roles = r.map((rl) => rl._id);
|
||||
const current = domain.getJoinSettings(this.domain, roles);
|
||||
if (!domain.JOIN_METHOD_RANGE[method]) throw new ValidationError('method');
|
||||
let joinSettings;
|
||||
if (method === domain.JOIN_METHOD_NONE) joinSettings = null;
|
||||
else {
|
||||
if (!roles.includes(role)) throw new ValidationError('role');
|
||||
if (!domain.JOIN_EXPIRATION_RANGE[expire]) throw new ValidationError('expire');
|
||||
if (!current && expire === domain.JOIN_EXPIRATION_KEEP_CURRENT) throw new ValidationError('expire');
|
||||
joinSettings = { method, role };
|
||||
if (method === domain.JOIN_METHOD_CODE) joinSettings.code = invitationCode;
|
||||
if (expire === domain.JOIN_EXPIRATION_KEEP_CURRENT) {
|
||||
joinSettings.expire = current.expire;
|
||||
} else if (expire === domain.JOIN_EXPIRATION_UNLIMITED) joinSettings.expire = null;
|
||||
else joinSettings.expire = moment().add(expire, 'hours').toDate();
|
||||
}
|
||||
await domain.edit(this.domain._id, { join: joinSettings });
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class DomainJoinHandler extends Handler {
|
||||
joinSettings: any;
|
||||
|
||||
async prepare() {
|
||||
const r = await domain.getRoles(this.domain);
|
||||
const roles = r.map((role) => role._id);
|
||||
this.joinSettings = domain.getJoinSettings(this.domain, roles);
|
||||
if (!this.joinSettings) throw new DomainJoinForbiddenError(this.domain._id);
|
||||
if (this.user.role !== 'default') throw new DomainJoinAlreadyMemberError(this.domain._id, this.user._id);
|
||||
}
|
||||
|
||||
// @base.require_priv(builtin.PRIV_USER_PROFILE)
|
||||
@param('code', Types.String, true)
|
||||
async get(domainId: string, code: string) {
|
||||
this.response.template = 'domain_join.html';
|
||||
this.response.body = { joinSettings: this.joinSettings, code };
|
||||
}
|
||||
|
||||
@param('code', Types.String, true)
|
||||
async post(domainId: string, code: string) {
|
||||
if (this.joinSettings.method === domain.JOIN_METHOD_CODE) {
|
||||
if (this.joinSettings.code !== code) {
|
||||
throw new InvalidJoinInvitationCodeError(this.domain._id);
|
||||
}
|
||||
}
|
||||
await domain.setUserRole(this.domain._id, this.user._id, this.joinSettings.role);
|
||||
this.response.redirect = this.url('domain_main');
|
||||
}
|
||||
}
|
||||
|
||||
class DomainSearchHandler extends Handler {
|
||||
@param('q', Types.String)
|
||||
async get(domainId: string, q: string) {
|
||||
@@ -202,6 +275,8 @@ export async function apply() {
|
||||
Route('domain_user', '/domain/user', DomainUserHandler);
|
||||
Route('domain_permission', '/domain/permission', DomainPermissionHandler);
|
||||
Route('domain_role', '/domain/role', DomainRoleHandler);
|
||||
Route('domain_join_applications', '/domain/join_applications', DomainJoinApplicationsHandler);
|
||||
Route('domain_join', '/domain/join', DomainJoinHandler, PRIV.PRIV_USER_PROFILE);
|
||||
Route('domain_search', '/domain/search', DomainSearchHandler, PRIV.PRIV_USER_PROFILE);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class HomeworkMainHandler extends HomeworkHandler {
|
||||
|
||||
class HomeworkDetailHandler extends HomeworkHandler {
|
||||
@param('tid', Types.ObjectID)
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, tid: ObjectID, page = 1) {
|
||||
const tdoc = await contest.get(domainId, tid, document.TYPE_HOMEWORK);
|
||||
const [tsdoc, pdict] = await Promise.all([
|
||||
|
||||
@@ -57,7 +57,7 @@ class ProblemHandler extends Handler {
|
||||
}
|
||||
|
||||
class ProblemMainHandler extends ProblemHandler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@param('q', Types.String, true)
|
||||
async get(domainId: string, page = 1, q = '') {
|
||||
this.response.template = 'problem_main.html';
|
||||
@@ -103,7 +103,7 @@ class ProblemMainHandler extends ProblemHandler {
|
||||
}
|
||||
|
||||
class ProblemCategoryHandler extends ProblemHandler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@param('category', Types.String, null, parseCategory)
|
||||
async get(domainId: string, page = 1, category: string[]) {
|
||||
this.response.template = 'problem_main.html';
|
||||
@@ -469,7 +469,7 @@ class ProblemDataDownloadHandler extends ProblemDetailHandler {
|
||||
}
|
||||
|
||||
class ProblemSolutionHandler extends ProblemDetailHandler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
this.response.template = 'problem_solution.html';
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Rdoc } from '../interface';
|
||||
const RecordHandler = contest.ContestHandlerMixin(Handler);
|
||||
|
||||
class RecordListHandler extends RecordHandler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@param('pid', Types.String, true)
|
||||
@param('tid', Types.ObjectID, true)
|
||||
@param('uidOrName', Types.String, true)
|
||||
|
||||
@@ -54,7 +54,7 @@ async function _parseDagJson(domainId, dag) {
|
||||
}
|
||||
|
||||
class TrainingMainHandler extends Handler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
const [tdocs, tpcount] = await paginate(
|
||||
training.getMulti(domainId),
|
||||
|
||||
Reference in new issue
Block a user