forRoles IS NOT NULL, coalesce to empty=unrestricted

This commit is contained in:
наб 2025-07-22 00:26:05 +02:00
parent f3b5c3f447
commit b61c1d5b27
No known key found for this signature in database
GPG key ID: BCFD0B018D2658F1
9 changed files with 16 additions and 16 deletions

View file

@ -5,7 +5,7 @@
export class AnnouncementForRoles1752352800438 {
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "announcement" ADD "forRoles" text[] DEFAULT null`);
await queryRunner.query(`ALTER TABLE "announcement" ADD "forRoles" text[] DEFAULT '{}'`);
}
async down(queryRunner) {

View file

@ -63,7 +63,7 @@ export class AnnouncementService {
}))
.andWhere(new Brackets(qb => {
qb.orWhere('announcement.forRoles && :roles', { roles: roles.map((r) => r.id) });
qb.orWhere('announcement.forRoles IS NULL');
qb.orWhere('announcement.forRoles = \'{}\'');
}))
.andWhere(`announcement.id NOT IN (${ readsQuery.getQuery() })`);

View file

@ -69,9 +69,9 @@ export class MiAnnouncement {
@Column('text', {
array: true,
default: null, nullable: true,
default: '{}', nullable: false,
})
public forRoles: MiRole['id'][] | null;
public forRoles: MiRole['id'][];
@Index()
@Column('boolean', {

View file

@ -59,7 +59,7 @@ export const paramDef = {
icon: { type: 'string', enum: ['info', 'warning', 'error', 'success'], default: 'info' },
display: { type: 'string', enum: ['normal', 'banner', 'dialog'], default: 'normal' },
forExistingUsers: { type: 'boolean', default: false },
forRoles: { type: 'array', nullable: true, default: null, items: { type: 'string', nullable: false, format: 'misskey:id' }, },
forRoles: { type: 'array', default: [], items: { type: 'string', nullable: false, format: 'misskey:id' }, },
silence: { type: 'boolean', default: false },
needConfirmationToRead: { type: 'boolean', default: false },
confetti: { type: 'boolean', default: false },

View file

@ -59,7 +59,7 @@ export const meta = {
},
forRoles: {
type: 'array',
optional: false, nullable: true,
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,

View file

@ -36,7 +36,7 @@ export const paramDef = {
icon: { type: 'string', enum: ['info', 'warning', 'error', 'success'] },
display: { type: 'string', enum: ['normal', 'banner', 'dialog'] },
forExistingUsers: { type: 'boolean' },
forRoles: { type: 'array', nullable: true, default: null, items: { type: 'string', nullable: false, format: 'misskey:id' }, },
forRoles: { type: 'array', default: [], items: { type: 'string', nullable: false, format: 'misskey:id' }, },
silence: { type: 'boolean' },
needConfirmationToRead: { type: 'boolean' },
confetti: { type: 'boolean' },

View file

@ -65,7 +65,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}))
.andWhere(new Brackets(qb => {
if (me) qb.orWhere('announcement.forRoles && :roles', { roles: roles.map((r) => r.id) });
qb.orWhere('announcement.forRoles IS NULL');
qb.orWhere('announcement.forRoles = \'{}\'');
}));
const announcements = await query.limit(ps.limit).getMany();

View file

@ -76,7 +76,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</MkDisableSection>
<div :class="$style.forRoles">
<MkInfo v-if="announcement.forRoles" :class="$style.forRolesLabel">{{ i18n.tsx._announcement.onlyForRolesRestricted({roles: announcement.forRoles.length}) }}</MkInfo>
<MkInfo v-if="announcement.forRoles.length !== 0" :class="$style.forRolesLabel">{{ i18n.tsx._announcement.onlyForRolesRestricted({roles: announcement.forRoles.length}) }}</MkInfo>
<MkInfo v-else :class="$style.forRolesLabel">{{ i18n.ts._announcement.onlyForRolesUnrestricted }}</MkInfo>
<MkButton primary @click="() => changeRoles(announcement)">
{{ i18n.ts._announcement.onlyForRolesChange }}
@ -141,7 +141,7 @@ function add() {
silence: false,
needConfirmationToRead: false,
confetti: false,
forRoles: null,
forRoles: [],
});
}
@ -153,7 +153,7 @@ async function changeRoles(announcement) {
});
if (result.canceled) return;
announcement.forRoles = result.result.length !== 0 ? result.result.map((r) => r.id) : null;
announcement.forRoles = result.result.map((r) => r.id);
}
function del(announcement) {

View file

@ -6694,8 +6694,8 @@ export type operations = {
display?: 'normal' | 'banner' | 'dialog';
/** @default false */
forExistingUsers?: boolean;
/** @default null */
forRoles?: string[] | null;
/** @default [] */
forRoles?: string[];
/** @default false */
silence?: boolean;
/** @default false */
@ -6858,7 +6858,7 @@ export type operations = {
title: string;
imageUrl: string | null;
reads: number;
forRoles: string[] | null;
forRoles: string[];
})[];
};
};
@ -6914,8 +6914,8 @@ export type operations = {
/** @enum {string} */
display?: 'normal' | 'banner' | 'dialog';
forExistingUsers?: boolean;
/** @default null */
forRoles?: string[] | null;
/** @default [] */
forRoles?: string[];
silence?: boolean;
needConfirmationToRead?: boolean;
confetti?: boolean;