From ba3a7a3cafd19b99614fc046130b20ae84d52a44 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 09:49:22 +0200 Subject: [PATCH 01/12] Validate domain name uniqueness --- src/models/MailDomain.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/models/MailDomain.ts b/src/models/MailDomain.ts index b192224..d8f381c 100644 --- a/src/models/MailDomain.ts +++ b/src/models/MailDomain.ts @@ -28,7 +28,9 @@ export default class MailDomain extends Model { } 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').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])?)+$/) + .unique(this); this.setValidation('user_id').acceptUndefined().exists(User, 'id'); } From 5eb8fa1f1e4c72114d26a492e3d9747e0ddc9c52 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 10:54:14 +0200 Subject: [PATCH 02/12] Improve tips styling and allow it in any button --- assets/sass/layout.scss | 91 +++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/assets/sass/layout.scss b/assets/sass/layout.scss index ef19293..f033e94 100644 --- a/assets/sass/layout.scss +++ b/assets/sass/layout.scss @@ -21,6 +21,46 @@ body { 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 { display: flex; flex-direction: row; @@ -77,27 +117,11 @@ header { &:not(button) { background-color: rgba(255, 255, 255, 0.07); } - - .tip { - visibility: visible; - opacity: 1; - transition: opacity ease-out 100ms; - transition-delay: 150ms; - } } .feather { --icon-size: 24px; } - - &:hover { - .tip { - visibility: visible; - opacity: 1; - transition: opacity ease-out 100ms; - transition-delay: 150ms; - } - } } button { @@ -108,11 +132,6 @@ header { .feather { margin-right: 0; } - - .tip { - text-transform: initial; - font-weight: initial; - } } form { @@ -188,32 +207,12 @@ header { @media (min-width: $menuLayoutSwitchTreshold) { nav ul li { - a, button { - .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; - } + a, button, .button { + @include tip; } &:last-child { - a, button { + a, button, .button { .tip { left: unset; right: 4px; @@ -235,6 +234,10 @@ footer { main { flex: 1; padding: 8px; + + button, .button { + @include tip; + } } h1 { From a6d9c227899e0e596ecb1d2c26cc252dda732744 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 10:54:29 +0200 Subject: [PATCH 03/12] Add basic breadcrumb style --- assets/sass/layout.scss | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assets/sass/layout.scss b/assets/sass/layout.scss index f033e94..3169556 100644 --- a/assets/sass/layout.scss +++ b/assets/sass/layout.scss @@ -568,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 // --- From 041f52fd3ed031bbe9306b7cb8a0dd22cfebb767 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 10:54:50 +0200 Subject: [PATCH 04/12] Improve table .actions style --- assets/sass/app.scss | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/assets/sass/app.scss b/assets/sass/app.scss index 2919b90..673d561 100644 --- a/assets/sass/app.scss +++ b/assets/sass/app.scss @@ -1,7 +1,26 @@ @import "layout"; td.actions { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + + > *:not(:first-child) { + margin-left: 8px; + } + form { padding: 0; + display: inline; + } + + button, .button { + margin: 0; + padding: 8px; + + .feather { + margin-right: 0; + } } } From fe722a1dee0e28fc8851d93d53228e10f9c06ccc Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 10:58:18 +0200 Subject: [PATCH 05/12] Use button .tip in every table .actions --- views/account.njk | 6 +++--- views/backend/mailbox.njk | 2 +- views/backend/mailboxes.njk | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/views/account.njk b/views/account.njk index 31cf255..3d5fa1d 100644 --- a/views/account.njk +++ b/views/account.njk @@ -44,7 +44,7 @@ {{ macros.csrf(getCSRFToken) }} @@ -54,7 +54,7 @@ {{ macros.csrf(getCSRFToken) }} @@ -101,7 +101,7 @@ {{ macros.csrf(getCSRFToken) }} diff --git a/views/backend/mailbox.njk b/views/backend/mailbox.njk index fcdefea..b32ba4d 100644 --- a/views/backend/mailbox.njk +++ b/views/backend/mailbox.njk @@ -29,7 +29,7 @@ {{ macros.csrf(getCSRFToken) }} diff --git a/views/backend/mailboxes.njk b/views/backend/mailboxes.njk index 2c8bd72..431048e 100644 --- a/views/backend/mailboxes.njk +++ b/views/backend/mailboxes.njk @@ -42,8 +42,9 @@
- {{ macros.csrf(getCSRFToken) }} From d4709b0499459c3e9578c958292ee23c6be427d5 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 10:58:51 +0200 Subject: [PATCH 06/12] Backend/Mailboxes: add domain editing --- src/controllers/MailboxBackendController.ts | 35 +++++++++++++++++++-- views/backend/mail_domain.njk | 25 +++++++++++++++ views/backend/mailboxes.njk | 4 +++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 views/backend/mail_domain.njk diff --git a/src/controllers/MailboxBackendController.ts b/src/controllers/MailboxBackendController.ts index df71a42..3794516 100644 --- a/src/controllers/MailboxBackendController.ts +++ b/src/controllers/MailboxBackendController.ts @@ -28,8 +28,10 @@ export default class MailboxBackendController extends Controller { 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.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.post('/add-domain', this.postAddDomain, 'backend-add-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('/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(); } + protected async getEditDomain(req: Request, res: Response): Promise { + 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 { + 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 { const domain = await MailDomain.select() .where('id', req.body.id) diff --git a/views/backend/mail_domain.njk b/views/backend/mail_domain.njk new file mode 100644 index 0000000..2819781 --- /dev/null +++ b/views/backend/mail_domain.njk @@ -0,0 +1,25 @@ +{% extends 'layouts/base.njk' %} + +{% set title = app.name + ' - Backend' %} + +{% block body %} +
+ {{ macros.breadcrumb('Mail domain: ' + domain.name, [ + {title: 'Backend', link: route('backend')}, + {title: 'Mailboxes', link: route('backend-mailboxes')} + ]) }} + +
+ +

Mail domain: {{ domain.name }}

+ + + {{ macros.field(_locals, 'select', 'user_id', domain.user_id, 'Owner', null, 'required', users) }} + + + + {{ macros.csrf(getCSRFToken) }} + +
+
+{% endblock %} \ No newline at end of file diff --git a/views/backend/mailboxes.njk b/views/backend/mailboxes.njk index 431048e..211f2d9 100644 --- a/views/backend/mailboxes.njk +++ b/views/backend/mailboxes.njk @@ -39,6 +39,10 @@ {{ domain.owner_name | default('Public') }} {{ domain.identity_count }} + + Edit + +
From cd0f526ef5e77dc643d7ff7ca859ef024b90628e Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:02:11 +0200 Subject: [PATCH 07/12] Upgrade dependencies i.e. wms-core --- yarn.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yarn.lock b/yarn.lock index 681fbbe..b4e735b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" 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" resolved "https://registry.toot.party/ajv/-/ajv-6.12.3.tgz#18c5af38a111ddeb4f2697bd78d68abc1cabd706" integrity sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA== @@ -4448,11 +4448,11 @@ har-schema@^2.0.0: integrity sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= har-validator@~5.1.3: - version "5.1.3" - resolved "https://registry.toot.party/har-validator/-/har-validator-5.1.3.tgz#1ef89ebd3e4996557675eed9893110dc350fa080" - integrity sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== + version "5.1.5" + resolved "https://registry.toot.party/har-validator/-/har-validator-5.1.5.tgz#1f0803b9f8cb20c0fa13822df1ecddb36bde1efd" + integrity sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w== dependencies: - ajv "^6.5.5" + ajv "^6.12.3" har-schema "^2.0.0" has-ansi@^2.0.0: @@ -9886,9 +9886,9 @@ widest-line@^3.1.0: string-width "^4.0.0" wms-core@^0: - version "0.20.1" - resolved "https://registry.toot.party/wms-core/-/wms-core-0.20.1.tgz#c63a1b6b5cd4669e97fa0b651cd5fa6496f6305c" - integrity sha512-JZkrLgxoPBSOf8P5KB9Fc5IoEoWyw6qMoSukpCIi14iue/rm/rW5M9D0Y3dy6tio3w7ZRsrcQdYbIkXW228lzQ== + version "0.20.2" + resolved "https://registry.toot.party/wms-core/-/wms-core-0.20.2.tgz#b4d3d71a30b4d8bcbb2c422b3b89027ef5bb4b0e" + integrity sha512-MlK9J5VolObOFi+lJW8PFX4IrCi/vUvhC1FGzHCkzdeU5ODagaj7T1HV/7cOaJtzH/pHB+XD1U+oveajkVZSxA== dependencies: argon2 "^0.26.2" compression "^1.7.4" From 41a06d9de18e462dea70eec900120f21c5ea79dd Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:07:31 +0200 Subject: [PATCH 08/12] Use breadcrumb on more pages --- views/backend/mail_domain.njk | 4 ++-- views/backend/mailbox.njk | 16 ++++++++++------ views/backend/mailboxes.njk | 8 ++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/views/backend/mail_domain.njk b/views/backend/mail_domain.njk index 2819781..a0aaf10 100644 --- a/views/backend/mail_domain.njk +++ b/views/backend/mail_domain.njk @@ -9,7 +9,7 @@ {title: 'Mailboxes', link: route('backend-mailboxes')} ]) }} -
+

Mail domain: {{ domain.name }}

@@ -20,6 +20,6 @@ {{ macros.csrf(getCSRFToken) }} -
+ {% endblock %} \ No newline at end of file diff --git a/views/backend/mailbox.njk b/views/backend/mailbox.njk index b32ba4d..773bd51 100644 --- a/views/backend/mailbox.njk +++ b/views/backend/mailbox.njk @@ -4,11 +4,14 @@ {% block body %}
-
- -

Mailbox

+ {{ macros.breadcrumb(mailbox.name, [ + {title: 'Backend', link: route('backend')}, + {title: 'Mailboxes', link: route('backend-mailboxes')} + ]) }} -

{{ mailbox.name }}

+
+ +

Mailbox: {{ mailbox.name }}

@@ -28,7 +31,8 @@ - @@ -53,6 +57,6 @@ {{ macros.csrf(getCSRFToken) }} - + {% endblock %} \ No newline at end of file diff --git a/views/backend/mailboxes.njk b/views/backend/mailboxes.njk index 211f2d9..9b7700c 100644 --- a/views/backend/mailboxes.njk +++ b/views/backend/mailboxes.njk @@ -3,9 +3,13 @@ {% set title = app.name + ' - Backend' %} {% block body %} -

Mailbox manager

-
+ {{ macros.breadcrumb('Mailboxes', [ + {title: 'Backend', link: route('backend')} + ]) }} + +

Mailbox manager

+

Domains

From 4dede38da41af60c03b23a26ab82950474869970 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:14:02 +0200 Subject: [PATCH 09/12] layout.scss: fix select chevron position when field has error --- assets/sass/layout.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/sass/layout.scss b/assets/sass/layout.scss index 3169556..eb52dc4 100644 --- a/assets/sass/layout.scss +++ b/assets/sass/layout.scss @@ -376,7 +376,7 @@ form { position: absolute; pointer-events: none; right: 8px; - bottom: 8px; + top: 30px; transition: transform 150ms ease-out; } From 21e327251ac777836effca172673623aad22523c Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:14:35 +0200 Subject: [PATCH 10/12] Backend/MailDomain: allow setting domain owner to public --- src/controllers/MailboxBackendController.ts | 2 +- src/models/MailDomain.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/MailboxBackendController.ts b/src/controllers/MailboxBackendController.ts index 3794516..3685e88 100644 --- a/src/controllers/MailboxBackendController.ts +++ b/src/controllers/MailboxBackendController.ts @@ -128,7 +128,7 @@ export default class MailboxBackendController extends Controller { .first(); if (!domain) throw new NotFoundHttpError('Domain', req.url); - domain.user_id = req.body.user_id; + domain.updateWithData(req.body); await domain.save(); req.flash('success', `Domain ${domain.name} updated successfully.`); diff --git a/src/models/MailDomain.ts b/src/models/MailDomain.ts index d8f381c..5f40fbf 100644 --- a/src/models/MailDomain.ts +++ b/src/models/MailDomain.ts @@ -28,7 +28,8 @@ export default class MailDomain extends Model { } protected init(): void { - this.setValidation('name').defined().maxLength(252) + 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'); From 683043f340786874d4b1756d09c0da06257127b0 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:20:31 +0200 Subject: [PATCH 11/12] Backend/Mailboxes: improve design --- views/backend/mail_domain.njk | 2 +- views/backend/mailboxes.njk | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/views/backend/mail_domain.njk b/views/backend/mail_domain.njk index a0aaf10..861bc85 100644 --- a/views/backend/mail_domain.njk +++ b/views/backend/mail_domain.njk @@ -10,7 +10,7 @@ ]) }}
- +

Mail domain: {{ domain.name }}

diff --git a/views/backend/mailboxes.njk b/views/backend/mailboxes.njk index 9b7700c..1f9dc20 100644 --- a/views/backend/mailboxes.njk +++ b/views/backend/mailboxes.njk @@ -11,7 +11,7 @@

Mailbox manager

-

Domains

+

Domains

Add domain

@@ -65,7 +65,7 @@
-

Mailboxes

+

Mailboxes

@@ -75,6 +75,7 @@ + @@ -83,9 +84,14 @@ - + + {% endfor %} From e8f110d8eaff56a5b7a6542a4fe04dcdd5198fa2 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 30 Jul 2020 11:34:54 +0200 Subject: [PATCH 12/12] Version 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df77a79..2d78558 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aldap", - "version": "1.0.1", + "version": "1.1.0", "description": "Authentication LDAP server", "repository": "git@gitlab.com:ArisuOngaku/aldap.git", "author": "Alice Gaudon ",
Name Identities Owned domainsActions
{{ box.id }} {{ box.username }}{{ box.name }}{{ box.name }} {{ box.identity_count }} {{ box.domain_count }} + + Edit + +