spec(skeb/role): Skeb募集中のクリエイターに自動でロールが付与されるように・バッジから募集状態の確認ができるように (MisskeyIO#593)
This commit is contained in:
parent
31ebd77e8a
commit
95838a036e
29 changed files with 323 additions and 44 deletions
|
|
@ -36,6 +36,7 @@ export const paramDef = {
|
|||
isAdministrator: { type: 'boolean' },
|
||||
isExplorable: { type: 'boolean', default: false }, // optional for backward compatibility
|
||||
asBadge: { type: 'boolean' },
|
||||
badgeBehavior: { type: 'string', nullable: true },
|
||||
canEditMembersByModerator: { type: 'boolean' },
|
||||
displayOrder: { type: 'number' },
|
||||
policies: {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export const paramDef = {
|
|||
isAdministrator: { type: 'boolean' },
|
||||
isExplorable: { type: 'boolean' },
|
||||
asBadge: { type: 'boolean' },
|
||||
badgeBehavior: { type: 'string', nullable: true },
|
||||
canEditMembersByModerator: { type: 'boolean' },
|
||||
displayOrder: { type: 'number' },
|
||||
policies: {
|
||||
|
|
@ -92,6 +93,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
isAdministrator: ps.isAdministrator,
|
||||
isExplorable: ps.isExplorable,
|
||||
asBadge: ps.asBadge,
|
||||
badgeBehavior: ps.badgeBehavior,
|
||||
canEditMembersByModerator: ps.canEditMembersByModerator,
|
||||
displayOrder: ps.displayOrder,
|
||||
policies: ps.policies,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import type { Config } from '@/config.js';
|
||||
|
|
@ -88,6 +89,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
@Inject(DI.config)
|
||||
private config: Config,
|
||||
|
||||
private roleService: RoleService,
|
||||
private loggerService: LoggerService,
|
||||
private httpRequestService: HttpRequestService,
|
||||
) {
|
||||
|
|
@ -128,13 +130,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
error?: unknown,
|
||||
};
|
||||
|
||||
if (res.status > 399 || (json.error ?? json.ban_reason)) {
|
||||
const hasSkebRole = await this.roleService.getUserRoles(ps.userId).then(roles => roles.some(r => r.id === this.config.skebStatus?.roleId));
|
||||
|
||||
if (res.status > 299 || (json.error ?? json.ban_reason)) {
|
||||
logger.error('Skeb status response error', { url: url.href, userId: ps.userId, status: res.status, statusText: res.statusText, error: json.error ?? json.ban_reason });
|
||||
if (res.status === 404 && hasSkebRole) await this.roleService.unassign(ps.userId, this.config.skebStatus.roleId);
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
}
|
||||
|
||||
logger.info('Skeb status response', { url: url.href, userId: ps.userId, status: res.status, statusText: res.statusText, skebStatus: json });
|
||||
|
||||
if (json.is_acceptable) {
|
||||
if (!hasSkebRole) await this.roleService.assign(ps.userId, this.config.skebStatus.roleId);
|
||||
} else if (hasSkebRole) {
|
||||
await this.roleService.unassign(ps.userId, this.config.skebStatus.roleId);
|
||||
}
|
||||
|
||||
return {
|
||||
screenName: json.screen_name,
|
||||
isCreator: json.is_creator,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue