core: support ban user from domain

This commit is contained in:
undefined committed 2025-03-23 05:04:38 +08:00
1 parent ff1605797b
commit 7ed859be2d
8 files changed
+15 -6

No files matched your search

+1 -1
View File
@@ -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.");
+2 -1
View File
@@ -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)
+2 -1
View File
@@ -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);
+1 -1
View File
@@ -201,7 +201,7 @@ export async function push(
{ $push: { [key]: v } },
{ returnDocument: 'after' },
);
return [doc.value, _id];
return [doc, _id];
}
export async function pull<K extends keyof DocType, T extends ArrayKeys<DocType[K]>>(
+1 -1
View File
@@ -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)