- mail_settings_controller for setting smtp settings - added view ror rjecting dataset for editor - added new model AppConfig for stroing appwide config values - better validate_chesum.ts command with process chunking - added vue3 apps 'BasicSettings' like email, profile settings - started with 2 multilingual capabilities - npm updates
This commit is contained in:
parent
010bead723
commit
b06ccae603
67 changed files with 7820 additions and 1463 deletions
103
app/Controllers/Http/Admin/mailsettings_controller.ts
Normal file
103
app/Controllers/Http/Admin/mailsettings_controller.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import vine from '@vinejs/vine';
|
||||
import AppConfig from '#models/appconfig';
|
||||
import mail from '@adonisjs/mail/services/main';
|
||||
// import config from '@adonisjs/core/services/config';
|
||||
// import { configProvider } from '@adonisjs/core';
|
||||
// import app from '@adonisjs/core/services/app';
|
||||
|
||||
export default class MailSettingsController {
|
||||
/**
|
||||
* Save the email server settings
|
||||
*/
|
||||
public async setMailSettings({ request, response }: HttpContext) {
|
||||
const settingsSchema = vine.compile(
|
||||
vine.object({
|
||||
mail_domain: vine.string(),
|
||||
mail_from_address: vine.string(),
|
||||
mail_smtp_mode: vine.string(),
|
||||
mail_smtpsecure: vine.string().optional(),
|
||||
mail_smtphost: vine.string(),
|
||||
mail_smtpport: vine.string(),
|
||||
mail_smtpauth: vine.boolean(),
|
||||
// mail_sendmailmode: vine.string().optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
const validatedData = await request.validateUsing(settingsSchema);
|
||||
|
||||
const configData: any = { ...validatedData };
|
||||
|
||||
if (!validatedData.mail_smtpauth) {
|
||||
configData.mail_smtpname = null;
|
||||
configData.mail_smtppassword = null;
|
||||
}
|
||||
|
||||
// Prepare the settings to be saved
|
||||
const settingsToSave = [
|
||||
{ appid: 'settings', configkey: 'default', configvalue: validatedData.mail_smtp_mode, type: 1, lazy: 0 },
|
||||
{ appid: 'settings', configkey: 'host', configvalue: validatedData.mail_smtphost, type: 1, lazy: 0 },
|
||||
{ appid: 'settings', configkey: 'port', configvalue: validatedData.mail_smtpport, type: 1, lazy: 0 },
|
||||
{
|
||||
appid: 'settings',
|
||||
configkey: 'from.address',
|
||||
configvalue: `${validatedData.mail_from_address}@${validatedData.mail_domain}`,
|
||||
type: 1,
|
||||
lazy: 0,
|
||||
},
|
||||
];
|
||||
|
||||
// if (validatedData.mail_smtpauth) {
|
||||
// settingsToSave.push(
|
||||
// { appid: 'settings', configkey: 'smtp_user', configvalue: validatedData.mail_smtpname, type: 1, lazy: 0 },
|
||||
// { appid: 'settings', configkey: 'smtp_password', configvalue: validatedData.mail_smtppassword, type: 1, lazy: 0 },
|
||||
// );
|
||||
// } else {
|
||||
// settingsToSave.push(
|
||||
// { appid: 'settings', configkey: 'smtp_user', configvalue: null, type: 1, lazy: 0 },
|
||||
// { appid: 'settings', configkey: 'smtp_password', configvalue: null, type: 1, lazy: 0 },
|
||||
// );
|
||||
// }
|
||||
|
||||
// Save or update the settings in the database
|
||||
for (const setting of settingsToSave) {
|
||||
await AppConfig.updateOrCreate(
|
||||
{ appid: setting.appid, configkey: setting.configkey },
|
||||
{ configvalue: setting.configvalue, type: setting.type, lazy: setting.lazy },
|
||||
);
|
||||
}
|
||||
|
||||
return response.json({ success: true, message: 'Mail settings updated successfully' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a test email to ensure settings work
|
||||
*/
|
||||
public async sendTestMail({ response, auth }: HttpContext) {
|
||||
const user = auth.user!;
|
||||
const userEmail = user.email;
|
||||
|
||||
// let mailManager = await app.container.make('mail.manager');
|
||||
// let iwas = mailManager.use();
|
||||
// let test = mail.config.mailers.smtp();
|
||||
if (!userEmail) {
|
||||
return response.badRequest({ message: 'User email is not set. Please update your profile.' });
|
||||
}
|
||||
|
||||
try {
|
||||
await mail.send((message) => {
|
||||
message
|
||||
// .from(Config.get('mail.from.address'))
|
||||
.from('tethys@geosphere.at')
|
||||
.to(userEmail)
|
||||
.subject('Test Email')
|
||||
.html('<p>If you received this email, the email configuration seems to be correct.</p>');
|
||||
});
|
||||
|
||||
return response.json({ success: true, message: 'Test email sent successfully' });
|
||||
// return response.flash('Test email sent successfully!', 'message').redirect().back();
|
||||
} catch (error) {
|
||||
return response.internalServerError({ message: `Error sending test email: ${error.message}` });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,6 +85,7 @@ export default class DatasetsController {
|
|||
can: {
|
||||
receive: await auth.user?.can(['dataset-receive']),
|
||||
approve: await auth.user?.can(['dataset-approve']),
|
||||
reject: await auth.user?.can(['dataset-editor-reject']),
|
||||
edit: await auth.user?.can(['dataset-editor-update']),
|
||||
delete: await auth.user?.can(['dataset-editor-delete']),
|
||||
publish: await auth.user?.can(['dataset-publish']),
|
||||
|
@ -223,6 +224,92 @@ export default class DatasetsController {
|
|||
}
|
||||
}
|
||||
|
||||
public async reject({ request, inertia, response }: HttpContext) {
|
||||
const id = request.param('id');
|
||||
const dataset = await Dataset.query()
|
||||
.where('id', id)
|
||||
// .preload('titles')
|
||||
// .preload('descriptions')
|
||||
.preload('user', (builder) => {
|
||||
builder.select('id', 'login');
|
||||
})
|
||||
.firstOrFail();
|
||||
|
||||
const validStates = ['editor_accepted', 'rejected_reviewer'];
|
||||
if (!validStates.includes(dataset.server_state)) {
|
||||
// session.flash('errors', 'Invalid server state!');
|
||||
return response
|
||||
.flash(
|
||||
'warning',
|
||||
`Invalid server state. Dataset with id ${id} cannot be rejected. Datset has server state ${dataset.server_state}.`,
|
||||
)
|
||||
.redirect()
|
||||
.toRoute('editor.dataset.list');
|
||||
}
|
||||
|
||||
return inertia.render('Editor/Dataset/Reject', {
|
||||
dataset,
|
||||
});
|
||||
}
|
||||
|
||||
public async rejectUpdate({ request, response }: HttpContext) {
|
||||
const id = request.param('id');
|
||||
const dataset = await Dataset.query()
|
||||
.where('id', id)
|
||||
.preload('user', (builder) => {
|
||||
builder.select('id', 'login');
|
||||
})
|
||||
.firstOrFail();
|
||||
|
||||
// const newSchema = schema.create({
|
||||
// server_state: schema.string({ trim: true }),
|
||||
// reject_reviewer_note: schema.string({ trim: true }, [rules.minLength(10), rules.maxLength(500)]),
|
||||
// });
|
||||
const newSchema = vine.object({
|
||||
server_state: vine.string().trim(),
|
||||
reject_editor_note: vine.string().trim().minLength(10).maxLength(500),
|
||||
});
|
||||
|
||||
try {
|
||||
// await request.validate({ schema: newSchema });
|
||||
const validator = vine.compile(newSchema);
|
||||
await request.validateUsing(validator);
|
||||
} catch (error) {
|
||||
// return response.badRequest(error.messages);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const validStates = ['editor_accepted', 'rejected_reviewer'];
|
||||
if (!validStates.includes(dataset.server_state)) {
|
||||
// throw new Error('Invalid server state!');
|
||||
// return response.flash('warning', 'Invalid server state. Dataset cannot be released to editor').redirect().back();
|
||||
return response
|
||||
.flash(
|
||||
'warning',
|
||||
`Invalid server state. Dataset with id ${id} cannot be rejected. Datset has server state ${dataset.server_state}.`,
|
||||
)
|
||||
.redirect()
|
||||
.toRoute('reviewer.dataset.list');
|
||||
}
|
||||
|
||||
// dataset.server_state = 'reviewed';
|
||||
dataset.server_state = 'rejected_editor';
|
||||
const rejectEditorNote = request.input('reject_editor_note', '');
|
||||
dataset.reject_editor_note = rejectEditorNote;
|
||||
|
||||
try {
|
||||
// await dataset.related('editor').associate(user); // speichert schon ab
|
||||
await dataset.save();
|
||||
return response
|
||||
.toRoute('editor.dataset.list')
|
||||
.flash('message', `You have rejected dataset ${dataset.id}! to submitter ${dataset.user.login}`);
|
||||
} catch (error) {
|
||||
// Handle any errors
|
||||
console.error(error);
|
||||
return response.status(500).json({ error: 'An error occurred while reviewing the data.' });
|
||||
}
|
||||
}
|
||||
|
||||
public async publish({ request, inertia, response }: HttpContext) {
|
||||
const id = request.param('id');
|
||||
|
||||
|
@ -254,7 +341,7 @@ export default class DatasetsController {
|
|||
|
||||
public async publishUpdate({ request, response }: HttpContext) {
|
||||
const publishDatasetSchema = vine.object({
|
||||
publisher_name: vine.string().alphaNumeric().trim(),
|
||||
publisher_name: vine.string().trim(),
|
||||
});
|
||||
try {
|
||||
// await request.validate({ schema: publishDatasetSchema, messages: this.messages });
|
||||
|
|
|
@ -96,11 +96,11 @@ export default class DatasetController {
|
|||
|
||||
// builder.where('type', 'Main');
|
||||
// })
|
||||
.paginate(page, 10);
|
||||
.paginate(page, 5);
|
||||
|
||||
return inertia.render('Submitter/Dataset/Index', {
|
||||
// testing: 'this is a test',
|
||||
datasets: myDatasets.serialize(),
|
||||
datasets: myDatasets.toJSON(),
|
||||
filters: request.all(),
|
||||
can: {
|
||||
// create: await auth.user?.can(['dataset-submit']),
|
||||
|
|
33
app/models/appconfig.ts
Normal file
33
app/models/appconfig.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import BaseModel from './base_model.js';
|
||||
import { column } from '@adonisjs/lucid/orm';
|
||||
|
||||
export default class AppConfig extends BaseModel {
|
||||
public static table = 'appconfigs'; // Specify the table name if it differs from the model name
|
||||
|
||||
@column({ isPrimary: true })
|
||||
public id: number;
|
||||
|
||||
@column()
|
||||
public appid: string;
|
||||
|
||||
@column()
|
||||
public configkey: string;
|
||||
|
||||
@column()
|
||||
public configvalue: string | null;
|
||||
|
||||
@column()
|
||||
public type: number;
|
||||
|
||||
@column()
|
||||
public lazy: number;
|
||||
|
||||
// async function setConfig(key: string, value: string) {
|
||||
// await this.updateOrCreate({ key }, { value })
|
||||
// }
|
||||
|
||||
// async function getConfig(key: string) {
|
||||
// const config = await this.findBy('key', key)
|
||||
// return config ? config.value : null
|
||||
// }
|
||||
}
|
|
@ -38,7 +38,7 @@ export const updateUserValidator = vine.withMetaData<{ objId: number }>().compil
|
|||
.email()
|
||||
.normalizeEmail()
|
||||
.isUnique({ table: 'accounts', column: 'email', whereNot: (field) => field.meta.objId }),
|
||||
password: vine.string().confirmed().trim().minLength(3).maxLength(60),
|
||||
password: vine.string().confirmed().trim().minLength(3).maxLength(60).optional(),
|
||||
roles: vine.array(vine.number()).minLength(1), // define at least one role for the new user
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue