Merge branch 'develop'

This commit is contained in:
Alice Gaudon 2020-07-30 11:34:59 +02:00
commit 15b733f900
10 changed files with 187 additions and 74 deletions

View File

@ -1,7 +1,26 @@
@import "layout"; @import "layout";
td.actions { td.actions {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
> *:not(:first-child) {
margin-left: 8px;
}
form { form {
padding: 0; padding: 0;
display: inline;
}
button, .button {
margin: 0;
padding: 8px;
.feather {
margin-right: 0;
}
} }
} }

View File

@ -21,6 +21,46 @@ body {
background-color: $backgroundColor; background-color: $backgroundColor;
} }
@mixin tip {
position: relative;
.tip {
visibility: hidden;
position: absolute;
z-index: 10000;
pointer-events: none;
display: block;
width: max-content;
height: 30px;
padding: 4px 8px;
line-height: 22px;
top: calc(100% + 8px);
left: 50%;
transform: translateX(-50%);
text-align: center;
font-size: 18px;
color: $defaultTextColor;
opacity: 0;
transition: opacity ease-out 100ms, visibility step-end 150ms;
transition-delay: 0ms;
background-color: #000;
border-radius: 5px;
text-transform: initial;
font-weight: initial;
}
&:hover, &:active {
.tip {
visibility: visible;
opacity: 1;
transition: opacity ease-out 100ms;
transition-delay: 150ms;
}
}
}
header { header {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -77,27 +117,11 @@ header {
&:not(button) { &:not(button) {
background-color: rgba(255, 255, 255, 0.07); background-color: rgba(255, 255, 255, 0.07);
} }
.tip {
visibility: visible;
opacity: 1;
transition: opacity ease-out 100ms;
transition-delay: 150ms;
}
} }
.feather { .feather {
--icon-size: 24px; --icon-size: 24px;
} }
&:hover {
.tip {
visibility: visible;
opacity: 1;
transition: opacity ease-out 100ms;
transition-delay: 150ms;
}
}
} }
button { button {
@ -108,11 +132,6 @@ header {
.feather { .feather {
margin-right: 0; margin-right: 0;
} }
.tip {
text-transform: initial;
font-weight: initial;
}
} }
form { form {
@ -188,32 +207,12 @@ header {
@media (min-width: $menuLayoutSwitchTreshold) { @media (min-width: $menuLayoutSwitchTreshold) {
nav ul li { nav ul li {
a, button { a, button, .button {
.tip { @include tip;
visibility: hidden;
position: absolute;
display: block;
width: max-content;
height: 30px;
padding: 4px 8px;
line-height: 22px;
top: calc(100% + 8px);
left: 50%;
transform: translateX(-50%);
text-align: center;
font-size: 18px;
color: $defaultTextColor;
opacity: 0;
transition: opacity ease-out 100ms, visibility step-end 150ms;
transition-delay: 0ms;
background-color: #000;
border-radius: 5px;
}
} }
&:last-child { &:last-child {
a, button { a, button, .button {
.tip { .tip {
left: unset; left: unset;
right: 4px; right: 4px;
@ -235,6 +234,10 @@ footer {
main { main {
flex: 1; flex: 1;
padding: 8px; padding: 8px;
button, .button {
@include tip;
}
} }
h1 { h1 {
@ -373,7 +376,7 @@ form {
position: absolute; position: absolute;
pointer-events: none; pointer-events: none;
right: 8px; right: 8px;
bottom: 8px; top: 30px;
transition: transform 150ms ease-out; transition: transform 150ms ease-out;
} }
@ -565,6 +568,19 @@ button, .button {
} }
} }
.breadcrumb {
list-style: none;
display: flex;
flex-direction: row;
margin: 0;
padding: 8px;
> *:not(:first-child)::before {
content: '';
padding: 0 8px;
}
}
// --- // ---
// --- Layout helpers // --- Layout helpers
// --- // ---

View File

@ -1,6 +1,6 @@
{ {
"name": "aldap", "name": "aldap",
"version": "1.0.1", "version": "1.1.0",
"description": "Authentication LDAP server", "description": "Authentication LDAP server",
"repository": "git@gitlab.com:ArisuOngaku/aldap.git", "repository": "git@gitlab.com:ArisuOngaku/aldap.git",
"author": "Alice Gaudon <alice@gaudon.pro>", "author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -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.updateWithData(req.body);
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)

View File

@ -28,7 +28,10 @@ export default class MailDomain extends Model {
} }
protected init(): void { protected init(): void {
this.setValidation('name').defined().maxLength(252).regexp(/^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/) this.setValidation('name').acceptUndefined()
.maxLength(252)
.regexp(/^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/)
.unique(this);
this.setValidation('user_id').acceptUndefined().exists(User, 'id'); this.setValidation('user_id').acceptUndefined().exists(User, 'id');
} }

View File

@ -44,7 +44,7 @@
<button class="warning" <button class="warning"
onclick="return confirm('Are you sure you want to set {{ email.email }} as your main address?');"> onclick="return confirm('Are you sure you want to set {{ email.email }} as your main address?');">
<i data-feather="refresh-ccw"></i> Set as main address <i data-feather="refresh-ccw"></i> <span class="tip">Set as main address</span>
</button> </button>
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}
</form> </form>
@ -54,7 +54,7 @@
<button class="danger" <button class="danger"
onclick="return confirm('Are you sure you want to delete {{ email.email }}?');"> onclick="return confirm('Are you sure you want to delete {{ email.email }}?');">
<i data-feather="trash"></i> Remove <i data-feather="trash"></i> <span class="tip">Remove</span>
</button> </button>
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}
</form> </form>
@ -101,7 +101,7 @@
<button class="danger" <button class="danger"
onclick="return confirm('Are you sure you want to delete {{ identity.email }}?')"> onclick="return confirm('Are you sure you want to delete {{ identity.email }}?')">
<i data-feather="trash"></i> Delete <i data-feather="trash"></i> <span class="tip">Delete</span>
</button> </button>
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}

View 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')}
]) }}
<div class="panel">
<i data-feather="globe"></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>
</div>
</div>
{% endblock %}

View File

@ -4,11 +4,14 @@
{% block body %} {% block body %}
<div class="container"> <div class="container">
<main class="panel"> {{ macros.breadcrumb(mailbox.name, [
<i data-feather="mail"></i> {title: 'Backend', link: route('backend')},
<h1>Mailbox</h1> {title: 'Mailboxes', link: route('backend-mailboxes')}
]) }}
<p class="center">{{ mailbox.name }}</p> <div class="panel">
<i data-feather="mail"></i>
<h1>Mailbox: {{ mailbox.name }}</h1>
<table class="data-table"> <table class="data-table">
<thead> <thead>
@ -28,8 +31,9 @@
<form action="{{ route('backend-delete-mail-identity') }}" method="POST"> <form action="{{ route('backend-delete-mail-identity') }}" method="POST">
<input type="hidden" name="id" value="{{ identity.id }}"> <input type="hidden" name="id" value="{{ identity.id }}">
<button class="danger" onclick="return confirm('Are you sure you want to delete {{ identity.email }}?')"> <button class="danger"
<i data-feather="trash"></i> Delete onclick="return confirm('Are you sure you want to delete {{ identity.email }}?')">
<i data-feather="trash"></i> <span class="tip">Delete</span>
</button> </button>
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}
@ -53,6 +57,6 @@
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}
</form> </form>
</main> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -3,11 +3,15 @@
{% set title = app.name + ' - Backend' %} {% set title = app.name + ' - Backend' %}
{% block body %} {% block body %}
<h1>Mailbox manager</h1>
<div class="container"> <div class="container">
{{ macros.breadcrumb('Mailboxes', [
{title: 'Backend', link: route('backend')}
]) }}
<h1>Mailbox manager</h1>
<section class="panel"> <section class="panel">
<h2>Domains</h2> <h2><i data-feather="globe"></i> Domains</h2>
<form action="{{ route('backend-add-domain') }}" method="POST" class="sub-panel"> <form action="{{ route('backend-add-domain') }}" method="POST" class="sub-panel">
<h3>Add domain</h3> <h3>Add domain</h3>
@ -39,11 +43,16 @@
<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 }}">
<button class="danger" onclick="return confirm('Are you sure you want to delete {{ domain.name }}?')"> <button class="danger"
<i data-feather="trash"></i> Remove onclick="return confirm('Are you sure you want to delete {{ domain.name }}?')">
<i data-feather="trash"></i> <span class="tip">Remove</span>
</button> </button>
{{ macros.csrf(getCSRFToken) }} {{ macros.csrf(getCSRFToken) }}
@ -56,7 +65,7 @@
</section> </section>
<section class="panel"> <section class="panel">
<h2>Mailboxes</h2> <h2><i data-feather="mail"></i> Mailboxes</h2>
<table class="data-table"> <table class="data-table">
<thead> <thead>
@ -66,6 +75,7 @@
<th>Name</th> <th>Name</th>
<th>Identities</th> <th>Identities</th>
<th>Owned domains</th> <th>Owned domains</th>
<th>Actions</th>
</tr> </tr>
</thead> </thead>
@ -74,9 +84,14 @@
<tr> <tr>
<td>{{ box.id }}</td> <td>{{ box.id }}</td>
<td>{{ box.username }}</td> <td>{{ box.username }}</td>
<td><a href="{{ route('backend-mailbox', box.id) }}">{{ box.name }}</a></td> <td>{{ box.name }}</td>
<td>{{ box.identity_count }}</td> <td>{{ box.identity_count }}</td>
<td>{{ box.domain_count }}</td> <td>{{ box.domain_count }}</td>
<td class="actions">
<a href="{{ route('backend-mailbox', box.id) }}" class="button">
<i data-feather="edit-2"></i> <span class="tip">Edit</span>
</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -1539,7 +1539,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1:
resolved "https://registry.toot.party/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" resolved "https://registry.toot.party/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d"
integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==
ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.5.5: ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.3:
version "6.12.3" version "6.12.3"
resolved "https://registry.toot.party/ajv/-/ajv-6.12.3.tgz#18c5af38a111ddeb4f2697bd78d68abc1cabd706" resolved "https://registry.toot.party/ajv/-/ajv-6.12.3.tgz#18c5af38a111ddeb4f2697bd78d68abc1cabd706"
integrity sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA== integrity sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==
@ -4448,11 +4448,11 @@ har-schema@^2.0.0:
integrity sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= integrity sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=
har-validator@~5.1.3: har-validator@~5.1.3:
version "5.1.3" version "5.1.5"
resolved "https://registry.toot.party/har-validator/-/har-validator-5.1.3.tgz#1ef89ebd3e4996557675eed9893110dc350fa080" resolved "https://registry.toot.party/har-validator/-/har-validator-5.1.5.tgz#1f0803b9f8cb20c0fa13822df1ecddb36bde1efd"
integrity sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== integrity sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==
dependencies: dependencies:
ajv "^6.5.5" ajv "^6.12.3"
har-schema "^2.0.0" har-schema "^2.0.0"
has-ansi@^2.0.0: has-ansi@^2.0.0:
@ -9886,9 +9886,9 @@ widest-line@^3.1.0:
string-width "^4.0.0" string-width "^4.0.0"
wms-core@^0: wms-core@^0:
version "0.20.1" version "0.20.2"
resolved "https://registry.toot.party/wms-core/-/wms-core-0.20.1.tgz#c63a1b6b5cd4669e97fa0b651cd5fa6496f6305c" resolved "https://registry.toot.party/wms-core/-/wms-core-0.20.2.tgz#b4d3d71a30b4d8bcbb2c422b3b89027ef5bb4b0e"
integrity sha512-JZkrLgxoPBSOf8P5KB9Fc5IoEoWyw6qMoSukpCIi14iue/rm/rW5M9D0Y3dy6tio3w7ZRsrcQdYbIkXW228lzQ== integrity sha512-MlK9J5VolObOFi+lJW8PFX4IrCi/vUvhC1FGzHCkzdeU5ODagaj7T1HV/7cOaJtzH/pHB+XD1U+oveajkVZSxA==
dependencies: dependencies:
argon2 "^0.26.2" argon2 "^0.26.2"
compression "^1.7.4" compression "^1.7.4"