From f5087ab4eef59db8c0c1f7f7e0d500003a3b8f5d Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Tue, 18 Jul 2023 13:55:02 -0700 Subject: [PATCH] Icu 10082 ldap account creation form (#1783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 Add support for LDAP account creation --- addons/core/translations/form/en-us.yaml | 1 + .../components/form/account/ldap/index.hbs | 84 +++++++++++++++++++ .../tests/acceptance/accounts/create-test.js | 21 +++++ 3 files changed, 106 insertions(+) create mode 100644 ui/admin/app/components/form/account/ldap/index.hbs diff --git a/addons/core/translations/form/en-us.yaml b/addons/core/translations/form/en-us.yaml index 7c2236ef1..c1f9e6723 100644 --- a/addons/core/translations/form/en-us.yaml +++ b/addons/core/translations/form/en-us.yaml @@ -20,6 +20,7 @@ type: help: The type of the resource, to help differentiate schemas login_name: label: Login Name + help: The account login name username: label: Username set_password: diff --git a/ui/admin/app/components/form/account/ldap/index.hbs b/ui/admin/app/components/form/account/ldap/index.hbs new file mode 100644 index 000000000..38ebf728f --- /dev/null +++ b/ui/admin/app/components/form/account/ldap/index.hbs @@ -0,0 +1,84 @@ +{{! + Copyright (c) HashiCorp, Inc. + SPDX-License-Identifier: MPL-2.0 +}} + + + + {{t 'form.type.label'}} + + + + {{t 'form.name.label'}} + {{t 'form.name.help'}} + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{t 'form.description.label'}} + {{t 'form.description.help'}} + {{#if @model.errors.description}} + + {{#each @model.errors.description as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{t 'form.login_name.label'}} + {{t 'form.login_name.help'}} + {{#if @model.errors.login_name}} + + {{#each @model.errors.login_name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + {{#if (can 'save model' @model)}} + + {{/if}} + + \ No newline at end of file diff --git a/ui/admin/tests/acceptance/accounts/create-test.js b/ui/admin/tests/acceptance/accounts/create-test.js index 64ff9f962..41f3560a4 100644 --- a/ui/admin/tests/acceptance/accounts/create-test.js +++ b/ui/admin/tests/acceptance/accounts/create-test.js @@ -85,6 +85,17 @@ module('Acceptance | accounts | create', function (hooks) { assert.strictEqual(this.server.db.accounts.length, accountsCount + 1); }); + test('can create a new LDAP account', async function (assert) { + assert.expect(1); + const accountsCount = this.server.db.accounts.length; + await visit(urls.newAccount); + await fillIn('[name="name"]', 'Account name'); + await fillIn('[name="description"]', 'description'); + await fillIn('[name="login_name"]', 'username'); + await click('form [type="submit"]:not(:disabled)'); + assert.strictEqual(this.server.schema.accounts.all().models.length, accountsCount + 1); + }); + test('Users cannot create a new account without proper authorization', async function (assert) { assert.expect(2); instances.authMethod.authorized_collection_actions.accounts = []; @@ -130,6 +141,16 @@ module('Acceptance | accounts | create', function (hooks) { assert.strictEqual(currentURL(), urls.accounts); }); + test('can cancel a new LDAP account creation', async function (assert) { + assert.expect(2); + const accountsCount = this.server.db.accounts.length; + await visit(urls.newAccount); + await fillIn('[name="name"]', 'Account name'); + await click('form button:not([type="submit"])'); + assert.strictEqual(this.server.db.accounts.length, accountsCount); + assert.strictEqual(currentURL(), urls.accounts); + }); + test('saving a new account with invalid fields displays error messages', async function (assert) { assert.expect(2); this.server.post('/accounts', () => {