Backend/Mailboxes: add domain editing
This commit is contained in:
parent
fe722a1dee
commit
d4709b0499
|
@ -28,8 +28,10 @@ export default class MailboxBackendController extends Controller {
|
||||||
this.get('/', this.getMailboxesBackend, 'backend-mailboxes', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
this.get('/', this.getMailboxesBackend, 'backend-mailboxes', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
this.get('/:id', this.getMailboxBackend, 'backend-mailbox', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
this.get('/:id', this.getMailboxBackend, 'backend-mailbox', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
|
|
||||||
this.post('/add-domain', this.postAddDomain, 'backend-add-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE)
|
this.post('/add-domain', this.postAddDomain, 'backend-add-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
this.post('/remove-domain', this.postRemoveDomain, 'backend-remove-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE)
|
this.get('/edit-domain/:id', this.getEditDomain, 'backend-edit-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
|
this.post('/edit-domain/:id', this.postEditDomain, 'backend-edit-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
|
this.post('/remove-domain', this.postRemoveDomain, 'backend-remove-domain', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
|
|
||||||
this.post('/:id/create-mail-identity', this.postCreateMailIdentity, 'backend-create-mail-identity', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
this.post('/:id/create-mail-identity', this.postCreateMailIdentity, 'backend-create-mail-identity', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
this.post('/delete-mail-identity', this.postDeleteMailIdentity, 'backend-delete-mail-identity', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
this.post('/delete-mail-identity', this.postDeleteMailIdentity, 'backend-delete-mail-identity', REQUIRE_AUTH_MIDDLEWARE, REQUIRE_ADMIN_MIDDLEWARE);
|
||||||
|
@ -104,6 +106,35 @@ export default class MailboxBackendController extends Controller {
|
||||||
res.redirectBack();
|
res.redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async getEditDomain(req: Request, res: Response): Promise<void> {
|
||||||
|
const domain = await MailDomain.getById(req.params.id);
|
||||||
|
if (!domain) throw new NotFoundHttpError('Domain', req.url);
|
||||||
|
|
||||||
|
res.render('backend/mail_domain', {
|
||||||
|
domain: domain,
|
||||||
|
users: [{
|
||||||
|
value: 0,
|
||||||
|
display: 'Public',
|
||||||
|
}, ...(await User.select().get()).map(u => ({
|
||||||
|
value: u.id,
|
||||||
|
display: u.name,
|
||||||
|
}))],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async postEditDomain(req: Request, res: Response): Promise<void> {
|
||||||
|
const domain = await MailDomain.select()
|
||||||
|
.where('id', req.params.id)
|
||||||
|
.first();
|
||||||
|
if (!domain) throw new NotFoundHttpError('Domain', req.url);
|
||||||
|
|
||||||
|
domain.user_id = req.body.user_id;
|
||||||
|
await domain.save();
|
||||||
|
|
||||||
|
req.flash('success', `Domain ${domain.name} updated successfully.`);
|
||||||
|
res.redirectBack();
|
||||||
|
}
|
||||||
|
|
||||||
protected async postRemoveDomain(req: Request, res: Response): Promise<void> {
|
protected async postRemoveDomain(req: Request, res: Response): Promise<void> {
|
||||||
const domain = await MailDomain.select()
|
const domain = await MailDomain.select()
|
||||||
.where('id', req.body.id)
|
.where('id', req.body.id)
|
||||||
|
|
25
views/backend/mail_domain.njk
Normal file
25
views/backend/mail_domain.njk
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{% extends 'layouts/base.njk' %}
|
||||||
|
|
||||||
|
{% set title = app.name + ' - Backend' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="container">
|
||||||
|
{{ macros.breadcrumb('Mail domain: ' + domain.name, [
|
||||||
|
{title: 'Backend', link: route('backend')},
|
||||||
|
{title: 'Mailboxes', link: route('backend-mailboxes')}
|
||||||
|
]) }}
|
||||||
|
|
||||||
|
<main class="panel">
|
||||||
|
<i data-feather="mail"></i>
|
||||||
|
<h1>Mail domain: {{ domain.name }}</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('backend-edit-domain', domain.id) }}" method="POST">
|
||||||
|
{{ macros.field(_locals, 'select', 'user_id', domain.user_id, 'Owner', null, 'required', users) }}
|
||||||
|
|
||||||
|
<button><i data-feather="check"></i> Update</button>
|
||||||
|
|
||||||
|
{{ macros.csrf(getCSRFToken) }}
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -39,6 +39,10 @@
|
||||||
<td>{{ domain.owner_name | default('Public') }}</td>
|
<td>{{ domain.owner_name | default('Public') }}</td>
|
||||||
<td>{{ domain.identity_count }}</td>
|
<td>{{ domain.identity_count }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
|
<a href="{{ route('backend-edit-domain', domain.id) }}" class="button">
|
||||||
|
<i data-feather="edit-2"></i> <span class="tip">Edit</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<form action="{{ route('backend-remove-domain') }}" method="POST">
|
<form action="{{ route('backend-remove-domain') }}" method="POST">
|
||||||
<input type="hidden" name="id" value="{{ domain.id }}">
|
<input type="hidden" name="id" value="{{ domain.id }}">
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user