mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00

* feat: allow users to select notification types * fix(ui): display personal notification types before management types * fix: update allRequestsAutoApproved check to account for new REQUEST_MOVIE & REQUEST_TV perms * fix(ui): do not display Discord notif type selector if user not eligible for any types * refactor(ui): remove unnecessary 'enabled' checkboxes from user notif settings * fix(ui): correct checkbox behavior * fix: add missing return type on hasNotificationType * refactor: remove unused isValid prop in NotificationsWebPush * fix(ui): use SensitiveInput for users' public PGP keys * fix(ui): add missing tip/hint for email encryption setting * refactor(svg): use the new Discord logo * revert(api): undo breaking change removing discordEnabled from UserSettingsNotificationsResponse * fix(lang): update notification type descriptions for clarity * fix(telegram): do not send users notifications of their own auto-approved requests
118 lines
3.0 KiB
TypeScript
118 lines
3.0 KiB
TypeScript
import {
|
|
Column,
|
|
Entity,
|
|
JoinColumn,
|
|
OneToOne,
|
|
PrimaryGeneratedColumn,
|
|
} from 'typeorm';
|
|
import { NotificationAgentTypes } from '../interfaces/api/userSettingsInterfaces';
|
|
import { hasNotificationType, Notification } from '../lib/notifications';
|
|
import { NotificationAgentKey } from '../lib/settings';
|
|
import { User } from './User';
|
|
|
|
export const ALL_NOTIFICATIONS = Object.values(Notification)
|
|
.filter((v) => !isNaN(Number(v)))
|
|
.reduce((a, v) => a + Number(v), 0);
|
|
|
|
@Entity()
|
|
export class UserSettings {
|
|
constructor(init?: Partial<UserSettings>) {
|
|
Object.assign(this, init);
|
|
}
|
|
|
|
@PrimaryGeneratedColumn()
|
|
public id: number;
|
|
|
|
@OneToOne(() => User, (user) => user.settings, { onDelete: 'CASCADE' })
|
|
@JoinColumn()
|
|
public user: User;
|
|
|
|
@Column({ default: '' })
|
|
public locale?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public region?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public originalLanguage?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public pgpKey?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public discordId?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public telegramChatId?: string;
|
|
|
|
@Column({ nullable: true })
|
|
public telegramSendSilently?: boolean;
|
|
|
|
@Column({
|
|
type: 'text',
|
|
nullable: true,
|
|
transformer: {
|
|
from: (value: string | null): Partial<NotificationAgentTypes> => {
|
|
const defaultTypes = {
|
|
email: ALL_NOTIFICATIONS,
|
|
discord: 0,
|
|
pushbullet: 0,
|
|
pushover: 0,
|
|
slack: 0,
|
|
telegram: 0,
|
|
webhook: 0,
|
|
webpush: ALL_NOTIFICATIONS,
|
|
};
|
|
if (!value) {
|
|
return defaultTypes;
|
|
}
|
|
|
|
const values = JSON.parse(value) as Partial<NotificationAgentTypes>;
|
|
|
|
// Something with the migration to this field has caused some issue where
|
|
// the value pre-populates with just a raw "2"? Here we check if that's the case
|
|
// and return the default notification types if so
|
|
if (typeof values !== 'object') {
|
|
return defaultTypes;
|
|
}
|
|
|
|
if (values.email == null) {
|
|
values.email = ALL_NOTIFICATIONS;
|
|
}
|
|
|
|
if (values.webpush == null) {
|
|
values.webpush = ALL_NOTIFICATIONS;
|
|
}
|
|
|
|
return values;
|
|
},
|
|
to: (value: Partial<NotificationAgentTypes>): string | null => {
|
|
if (!value || typeof value !== 'object') {
|
|
return null;
|
|
}
|
|
|
|
const allowedKeys = Object.values(NotificationAgentKey);
|
|
|
|
// Remove any unknown notification agent keys before saving to db
|
|
(Object.keys(value) as (keyof NotificationAgentTypes)[]).forEach(
|
|
(key) => {
|
|
if (!allowedKeys.includes(key)) {
|
|
delete value[key];
|
|
}
|
|
}
|
|
);
|
|
|
|
return JSON.stringify(value);
|
|
},
|
|
},
|
|
})
|
|
public notificationTypes: Partial<NotificationAgentTypes>;
|
|
|
|
public hasNotificationType(
|
|
key: NotificationAgentKey,
|
|
type: Notification
|
|
): boolean {
|
|
return hasNotificationType(type, this.notificationTypes[key] ?? 0);
|
|
}
|
|
}
|