({ domainId }, target: string = domainId)
| 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) |
nothing calls this directly
no test coverage detected