mirror of
https://github.com/immich-app/immich.git
synced 2025-06-02 21:24:28 -04:00
refactor: notification-admin controller (#17748)
This commit is contained in:
parent
f0ff8581da
commit
488dc4efbd
4
mobile/openapi/README.md
generated
4
mobile/openapi/README.md
generated
@ -145,8 +145,8 @@ Class | Method | HTTP request | Description
|
|||||||
*MemoriesApi* | [**removeMemoryAssets**](doc//MemoriesApi.md#removememoryassets) | **DELETE** /memories/{id}/assets |
|
*MemoriesApi* | [**removeMemoryAssets**](doc//MemoriesApi.md#removememoryassets) | **DELETE** /memories/{id}/assets |
|
||||||
*MemoriesApi* | [**searchMemories**](doc//MemoriesApi.md#searchmemories) | **GET** /memories |
|
*MemoriesApi* | [**searchMemories**](doc//MemoriesApi.md#searchmemories) | **GET** /memories |
|
||||||
*MemoriesApi* | [**updateMemory**](doc//MemoriesApi.md#updatememory) | **PUT** /memories/{id} |
|
*MemoriesApi* | [**updateMemory**](doc//MemoriesApi.md#updatememory) | **PUT** /memories/{id} |
|
||||||
*NotificationsApi* | [**getNotificationTemplate**](doc//NotificationsApi.md#getnotificationtemplate) | **POST** /notifications/templates/{name} |
|
*NotificationsAdminApi* | [**getNotificationTemplateAdmin**](doc//NotificationsAdminApi.md#getnotificationtemplateadmin) | **POST** /notifications/admin/templates/{name} |
|
||||||
*NotificationsApi* | [**sendTestEmail**](doc//NotificationsApi.md#sendtestemail) | **POST** /notifications/test-email |
|
*NotificationsAdminApi* | [**sendTestEmailAdmin**](doc//NotificationsAdminApi.md#sendtestemailadmin) | **POST** /notifications/admin/test-email |
|
||||||
*OAuthApi* | [**finishOAuth**](doc//OAuthApi.md#finishoauth) | **POST** /oauth/callback |
|
*OAuthApi* | [**finishOAuth**](doc//OAuthApi.md#finishoauth) | **POST** /oauth/callback |
|
||||||
*OAuthApi* | [**linkOAuthAccount**](doc//OAuthApi.md#linkoauthaccount) | **POST** /oauth/link |
|
*OAuthApi* | [**linkOAuthAccount**](doc//OAuthApi.md#linkoauthaccount) | **POST** /oauth/link |
|
||||||
*OAuthApi* | [**redirectOAuthToMobile**](doc//OAuthApi.md#redirectoauthtomobile) | **GET** /oauth/mobile-redirect |
|
*OAuthApi* | [**redirectOAuthToMobile**](doc//OAuthApi.md#redirectoauthtomobile) | **GET** /oauth/mobile-redirect |
|
||||||
|
2
mobile/openapi/lib/api.dart
generated
2
mobile/openapi/lib/api.dart
generated
@ -44,7 +44,7 @@ part 'api/jobs_api.dart';
|
|||||||
part 'api/libraries_api.dart';
|
part 'api/libraries_api.dart';
|
||||||
part 'api/map_api.dart';
|
part 'api/map_api.dart';
|
||||||
part 'api/memories_api.dart';
|
part 'api/memories_api.dart';
|
||||||
part 'api/notifications_api.dart';
|
part 'api/notifications_admin_api.dart';
|
||||||
part 'api/o_auth_api.dart';
|
part 'api/o_auth_api.dart';
|
||||||
part 'api/partners_api.dart';
|
part 'api/partners_api.dart';
|
||||||
part 'api/people_api.dart';
|
part 'api/people_api.dart';
|
||||||
|
@ -11,20 +11,20 @@
|
|||||||
part of openapi.api;
|
part of openapi.api;
|
||||||
|
|
||||||
|
|
||||||
class NotificationsApi {
|
class NotificationsAdminApi {
|
||||||
NotificationsApi([ApiClient? apiClient]) : apiClient = apiClient ?? defaultApiClient;
|
NotificationsAdminApi([ApiClient? apiClient]) : apiClient = apiClient ?? defaultApiClient;
|
||||||
|
|
||||||
final ApiClient apiClient;
|
final ApiClient apiClient;
|
||||||
|
|
||||||
/// Performs an HTTP 'POST /notifications/templates/{name}' operation and returns the [Response].
|
/// Performs an HTTP 'POST /notifications/admin/templates/{name}' operation and returns the [Response].
|
||||||
/// Parameters:
|
/// Parameters:
|
||||||
///
|
///
|
||||||
/// * [String] name (required):
|
/// * [String] name (required):
|
||||||
///
|
///
|
||||||
/// * [TemplateDto] templateDto (required):
|
/// * [TemplateDto] templateDto (required):
|
||||||
Future<Response> getNotificationTemplateWithHttpInfo(String name, TemplateDto templateDto,) async {
|
Future<Response> getNotificationTemplateAdminWithHttpInfo(String name, TemplateDto templateDto,) async {
|
||||||
// ignore: prefer_const_declarations
|
// ignore: prefer_const_declarations
|
||||||
final apiPath = r'/notifications/templates/{name}'
|
final apiPath = r'/notifications/admin/templates/{name}'
|
||||||
.replaceAll('{name}', name);
|
.replaceAll('{name}', name);
|
||||||
|
|
||||||
// ignore: prefer_final_locals
|
// ignore: prefer_final_locals
|
||||||
@ -53,8 +53,8 @@ class NotificationsApi {
|
|||||||
/// * [String] name (required):
|
/// * [String] name (required):
|
||||||
///
|
///
|
||||||
/// * [TemplateDto] templateDto (required):
|
/// * [TemplateDto] templateDto (required):
|
||||||
Future<TemplateResponseDto?> getNotificationTemplate(String name, TemplateDto templateDto,) async {
|
Future<TemplateResponseDto?> getNotificationTemplateAdmin(String name, TemplateDto templateDto,) async {
|
||||||
final response = await getNotificationTemplateWithHttpInfo(name, templateDto,);
|
final response = await getNotificationTemplateAdminWithHttpInfo(name, templateDto,);
|
||||||
if (response.statusCode >= HttpStatus.badRequest) {
|
if (response.statusCode >= HttpStatus.badRequest) {
|
||||||
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
||||||
}
|
}
|
||||||
@ -68,13 +68,13 @@ class NotificationsApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs an HTTP 'POST /notifications/test-email' operation and returns the [Response].
|
/// Performs an HTTP 'POST /notifications/admin/test-email' operation and returns the [Response].
|
||||||
/// Parameters:
|
/// Parameters:
|
||||||
///
|
///
|
||||||
/// * [SystemConfigSmtpDto] systemConfigSmtpDto (required):
|
/// * [SystemConfigSmtpDto] systemConfigSmtpDto (required):
|
||||||
Future<Response> sendTestEmailWithHttpInfo(SystemConfigSmtpDto systemConfigSmtpDto,) async {
|
Future<Response> sendTestEmailAdminWithHttpInfo(SystemConfigSmtpDto systemConfigSmtpDto,) async {
|
||||||
// ignore: prefer_const_declarations
|
// ignore: prefer_const_declarations
|
||||||
final apiPath = r'/notifications/test-email';
|
final apiPath = r'/notifications/admin/test-email';
|
||||||
|
|
||||||
// ignore: prefer_final_locals
|
// ignore: prefer_final_locals
|
||||||
Object? postBody = systemConfigSmtpDto;
|
Object? postBody = systemConfigSmtpDto;
|
||||||
@ -100,8 +100,8 @@ class NotificationsApi {
|
|||||||
/// Parameters:
|
/// Parameters:
|
||||||
///
|
///
|
||||||
/// * [SystemConfigSmtpDto] systemConfigSmtpDto (required):
|
/// * [SystemConfigSmtpDto] systemConfigSmtpDto (required):
|
||||||
Future<TestEmailResponseDto?> sendTestEmail(SystemConfigSmtpDto systemConfigSmtpDto,) async {
|
Future<TestEmailResponseDto?> sendTestEmailAdmin(SystemConfigSmtpDto systemConfigSmtpDto,) async {
|
||||||
final response = await sendTestEmailWithHttpInfo(systemConfigSmtpDto,);
|
final response = await sendTestEmailAdminWithHttpInfo(systemConfigSmtpDto,);
|
||||||
if (response.statusCode >= HttpStatus.badRequest) {
|
if (response.statusCode >= HttpStatus.badRequest) {
|
||||||
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
||||||
}
|
}
|
@ -3485,9 +3485,9 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/notifications/templates/{name}": {
|
"/notifications/admin/templates/{name}": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "getNotificationTemplate",
|
"operationId": "getNotificationTemplateAdmin",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "name",
|
"name": "name",
|
||||||
@ -3532,13 +3532,13 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Notifications"
|
"Notifications (Admin)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/notifications/test-email": {
|
"/notifications/admin/test-email": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "sendTestEmail",
|
"operationId": "sendTestEmailAdmin",
|
||||||
"parameters": [],
|
"parameters": [],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
@ -3574,7 +3574,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Notifications"
|
"Notifications (Admin)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -2318,26 +2318,26 @@ export function addMemoryAssets({ id, bulkIdsDto }: {
|
|||||||
body: bulkIdsDto
|
body: bulkIdsDto
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
export function getNotificationTemplate({ name, templateDto }: {
|
export function getNotificationTemplateAdmin({ name, templateDto }: {
|
||||||
name: string;
|
name: string;
|
||||||
templateDto: TemplateDto;
|
templateDto: TemplateDto;
|
||||||
}, opts?: Oazapfts.RequestOpts) {
|
}, opts?: Oazapfts.RequestOpts) {
|
||||||
return oazapfts.ok(oazapfts.fetchJson<{
|
return oazapfts.ok(oazapfts.fetchJson<{
|
||||||
status: 200;
|
status: 200;
|
||||||
data: TemplateResponseDto;
|
data: TemplateResponseDto;
|
||||||
}>(`/notifications/templates/${encodeURIComponent(name)}`, oazapfts.json({
|
}>(`/notifications/admin/templates/${encodeURIComponent(name)}`, oazapfts.json({
|
||||||
...opts,
|
...opts,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: templateDto
|
body: templateDto
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
export function sendTestEmail({ systemConfigSmtpDto }: {
|
export function sendTestEmailAdmin({ systemConfigSmtpDto }: {
|
||||||
systemConfigSmtpDto: SystemConfigSmtpDto;
|
systemConfigSmtpDto: SystemConfigSmtpDto;
|
||||||
}, opts?: Oazapfts.RequestOpts) {
|
}, opts?: Oazapfts.RequestOpts) {
|
||||||
return oazapfts.ok(oazapfts.fetchJson<{
|
return oazapfts.ok(oazapfts.fetchJson<{
|
||||||
status: 200;
|
status: 200;
|
||||||
data: TestEmailResponseDto;
|
data: TestEmailResponseDto;
|
||||||
}>("/notifications/test-email", oazapfts.json({
|
}>("/notifications/admin/test-email", oazapfts.json({
|
||||||
...opts,
|
...opts,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: systemConfigSmtpDto
|
body: systemConfigSmtpDto
|
||||||
|
@ -13,7 +13,7 @@ import { JobController } from 'src/controllers/job.controller';
|
|||||||
import { LibraryController } from 'src/controllers/library.controller';
|
import { LibraryController } from 'src/controllers/library.controller';
|
||||||
import { MapController } from 'src/controllers/map.controller';
|
import { MapController } from 'src/controllers/map.controller';
|
||||||
import { MemoryController } from 'src/controllers/memory.controller';
|
import { MemoryController } from 'src/controllers/memory.controller';
|
||||||
import { NotificationController } from 'src/controllers/notification.controller';
|
import { NotificationAdminController } from 'src/controllers/notification-admin.controller';
|
||||||
import { OAuthController } from 'src/controllers/oauth.controller';
|
import { OAuthController } from 'src/controllers/oauth.controller';
|
||||||
import { PartnerController } from 'src/controllers/partner.controller';
|
import { PartnerController } from 'src/controllers/partner.controller';
|
||||||
import { PersonController } from 'src/controllers/person.controller';
|
import { PersonController } from 'src/controllers/person.controller';
|
||||||
@ -47,7 +47,7 @@ export const controllers = [
|
|||||||
LibraryController,
|
LibraryController,
|
||||||
MapController,
|
MapController,
|
||||||
MemoryController,
|
MemoryController,
|
||||||
NotificationController,
|
NotificationAdminController,
|
||||||
OAuthController,
|
OAuthController,
|
||||||
PartnerController,
|
PartnerController,
|
||||||
PersonController,
|
PersonController,
|
||||||
|
@ -7,22 +7,22 @@ import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
|||||||
import { EmailTemplate } from 'src/repositories/notification.repository';
|
import { EmailTemplate } from 'src/repositories/notification.repository';
|
||||||
import { NotificationService } from 'src/services/notification.service';
|
import { NotificationService } from 'src/services/notification.service';
|
||||||
|
|
||||||
@ApiTags('Notifications')
|
@ApiTags('Notifications (Admin)')
|
||||||
@Controller('notifications')
|
@Controller('notifications/admin')
|
||||||
export class NotificationController {
|
export class NotificationAdminController {
|
||||||
constructor(private service: NotificationService) {}
|
constructor(private service: NotificationService) {}
|
||||||
|
|
||||||
@Post('test-email')
|
@Post('test-email')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@Authenticated({ admin: true })
|
@Authenticated({ admin: true })
|
||||||
sendTestEmail(@Auth() auth: AuthDto, @Body() dto: SystemConfigSmtpDto): Promise<TestEmailResponseDto> {
|
sendTestEmailAdmin(@Auth() auth: AuthDto, @Body() dto: SystemConfigSmtpDto): Promise<TestEmailResponseDto> {
|
||||||
return this.service.sendTestEmail(auth.user.id, dto);
|
return this.service.sendTestEmail(auth.user.id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('templates/:name')
|
@Post('templates/:name')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@Authenticated({ admin: true })
|
@Authenticated({ admin: true })
|
||||||
getNotificationTemplate(
|
getNotificationTemplateAdmin(
|
||||||
@Auth() auth: AuthDto,
|
@Auth() auth: AuthDto,
|
||||||
@Param('name') name: EmailTemplate,
|
@Param('name') name: EmailTemplate,
|
||||||
@Body() dto: TemplateDto,
|
@Body() dto: TemplateDto,
|
@ -12,7 +12,7 @@
|
|||||||
import { SettingInputFieldType } from '$lib/constants';
|
import { SettingInputFieldType } from '$lib/constants';
|
||||||
import { user } from '$lib/stores/user.store';
|
import { user } from '$lib/stores/user.store';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { sendTestEmail, type SystemConfigDto } from '@immich/sdk';
|
import { sendTestEmailAdmin, type SystemConfigDto } from '@immich/sdk';
|
||||||
import { Button } from '@immich/ui';
|
import { Button } from '@immich/ui';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
@ -40,7 +40,7 @@
|
|||||||
isSending = true;
|
isSending = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await sendTestEmail({
|
await sendTestEmailAdmin({
|
||||||
systemConfigSmtpDto: {
|
systemConfigSmtpDto: {
|
||||||
enabled: config.notifications.smtp.enabled,
|
enabled: config.notifications.smtp.enabled,
|
||||||
transport: {
|
transport: {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import SettingAccordion from '$lib/components/shared-components/settings/setting-accordion.svelte';
|
import SettingAccordion from '$lib/components/shared-components/settings/setting-accordion.svelte';
|
||||||
import SettingTextarea from '$lib/components/shared-components/settings/setting-textarea.svelte';
|
import SettingTextarea from '$lib/components/shared-components/settings/setting-textarea.svelte';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { type SystemConfigDto, type SystemConfigTemplateEmailsDto, getNotificationTemplate } from '@immich/sdk';
|
import { type SystemConfigDto, type SystemConfigTemplateEmailsDto, getNotificationTemplateAdmin } from '@immich/sdk';
|
||||||
import { Button } from '@immich/ui';
|
import { Button } from '@immich/ui';
|
||||||
import { mdiEyeOutline } from '@mdi/js';
|
import { mdiEyeOutline } from '@mdi/js';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
@ -25,7 +25,7 @@
|
|||||||
const getTemplate = async (name: string, template: string) => {
|
const getTemplate = async (name: string, template: string) => {
|
||||||
try {
|
try {
|
||||||
loadingPreview = true;
|
loadingPreview = true;
|
||||||
const result = await getNotificationTemplate({ name, templateDto: { template } });
|
const result = await getNotificationTemplateAdmin({ name, templateDto: { template } });
|
||||||
htmlPreview = result.html;
|
htmlPreview = result.html;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, 'Could not load template.');
|
handleError(error, 'Could not load template.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user