* fix: fix improper authorization when accessing with third-party application
* refactor: refactor type definitions
* fix: get rid of unnecessary access limitation
* enhance: サードパーティアプリケーションがWebsocket APIを使えるように
* fix: add missing parentheses
* Revert "fix(backend): add missing kind definition for admin endpoints to improve security"
This reverts commit 5150053275
.
* frontend: 翻訳の抜けを訂正, read:adminとwrite:adminはアクセス発行トークンのデフォルトでは非表示にする
* enhance(test): misskey-ghsa-7pxq-6xx9-xpgmに関するテストを追加
* enhance(test): Websocket APIに対するテストも追加
* enhance(refactor): `@/misc/api-permissions.ts`を`misskey-js/permissions`に統合
* fix(frontend): アクセストークン発行UIで全ての権限を有効にした際、管理者用APIへのアクセスも許可してしまう問題を修正
* enhance(backend): Websocketの接続に最低限必要な権限を変更
* fix(backend): `/api/admin/meta`をサードパーティアプリケーションからはアクセスできないように
* fix(backend): エンドポイントにアクセスするために必要な権限を変更
* fix(frontend/locale): Add missing type declaration
* chore: update `misskey-js/src/autogen`
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
76 lines
2 KiB
TypeScript
76 lines
2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import type { RegistrationTicketsRepository } from '@/models/_.js';
|
|
import { RoleService } from '@/core/RoleService.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ApiError } from '../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['meta'],
|
|
|
|
requireCredential: true,
|
|
requireRolePolicy: 'canInvite',
|
|
kind: 'write:invite-codes',
|
|
|
|
errors: {
|
|
noSuchCode: {
|
|
message: 'No such invite code.',
|
|
code: 'NO_SUCH_INVITE_CODE',
|
|
id: 'cd4f9ae4-7854-4e3e-8df9-c296f051e634',
|
|
},
|
|
|
|
cantDelete: {
|
|
message: 'You can\'t delete this invite code.',
|
|
code: 'CAN_NOT_DELETE_INVITE_CODE',
|
|
id: 'ff17af39-000c-4d4e-abdf-848fa30fc1ce',
|
|
},
|
|
|
|
accessDenied: {
|
|
message: 'Access denied.',
|
|
code: 'ACCESS_DENIED',
|
|
id: '5eb8d909-2540-4970-90b8-dd6f86088121',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
inviteId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['inviteId'],
|
|
} as const;
|
|
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
|
constructor(
|
|
@Inject(DI.registrationTicketsRepository)
|
|
private registrationTicketsRepository: RegistrationTicketsRepository,
|
|
|
|
private roleService: RoleService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const ticket = await this.registrationTicketsRepository.findOneBy({ id: ps.inviteId });
|
|
const isModerator = await this.roleService.isModerator(me);
|
|
|
|
if (ticket == null) {
|
|
throw new ApiError(meta.errors.noSuchCode);
|
|
}
|
|
|
|
if (ticket.createdById !== me.id && !isModerator) {
|
|
throw new ApiError(meta.errors.accessDenied);
|
|
}
|
|
|
|
if (ticket.usedAt && !isModerator) {
|
|
throw new ApiError(meta.errors.cantDelete);
|
|
}
|
|
|
|
await this.registrationTicketsRepository.delete(ticket.id);
|
|
});
|
|
}
|
|
}
|