forRoles IS NOT NULL, coalesce to empty=unrestricted
This commit is contained in:
parent
f3b5c3f447
commit
b61c1d5b27
9 changed files with 16 additions and 16 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() })`);
|
||||
|
||||
|
|
|
|||
|
|
@ -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', {
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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' },
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue