core: domain_join: allow auto group assignment

This commit is contained in:
undefined committed 2025-03-23 04:55:28 +08:00
1 parent 917ed3d555
commit ff1605797b
5 files changed
+22 -3

No files matched your search

+9 -2
View File
@@ -280,9 +280,10 @@ class DomainJoinApplicationsHandler extends ManageHandler {
@requireSudo
@post('method', Types.Range([domain.JOIN_METHOD_NONE, domain.JOIN_METHOD_ALL, domain.JOIN_METHOD_CODE]))
@post('role', Types.Role, true)
@post('group', Types.Name, true)
@post('expire', Types.Int, true)
@post('invitationCode', Types.Content, true)
async post(domainId: string, method: number, role: string, expire: number, invitationCode = '') {
async post(domainId: string, method: number, role: string, group = '', expire: number, invitationCode = '') {
const r = await domain.getRoles(this.domain);
const roles = r.map((rl) => rl._id);
const current = domain.getJoinSettings(this.domain, roles);
@@ -291,7 +292,7 @@ class DomainJoinApplicationsHandler extends ManageHandler {
else {
if (!roles.includes(role)) throw new ValidationError('role');
if (!current && expire === domain.JOIN_EXPIRATION_KEEP_CURRENT) throw new ValidationError('expire');
joinSettings = { method, role };
joinSettings = { method, role, group };
if (expire === domain.JOIN_EXPIRATION_KEEP_CURRENT) joinSettings.expire = current.expire;
else if (expire === domain.JOIN_EXPIRATION_UNLIMITED) joinSettings.expire = null;
else if (!domain.JOIN_EXPIRATION_RANGE[expire]) throw new ValidationError('expire');
@@ -377,6 +378,12 @@ class DomainJoinHandler extends Handler {
throw new InvalidJoinInvitationCodeError(target);
}
}
if (this.joinSettings?.group) {
const groups = await user.listGroup(target);
const entry = groups.find((i) => i.name === this.joinSettings.group);
if (!entry) throw new ValidationError('group');
await user.updateGroup(target, entry.name, entry.uids.concat(this.user._id));
}
await Promise.all([
domain.setUserInDomain(target, this.user._id, {
join: true,
+3 -1
View File
@@ -312,6 +312,7 @@ Formula blocks: 공식 블록
fs_upload: 업로드
Gender Visibility: 성별 공개
Gender: 성
Group Assignment (Optional): 그룹 할당 (선택)
Hard Deadline: 마감일
Hash: 해시
Have ALL PERMISSIONS in this domain: 이 그룹에 대한 모든 권한
@@ -387,6 +388,7 @@ Last Update At: '마지막 활동'
LaTeX Expressions: LaTeX 표현
Learn More: 더 알아보기
Leave blank to use numeric pid.: 공란으로 둘 시 자동 배정
Leave: 나가기
Limitations: 제한
Links: 링크
List View: 목록 보기
@@ -680,7 +682,7 @@ Terms of Service: 이용 약관
Test data comes from: Testdata 출처
Testdata Config: Testdata 설정
Text: 본문
Leave: 나가기
The group to join when user joining the domain.: 사용자가 그룹에 참여할 때 자동으로 참여할 그룹
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.: 잘못된 초대 코드
+2
View File
@@ -411,6 +411,7 @@ Generate Testdata: 生成测试数据
Generate: 生成
Gravatar URL Prefix: Gravatar地址前缀
Group / UID: 小组或 UID
Group Assignment (Optional): 小组分配 (可选)
Group Name: 名称
Hard Deadline: 最终截止时间
Hash: 散列
@@ -908,6 +909,7 @@ Text: 文本
The 'default' role applies to ALL REGISTERED USER.: default 角色作用于<b>所有已注册用户</b>
The contest is a flexible time contest. You need to complete the contest within a specified time after you attended.: 本场比赛采用灵活时间模式,你需要在参加后的指定时间内完成比赛。
The domain owner: 域所有者:
The group to join when user joining the domain.: 加入域时自动加入的小组。
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.: 您提供的邀请码无效。
+2
View File
@@ -193,6 +193,7 @@ Forgot password or username?: 忘記密碼或者使用者名?
Formula blocks: 公式區塊
Gender Visibility: 性別可見性
Gender: 性別
Group Assignment (Optional): 小組分配 (選填)
Hard Deadline: 最終截止時間
Have ALL PERMISSIONS in this domain: 在此域中擁有全部許可權
Help: 幫助
@@ -462,6 +463,7 @@ Support: 支援
Technical Information: 技術資訊
Temporary session: 臨時會話
Text: 文字
The group to join when user joining the domain.: 加入域時自動加入的小組。
The homework's deadline is due but in extension. You can still submit for this problem but your score will be penalized.: 功課已經截止,但處於延期時間内。您此時遞交的題目無法獲得全部分數。
Their account will not be deleted and they will be with the guest role until they re-join the domain.: 他們的賬號不會被刪除,並且之後將以 guest 角色訪問,直到他們重新加入域。
There are no contests...: 沒有比賽…
@@ -40,6 +40,12 @@
help_text:'The role to assign when user joining the domain.',
value:joinSettings['role']|default('')
}) }}
{{ form.form_text({
label:'Group Assignment (Optional)',
name:'group',
help_text:'The group to join when user joining the domain.',
value:joinSettings['group']|default('')
}) }}
{{ form.form_select({
options:expirations,
label:'Expire',