mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: support ban user from domain
This commit is contained in:
8 files changed
+15
-6
No files matched your search
@@ -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.");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]>>(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user