mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-02 22:46:40 +09:00
enhance: make configurable to whether notes search available by role
Resolve #10318
This commit is contained in:
@ -21,6 +21,7 @@ export type RolePolicies = {
|
||||
canPublicNote: boolean;
|
||||
canInvite: boolean;
|
||||
canManageCustomEmojis: boolean;
|
||||
canSearchNotes: boolean;
|
||||
canHideAds: boolean;
|
||||
driveCapacityMb: number;
|
||||
pinLimit: number;
|
||||
@ -40,6 +41,7 @@ export const DEFAULT_POLICIES: RolePolicies = {
|
||||
canPublicNote: true,
|
||||
canInvite: false,
|
||||
canManageCustomEmojis: false,
|
||||
canSearchNotes: false,
|
||||
canHideAds: false,
|
||||
driveCapacityMb: 100,
|
||||
pinLimit: 5,
|
||||
@ -264,6 +266,7 @@ export class RoleService implements OnApplicationShutdown {
|
||||
canPublicNote: calc('canPublicNote', vs => vs.some(v => v === true)),
|
||||
canInvite: calc('canInvite', vs => vs.some(v => v === true)),
|
||||
canManageCustomEmojis: calc('canManageCustomEmojis', vs => vs.some(v => v === true)),
|
||||
canSearchNotes: calc('canSearchNotes', vs => vs.some(v => v === true)),
|
||||
canHideAds: calc('canHideAds', vs => vs.some(v => v === true)),
|
||||
driveCapacityMb: calc('driveCapacityMb', vs => Math.max(...vs)),
|
||||
pinLimit: calc('pinLimit', vs => Math.max(...vs)),
|
||||
|
@ -6,6 +6,8 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['notes'],
|
||||
@ -23,6 +25,11 @@ export const meta = {
|
||||
},
|
||||
|
||||
errors: {
|
||||
unavailable: {
|
||||
message: 'Search of notes unavailable.',
|
||||
code: 'UNAVAILABLE',
|
||||
id: '0b44998d-77aa-4427-80d0-d2c9b8523011',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
@ -59,8 +66,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
|
||||
private noteEntityService: NoteEntityService,
|
||||
private queryService: QueryService,
|
||||
private roleService: RoleService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
|
||||
if (!policies.canSearchNotes) {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
|
||||
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId);
|
||||
|
||||
if (ps.userId) {
|
||||
|
Reference in New Issue
Block a user