MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / prepare

Method prepare

packages/hydrooj/src/handler/domain.ts:345–361  ·  view source on GitHub ↗
({ domainId }, target: string = domainId)

Source from the content-addressed store, hash-verified

343
344 @param('target', Types.DomainId, true)
345 async prepare({ domainId }, target: string = domainId) {
346 const [ddoc, dudoc] = await Promise.all([
347 domain.get(target),
348 domain.collUser.findOne({ domainId: target, uid: this.user._id }),
349 ]);
350 if (!ddoc) throw new NotFoundError(target);
351 const assignedRole = this.user.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN)
352 ? 'root'
353 : dudoc?.role || 'default';
354 if (dudoc?.join) throw new DomainJoinAlreadyMemberError(target, this.user._id);
355 const r = await domain.getRoles(ddoc);
356 const roles = r.map((role) => role._id);
357 this.joinSettings = domain.getJoinSettings(ddoc, roles);
358 if (assignedRole !== 'default') delete this.joinSettings;
359 else if (!this.joinSettings) throw new DomainJoinForbiddenError(target, 'The link is either invalid or expired.');
360 if (assignedRole === 'guest') throw new DomainJoinForbiddenError(target, 'You are banned by the domain moderator.');
361 }
362
363 @param('code', Types.Content, true)
364 @param('target', Types.DomainId, true)

Callers

nothing calls this directly

Calls 5

hasPrivMethod · 0.80
getRolesMethod · 0.80
getJoinSettingsMethod · 0.80
allMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected