diff --git a/packages/hydrooj/locales/zh.yaml b/packages/hydrooj/locales/zh.yaml index 97a579d76..988e63af5 100644 --- a/packages/hydrooj/locales/zh.yaml +++ b/packages/hydrooj/locales/zh.yaml @@ -787,6 +787,7 @@ The discussion is locked, you can not reply anymore.: 此讨论已经锁定, The homework's deadline is due but in extension. You can still submit for this problem but your score will be penalized.: 作业已超过截止时间,但仍在延期时间内。您递交题目将无法获得全部分数。 The invitation code to enter to successfully join the domain. You can only use letters and numbers in the code and it should not be longer than 64 characters.: 加入此域的邀请码。您只能使用字母和数字,并且不能长于 64 个字符。 The invitation code you provided is invalid.: 您提供的邀请码无效。 +The link is either invalid or expired.: 加域链接无效或已过期。 The link will be expired at {0}: 链接将于 {0} 过期 The role to assign when user joining the domain.: 用户加入此域时分配的角色。 The uploaded file is too long.: 上传的文件太长。 @@ -925,7 +926,8 @@ Write Your Comment: 发表您的评论 Write Your Solution: 发表您的题解 WYSIWYG: 所见即所得 Year: 年 -You are not allowed to join the domain. The link is either invalid or expired.: 您无法加入该域,链接无效或已过期。 +You are banned by the domain moderator.: 您被该域的管理员封禁。 +You are not allowed to join domain {0}. {1}: 您无法加入 {0}。{1} You can create your own training plans and share them with others.: 您可以创建您自己的训练计划并且与他人分享。 You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.: 该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。 You cannot submit for this problem because the homework's deadline is due.: 作业已超过截止时间,您无法递交本题目。 diff --git a/packages/hydrooj/locales/zh_TW.yaml b/packages/hydrooj/locales/zh_TW.yaml index e16a4dedb..e5b87ed13 100644 --- a/packages/hydrooj/locales/zh_TW.yaml +++ b/packages/hydrooj/locales/zh_TW.yaml @@ -463,6 +463,7 @@ Technical Information: 技術資訊 Temporary session: 臨時會話 Text: 文字 The homework's deadline is due but in extension. You can still submit for this problem but your score will be penalized.: 功課已經截止,但處於延期時間内。您此時遞交的題目無法獲得全部分數。 +The link is either invalid or expired.: 加域鏈接無效或已過期。 There are no contests...: 沒有比賽… There is no homework so far ╰(*°▽°*)╯: 目前沒有功課 ╰(*°▽°*)╯ This contest is not live.: 比賽沒有開始。 @@ -545,6 +546,8 @@ Will be used as the domain icon.: 將被用作圖示。 Without slashes or backslashes: 不含斜槓和反斜槓 Write Your Comment: 發表您的評論 Write Your Solution: 發表您的題解 +You are banned by the domain moderator.: 您被該域的管理員封禁。 +You are not allowed to join domain {0}. {1}: 您無法加入 {0}。{1} You can create your own training plans and share them with others.: 您可以創建您自己的訓練計劃並且與他人分享。 You cannot submit for this problem because the homework's deadline is due.: 功課已到達截止時間,您無法遞交了。 You don't have the required permission ({0}) in this domain.: 您在該域中無相應許可權 ({0})。 diff --git a/packages/hydrooj/src/error.ts b/packages/hydrooj/src/error.ts index 9ddbbe7cf..94d42010e 100644 --- a/packages/hydrooj/src/error.ts +++ b/packages/hydrooj/src/error.ts @@ -42,7 +42,7 @@ export const HomeworkNotLiveError = Err('HomeworkNotLiveError', ForbiddenError, export const HomeworkNotAttendedError = Err('HomeworkNotAttendedError', ForbiddenError, "You haven't claimed this homework yet."); export const RoleAlreadyExistError = Err('RoleAlreadyExistError', ForbiddenError, 'This role already exists.'); export const DomainAlreadyExistsError = Err('DomainAlreadyExistsError', ForbiddenError, 'The domain {0} already exists.'); -export const DomainJoinForbiddenError = Err('DomainJoinForbiddenError', ForbiddenError, 'You are not allowed to join the domain. The link is either invalid or expired.'); +export const DomainJoinForbiddenError = Err('DomainJoinForbiddenError', ForbiddenError, 'You are not allowed to join domain {0}. {1}'); export const DomainJoinAlreadyMemberError = Err('DomainJoinAlreadyMemberError', ForbiddenError, 'Failed to join the domain. You are already a member.'); export const InvalidJoinInvitationCodeError = Err('InvalidJoinInvitationCodeError', ForbiddenError, 'The invitation code you provided is invalid.'); export const CurrentPasswordError = Err('CurrentPasswordError', ForbiddenError, "Current password doesn't match."); diff --git a/packages/hydrooj/src/handler/domain.ts b/packages/hydrooj/src/handler/domain.ts index ff9f6d625..a45e01d87 100644 --- a/packages/hydrooj/src/handler/domain.ts +++ b/packages/hydrooj/src/handler/domain.ts @@ -345,7 +345,8 @@ class DomainJoinHandler extends Handler { const roles = r.map((role) => role._id); this.joinSettings = domain.getJoinSettings(ddoc, roles); if (assignedRole !== 'default') delete this.joinSettings; - else if (!this.joinSettings) throw new DomainJoinForbiddenError(target); + else if (!this.joinSettings) throw new DomainJoinForbiddenError(target, 'The link is either invalid or expired.'); + if (assignedRole === 'guest') throw new DomainJoinForbiddenError(target, 'You are banned by the domain moderator.'); } @param('code', Types.Content, true) diff --git a/packages/hydrooj/src/handler/home.ts b/packages/hydrooj/src/handler/home.ts index 5366e42f1..db4665ea3 100644 --- a/packages/hydrooj/src/handler/home.ts +++ b/packages/hydrooj/src/handler/home.ts @@ -7,7 +7,7 @@ import { Binary, ObjectId } from 'mongodb'; import { UAParser } from 'ua-parser-js'; import { Context } from '../context'; import { - AuthOperationError, BlacklistedError, DomainAlreadyExistsError, InvalidTokenError, + AuthOperationError, BadRequestError, BlacklistedError, DomainAlreadyExistsError, InvalidTokenError, NotFoundError, PermissionError, UserAlreadyExistError, UserNotFoundError, ValidationError, VerifyPasswordError, } from '../error'; @@ -507,6 +507,7 @@ class HomeDomainHandler extends Handler { @param('id', Types.String) async postLeave({ }, id: string) { + if (id === 'system') throw new BadRequestError(); const ddoc = await domain.get(id); if (!ddoc) throw new NotFoundError(id); await domain.setJoin(id, this.user._id, false); diff --git a/packages/hydrooj/src/model/document.ts b/packages/hydrooj/src/model/document.ts index c4263ccbe..850930daa 100644 --- a/packages/hydrooj/src/model/document.ts +++ b/packages/hydrooj/src/model/document.ts @@ -201,7 +201,7 @@ export async function push( { $push: { [key]: v } }, { returnDocument: 'after' }, ); - return [doc.value, _id]; + return [doc, _id]; } export async function pull>( diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index efbe5a0a9..7e4e53e91 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -707,7 +707,7 @@ export const coreScripts: MigrationScript[] = [ async function _91_92() { await domain.collUser.updateMany({}, { $set: { join: true } }); await domain.coll.updateMany( - { $or: [{ _join: { $exists: false } }, { _join: { $eq: null } }] }, + { $or: [{ _join: { $exists: false } }, { _join: { $eq: null } }, { '_join.method': domain.JOIN_METHOD_NONE }] }, { $set: { _join: { method: domain.JOIN_METHOD_ALL, role: 'default', expire: null }, _migratedJoin: true } }, ); const domainUser = await domain.coll.find({ domainId: 'system', join: true }, onPrimary) diff --git a/packages/ui-default/templates/home_domain.html b/packages/ui-default/templates/home_domain.html index 329f4be30..dab5fca7a 100644 --- a/packages/ui-default/templates/home_domain.html +++ b/packages/ui-default/templates/home_domain.html @@ -44,11 +44,13 @@ {% if canManage[ddoc['_id']] %} · {{ _('Manage') }} {% endif %} + {% if ddoc['_id'] != 'system' and ddoc['owner'] != handler.user._id %} ·
+ {% endif %} {%- endfor -%}