From 91383269b92613dffdbab4ce857bfea032b1e50e Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 1 Dec 2021 11:04:02 +0000 Subject: [PATCH] ui: Move nspace CRUD to use the same approach as partitions (#11633) This sounds a bit 'backwards' as the end goal here is to add an improved UX to partitions, not namespaces. The reason for doing it this way is that Namespaces already has a type of 'improved UX' CRUD in that it has one to many relationship in the form when saving your namespaces (the end goal for partitions). In moving Namespaces to use the same approach as partitions we: - Ensure the new approach works with one-to-many forms. - Test the new approach without writing a single test (we already have a bunch of tests for namespaces which are now testing the approach used by both namespaces and partitions) Additionally: - Fixes issue with missing default nspace in the nspace selector - In doing when checking to see that things where consistent between the two, I found a few little minor problems with the Admin Partition CRUD so fixed those up here also. - Removed the old style Nspace notifications --- .circleci/config.yml | 2 +- ui/package.json | 2 +- .../components/consul/nspace/form/README.mdx | 24 +++ .../components/consul/nspace/form/index.hbs | 169 ++++++++++++++++++ .../components/consul/nspace/list/README.mdx | 25 +-- .../components/consul/nspace/list/index.hbs | 0 .../consul/nspace/list/pageobject.js | 0 .../consul/nspace/notifications/README.mdx | 19 ++ .../consul/nspace/notifications/index.hbs | 16 ++ .../consul/nspace/search-bar/README.mdx | 30 ++++ .../consul/nspace/search-bar/index.hbs | 0 .../consul/nspace/selector/README.mdx | 40 +++++ .../consul/nspace/selector/index.hbs | 74 ++++++++ .../app/templates/dc/nspaces/edit.hbs | 15 +- .../app/templates/dc/nspaces/index.hbs | 34 +++- ui/packages/consul-nspaces/package.json | 5 + .../vendor/consul-nspaces/routes.js | 38 ++++ .../consul/partition/form/index.hbs | 42 +++-- .../consul/partition/list/README.mdx | 5 +- .../consul/partition/notifications/README.mdx | 39 +--- .../consul/partition/notifications/index.hbs | 38 ++-- .../app/templates/dc/partitions/edit.hbs | 23 +-- .../app/templates/dc/partitions/index.hbs | 16 +- ui/packages/consul-ui/.docfy-config.js | 6 + .../consul/nspace/notifications/index.hbs | 24 --- .../app/components/hashicorp-consul/index.hbs | 68 +------ .../app/controllers/dc/nspaces/create.js | 2 - .../app/controllers/dc/nspaces/edit.js | 24 --- ui/packages/consul-ui/app/forms/nspace.js | 9 - ui/packages/consul-ui/app/forms/partition.js | 7 - ui/packages/consul-ui/app/router.js | 17 -- .../consul-ui/app/routes/dc/nspaces/create.js | 5 - .../consul-ui/app/routes/dc/nspaces/edit.js | 8 - .../consul-ui/app/routes/dc/nspaces/index.js | 19 -- ui/packages/consul-ui/app/routing/route.js | 7 +- .../consul-ui/app/serializers/nspace.js | 6 +- .../consul-ui/app/serializers/partition.js | 4 +- .../app/services/data-sink/protocols/http.js | 1 + ui/packages/consul-ui/app/services/form.js | 4 - .../app/services/repository/nspace.js | 9 +- .../app/services/repository/partition.js | 7 +- .../app/templates/dc/nspaces/-form.hbs | 80 --------- ui/packages/consul-ui/app/templates/debug.hbs | 10 ++ .../consul-ui/app/templates/nspace.hbs | 10 -- .../consul-ui/app/utils/form/builder.js | 2 +- .../consul-ui/app/validations/nspace.js | 4 - ui/packages/consul-ui/ember-cli-build.js | 3 +- ui/packages/consul-ui/lib/startup/index.js | 5 + .../lib/startup/templates/body.html.js | 16 +- ui/packages/consul-ui/package.json | 1 + .../acceptance/dc/nspaces/delete.feature | 11 +- .../integration/serializers/nspace-test.js | 4 +- .../integration/serializers/partition-test.js | 6 +- .../controllers/dc/nspaces/create-test.js | 12 -- .../unit/controllers/dc/nspaces/edit-test.js | 12 -- .../unit/routes/dc/nspaces/create-test.js | 11 -- .../tests/unit/routes/dc/nspaces/edit-test.js | 11 -- .../unit/routes/dc/nspaces/index-test.js | 11 -- 58 files changed, 601 insertions(+), 491 deletions(-) create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/form/README.mdx create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/form/index.hbs rename ui/packages/{consul-ui => consul-nspaces}/app/components/consul/nspace/list/README.mdx (60%) rename ui/packages/{consul-ui => consul-nspaces}/app/components/consul/nspace/list/index.hbs (100%) rename ui/packages/{consul-ui => consul-nspaces}/app/components/consul/nspace/list/pageobject.js (100%) create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/notifications/README.mdx create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/notifications/index.hbs create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/README.mdx rename ui/packages/{consul-ui => consul-nspaces}/app/components/consul/nspace/search-bar/index.hbs (100%) create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/selector/README.mdx create mode 100644 ui/packages/consul-nspaces/app/components/consul/nspace/selector/index.hbs rename ui/packages/{consul-ui => consul-nspaces}/app/templates/dc/nspaces/edit.hbs (83%) rename ui/packages/{consul-ui => consul-nspaces}/app/templates/dc/nspaces/index.hbs (82%) create mode 100644 ui/packages/consul-nspaces/package.json create mode 100644 ui/packages/consul-nspaces/vendor/consul-nspaces/routes.js delete mode 100644 ui/packages/consul-ui/app/components/consul/nspace/notifications/index.hbs delete mode 100644 ui/packages/consul-ui/app/controllers/dc/nspaces/create.js delete mode 100644 ui/packages/consul-ui/app/controllers/dc/nspaces/edit.js delete mode 100644 ui/packages/consul-ui/app/forms/nspace.js delete mode 100644 ui/packages/consul-ui/app/forms/partition.js delete mode 100644 ui/packages/consul-ui/app/routes/dc/nspaces/create.js delete mode 100644 ui/packages/consul-ui/app/routes/dc/nspaces/edit.js delete mode 100644 ui/packages/consul-ui/app/routes/dc/nspaces/index.js delete mode 100644 ui/packages/consul-ui/app/templates/dc/nspaces/-form.hbs delete mode 100644 ui/packages/consul-ui/app/templates/nspace.hbs delete mode 100644 ui/packages/consul-ui/app/validations/nspace.js delete mode 100644 ui/packages/consul-ui/tests/unit/controllers/dc/nspaces/create-test.js delete mode 100644 ui/packages/consul-ui/tests/unit/controllers/dc/nspaces/edit-test.js delete mode 100644 ui/packages/consul-ui/tests/unit/routes/dc/nspaces/create-test.js delete mode 100644 ui/packages/consul-ui/tests/unit/routes/dc/nspaces/edit-test.js delete mode 100644 ui/packages/consul-ui/tests/unit/routes/dc/nspaces/index-test.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b587dc02..fcdbea518 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,7 @@ references: test-results: &TEST_RESULTS_DIR /tmp/test-results cache: - yarn: &YARN_CACHE_KEY consul-ui-v5-{{ checksum "ui/yarn.lock" }} + yarn: &YARN_CACHE_KEY consul-ui-v6-{{ checksum "ui/yarn.lock" }} rubygem: &RUBYGEM_CACHE_KEY static-site-gems-v1-{{ checksum "Gemfile.lock" }} environment: &ENVIRONMENT diff --git a/ui/package.json b/ui/package.json index 06b57506c..542087e1d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -11,7 +11,7 @@ "scripts": { "doc:toc": "doctoc README.md", "compliance": "npm-run-all compliance:*", - "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-partitions@0.1.0'" + "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0'" }, "devDependencies": { diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/form/README.mdx b/ui/packages/consul-nspaces/app/components/consul/nspace/form/README.mdx new file mode 100644 index 000000000..d9e2eb2d2 --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/form/README.mdx @@ -0,0 +1,24 @@ +# Consul::Nspace::Form + +```hbs preview-template + + + + + +``` diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/form/index.hbs b/ui/packages/consul-nspaces/app/components/consul/nspace/form/index.hbs new file mode 100644 index 000000000..ec2a3d6b4 --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/form/index.hbs @@ -0,0 +1,169 @@ +
+ + + + + + + +{{#let + + (not (can "write nspaces")) + + @item + + (hash + help='Must be a valid DNS hostname. Must contain 1-64 characters (numbers, letters, and hyphens), and must begin with a letter. Once created, this cannot be changed.' + Name=(array + (hash + test='^[a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?$' + error='Name must be a valid DNS hostname.' + ) + ) + ) + + (hash + Description=(array) + ) + +as |readOnly item Name Description|}} +
+ + + +
+{{#if (is "new nspace" item=item)}} + +{{/if}} + +
+{{#if (can 'use acls')}} +
+

Roles

+

+{{#if (can "write nspace" item=item)}} + By adding roles to this namespaces, you will apply them to all tokens created within this namespace. +{{else}} + The following roles are applied to all tokens created within this namespace. +{{/if}} +

+ +
+
+

Policies

+

+{{#if (not readOnly)}} + By adding policies to this namespace, you will apply them to all tokens created within this namespace. +{{else}} + The following policies are applied to all tokens created within this namespace. +{{/if}} +

+ +
+{{/if}} +
+{{#if (and (is "new nspace" item=item) (can "create nspaces"))}} + + Save + +{{else if (can "write nspace" item=item)}} + Save +{{/if}} + + + Cancel + + +{{#if (and (not (is "new nspace" item=item)) (can "delete nspace" item=item))}} + + + + Delete + + + + + + +{{/if}} + +
+
+
+{{/let}} +
+
+
+ diff --git a/ui/packages/consul-ui/app/components/consul/nspace/list/README.mdx b/ui/packages/consul-nspaces/app/components/consul/nspace/list/README.mdx similarity index 60% rename from ui/packages/consul-ui/app/components/consul/nspace/list/README.mdx rename to ui/packages/consul-nspaces/app/components/consul/nspace/list/README.mdx index 7be2debf0..7e5ee50cd 100644 --- a/ui/packages/consul-ui/app/components/consul/nspace/list/README.mdx +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/list/README.mdx @@ -1,29 +1,30 @@ ---- -class: ember ---- -## Consul::Nspace::List +# Consul::Nspace::List -```hbs - +A presentational component for rendering Consul Namespaces + +Please note: + +- For the moment, make sure you have enabled nspaces using developer debug + cookies. + +```hbs preview-template + ``` -A presentational component for rendering Consul Namespaces - -### Arguments +## Arguments | Argument/Attribute | Type | Default | Description | | --- | --- | --- | --- | | `items` | `array` | | An array of Namespaces | | `ondelete` | `function` | | An action to execute when the `Delete` action is clicked | -### See +## See -- [Component Source Code](./index.js) - [Template Source Code](./index.hbs) --- diff --git a/ui/packages/consul-ui/app/components/consul/nspace/list/index.hbs b/ui/packages/consul-nspaces/app/components/consul/nspace/list/index.hbs similarity index 100% rename from ui/packages/consul-ui/app/components/consul/nspace/list/index.hbs rename to ui/packages/consul-nspaces/app/components/consul/nspace/list/index.hbs diff --git a/ui/packages/consul-ui/app/components/consul/nspace/list/pageobject.js b/ui/packages/consul-nspaces/app/components/consul/nspace/list/pageobject.js similarity index 100% rename from ui/packages/consul-ui/app/components/consul/nspace/list/pageobject.js rename to ui/packages/consul-nspaces/app/components/consul/nspace/list/pageobject.js diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/README.mdx b/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/README.mdx new file mode 100644 index 000000000..fb2f834dd --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/README.mdx @@ -0,0 +1,19 @@ +# Consul::Nspace::Notifications + +A Notification component specifically for namespaces. This is only a component as we currently use this in two places and if we need to add more types we can do so in one place. + +We currently only have one 'remove' type due to the fact that namespaces can't use the default 'delete' notification as they get 'marked for deletion' instead. + +```hbs preview-template + +``` + + + +## See + +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/index.hbs b/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/index.hbs new file mode 100644 index 000000000..c373a535b --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/notifications/index.hbs @@ -0,0 +1,16 @@ +{{#if (eq @type 'remove')}} + + + Success! + + +

+ Your Namespace has been marked for deletion. +

+
+
+{{/if}} diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/README.mdx b/ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/README.mdx new file mode 100644 index 000000000..0bcbd29fd --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/README.mdx @@ -0,0 +1,30 @@ +# Consul::Nspace::SearchBar + +Searchbar tailored for searching namespaces. Follows our more generic +'*::SearchBar' component interface. + +```hbs preview-template + +``` + +## See + +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-ui/app/components/consul/nspace/search-bar/index.hbs b/ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/index.hbs similarity index 100% rename from ui/packages/consul-ui/app/components/consul/nspace/search-bar/index.hbs rename to ui/packages/consul-nspaces/app/components/consul/nspace/search-bar/index.hbs diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/selector/README.mdx b/ui/packages/consul-nspaces/app/components/consul/nspace/selector/README.mdx new file mode 100644 index 000000000..afd5d8fb6 --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/selector/README.mdx @@ -0,0 +1,40 @@ +# Consul::Nspace::Selector + +A conditional, autoloading, menu component specifically for making it easy to select namespaces. + +Please note: + +- Currently at least, you must add this inside of a `
    ` element, as the `
  • ` elements output by this component are intended to be mixed with other sibling `
  • `s from other components or template code. +- For the moment, make sure you have enabled nspaces using developer debug + cookies. + +```hbs preview-template +
      + +
    +``` + + +## Arguments + +| Argument/Attribute | Type | Default | Description | +| --- | --- | --- | --- | +| `dc` | `object` | | The current datacenter | +| `nspace` | `string` | | The name of the current namespace | +| `partition` | `string` | | The name of the current partition | +| `nspaces` | `array` | | A list of nspace models/objects to use for the selector | +| `onchange` | `function` | | An event handler, for when nspaces are loaded. You probably want to update `@nspaces` using this. | + +## See + +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-nspaces/app/components/consul/nspace/selector/index.hbs b/ui/packages/consul-nspaces/app/components/consul/nspace/selector/index.hbs new file mode 100644 index 000000000..c3296dff2 --- /dev/null +++ b/ui/packages/consul-nspaces/app/components/consul/nspace/selector/index.hbs @@ -0,0 +1,74 @@ +{{#if (can "use nspaces")}} + {{#if (can "choose nspaces")}} +{{#let + (or @nspace 'default') +as |nspace|}} +
  • + + + {{nspace}} + + + {{#let components.MenuItem components.MenuSeparator as |MenuItem MenuSeparator|}} + {{#if (gt @nspaces.length 0)}} + + {{else}} + + {{/if}} + {{#each (reject-by 'DeletedAt' @nspaces) as |item|}} + + + {{item.Name}} + + + {{/each}} + {{#if (can 'manage nspaces')}} + + + + Manage Namespaces + + + {{/if}} + {{/let}} + + +
  • +{{/let}} + {{/if}} + {{/if}} + diff --git a/ui/packages/consul-ui/app/templates/dc/nspaces/edit.hbs b/ui/packages/consul-nspaces/app/templates/dc/nspaces/edit.hbs similarity index 83% rename from ui/packages/consul-ui/app/templates/dc/nspaces/edit.hbs rename to ui/packages/consul-nspaces/app/templates/dc/nspaces/edit.hbs index d21c293f6..3fef753e8 100644 --- a/ui/packages/consul-ui/app/templates/dc/nspaces/edit.hbs +++ b/ui/packages/consul-nspaces/app/templates/dc/nspaces/edit.hbs @@ -30,13 +30,6 @@ as |route|> loader.data.isNew as |dc partition nspace item create|}} - - -
    1. All Namespaces
    2. @@ -50,7 +43,13 @@ as |dc partition nspace item create|}} - {{ partial 'dc/nspaces/form'}} + {{/let}} diff --git a/ui/packages/consul-ui/app/templates/dc/nspaces/index.hbs b/ui/packages/consul-nspaces/app/templates/dc/nspaces/index.hbs similarity index 82% rename from ui/packages/consul-ui/app/templates/dc/nspaces/index.hbs rename to ui/packages/consul-nspaces/app/templates/dc/nspaces/index.hbs index e5721fbb5..ec008d528 100644 --- a/ui/packages/consul-ui/app/templates/dc/nspaces/index.hbs +++ b/ui/packages/consul-nspaces/app/templates/dc/nspaces/index.hbs @@ -42,13 +42,6 @@ as |route|> as |sort filters items|}} - - -

      @@ -72,6 +65,27 @@ as |route|> {{/if}} + + + + + @@ -118,9 +132,11 @@ as |route|> + + {{/let}} - \ No newline at end of file + diff --git a/ui/packages/consul-nspaces/package.json b/ui/packages/consul-nspaces/package.json new file mode 100644 index 000000000..96ff1ed9b --- /dev/null +++ b/ui/packages/consul-nspaces/package.json @@ -0,0 +1,5 @@ +{ + "name": "consul-nspaces", + "version": "0.1.0", + "private": true +} diff --git a/ui/packages/consul-nspaces/vendor/consul-nspaces/routes.js b/ui/packages/consul-nspaces/vendor/consul-nspaces/routes.js new file mode 100644 index 000000000..3f8a0f904 --- /dev/null +++ b/ui/packages/consul-nspaces/vendor/consul-nspaces/routes.js @@ -0,0 +1,38 @@ +(routes => routes({ + dc: { + nspaces: { + _options: { + path: '/namespaces', + queryParams: { + sortBy: 'sort', + searchproperty: { + as: 'searchproperty', + empty: [['Name', 'Description', 'Role', 'Policy']], + }, + search: { + as: 'filter', + replace: true, + }, + }, + abilities: ['read nspaces'], + }, + edit: { + _options: { path: '/:name' }, + }, + create: { + _options: { + template: 'dc/nspaces/edit', + path: '/create', + abilities: ['create nspaces'], + }, + }, + }, + }, +}))( + (json, data = document.currentScript.dataset) => { + const appNameJS = data.appName.split('-') + .map((item, i) => i ? `${item.substr(0, 1).toUpperCase()}${item.substr(1)}` : item) + .join(''); + data[`${appNameJS}Routes`] = JSON.stringify(json); + } +); diff --git a/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs index 7795f03c1..07bdf9281 100644 --- a/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs +++ b/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs @@ -12,14 +12,24 @@ ) }} @type={{'partition'}} - @label={{label}} + @label={{'Admin Partition'}} @ondelete={{fn (if @ondelete @ondelete @onsubmit) @item}} @onchange={{fn (optional @onsubmit) @item}} as |writer|> + + + {{#let + + (not (can "write partition")) @item @@ -37,19 +47,18 @@ Description=(array) ) -as |item Name Description|}} - +as |readOnly item Name Description|}}
      +as |State Guard ChartAction dispatch state|>
      - {{#if (is "new partition" item=item)}} +{{#if (is "new partition" item=item)}}
      {{#if (and (is "new partition" item=item) (can "create partitions")) }} - -{{else if (can "write partition" item=item)}} - + +{{else if (not readOnly)}} + Save {{/if}} - + {{#if (and (not (is "new partition" item=item)) (can "delete partition" item=item))}} - + -
      Provide a widget to change the @type
      - - - -
      -
      Provide a widget to change the @status
      - - -
      -
      -
      Show the notification text
      -

      - -

      -
      - + ``` diff --git a/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs index 14eb0c41a..46e0f483b 100644 --- a/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs +++ b/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs @@ -1,24 +1,16 @@ -{{#if (eq @type 'create')}} - {{#if (eq @status 'success') }} - Your partition has been added. - {{else}} - There was an error adding your partition. - {{/if}} -{{else if (eq @type 'update') }} - {{#if (eq @status 'success') }} - Your partition has been saved. - {{else}} - There was an error saving your partition. - {{/if}} -{{ else if (eq @type 'delete')}} - {{#if (eq @status 'success') }} - Your partition has been marked for deletion. - {{else}} - There was an error deleting your partition. - {{/if}} +{{#if (eq @type 'remove')}} + + + Success! + + +

      + Your Admin Partition has been marked for deletion. +

      +
      +
      {{/if}} -{{#let @error.errors.firstObject as |error|}} - {{#if error.detail }} -
      {{concat '(' (if error.status (concat error.status ': ')) error.detail ')'}} - {{/if}} -{{/let}} diff --git a/ui/packages/consul-partitions/app/templates/dc/partitions/edit.hbs b/ui/packages/consul-partitions/app/templates/dc/partitions/edit.hbs index 019ca28bf..0396562f6 100644 --- a/ui/packages/consul-partitions/app/templates/dc/partitions/edit.hbs +++ b/ui/packages/consul-partitions/app/templates/dc/partitions/edit.hbs @@ -27,28 +27,24 @@ as |route|> route.params.nspace loader.data - loader.data.isNew -as |dc partition nspace item create|}} +as |dc partition nspace item|}} - - -
        -
      1. All Partitions
      2. +
      3. All Admin Partitions

      - +

      - - -
      {{/let}} diff --git a/ui/packages/consul-partitions/app/templates/dc/partitions/index.hbs b/ui/packages/consul-partitions/app/templates/dc/partitions/index.hbs index cf905bfd5..363bf4a5b 100644 --- a/ui/packages/consul-partitions/app/templates/dc/partitions/index.hbs +++ b/ui/packages/consul-partitions/app/templates/dc/partitions/index.hbs @@ -42,13 +42,6 @@ as |route|> as |sort filters items|}} - - -

      @@ -79,8 +72,17 @@ as |route|> ) }} @type="partition" + @label="Admin Partition" @ondelete={{refresh-route}} as |writer|> + + + {{concat '(' (if error.status (concat error.status ': ')) error.detail ')'}} - {{/if}} -{{/let}} diff --git a/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs b/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs index 026cb84ab..8a7336f9c 100644 --- a/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs +++ b/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs @@ -60,13 +60,6 @@ @item={{flash.item}} @error={{flash.error}} /> - {{else if (eq flash.model 'nspace')}} - {{/if}} {{/if}}

      @@ -140,60 +133,13 @@ @partitions={{this.partitions}} @onchange={{action (mut this.partitions) value="data"}} /> - {{#if (can "choose nspaces")}} -
    3. - - - {{@nspace}} - - - {{#let components.MenuItem components.MenuSeparator as |MenuItem MenuSeparator|}} - - {{#each (reject-by 'DeletedAt' this.nspaces) as |item|}} - - - {{item.Name}} - - - {{/each}} - {{#if (can 'manage nspaces')}} - - - - Manage Namespaces - - - {{/if}} - {{/let}} - - -
    4. - {{/if}} + {{#if (can "read services")}}
    5. Services diff --git a/ui/packages/consul-ui/app/controllers/dc/nspaces/create.js b/ui/packages/consul-ui/app/controllers/dc/nspaces/create.js deleted file mode 100644 index f4c701cbb..000000000 --- a/ui/packages/consul-ui/app/controllers/dc/nspaces/create.js +++ /dev/null @@ -1,2 +0,0 @@ -import Controller from './edit'; -export default class CreateController extends Controller {} diff --git a/ui/packages/consul-ui/app/controllers/dc/nspaces/edit.js b/ui/packages/consul-ui/app/controllers/dc/nspaces/edit.js deleted file mode 100644 index a5d410f24..000000000 --- a/ui/packages/consul-ui/app/controllers/dc/nspaces/edit.js +++ /dev/null @@ -1,24 +0,0 @@ -import Controller from '@ember/controller'; -import { inject as service } from '@ember/service'; -export default Controller.extend({ - dom: service('dom'), - builder: service('form'), - init: function() { - this._super(...arguments); - this.form = this.builder.form('nspace'); - }, - actions: { - change: function(e, value, item) { - const event = this.dom.normalizeEvent(e, value); - try { - this.form.handleEvent(event); - } catch (err) { - const target = event.target; - switch (target.name) { - default: - throw err; - } - } - }, - }, -}); diff --git a/ui/packages/consul-ui/app/forms/nspace.js b/ui/packages/consul-ui/app/forms/nspace.js deleted file mode 100644 index e6013896e..000000000 --- a/ui/packages/consul-ui/app/forms/nspace.js +++ /dev/null @@ -1,9 +0,0 @@ -import validations from 'consul-ui/validations/nspace'; -import builderFactory from 'consul-ui/utils/form/builder'; -const builder = builderFactory(); -export default function(container, name = '', v = validations, form = builder) { - return form(name, {}) - .setValidators(v) - .add(container.form('policy')) - .add(container.form('role')); -} diff --git a/ui/packages/consul-ui/app/forms/partition.js b/ui/packages/consul-ui/app/forms/partition.js deleted file mode 100644 index eac1aebf4..000000000 --- a/ui/packages/consul-ui/app/forms/partition.js +++ /dev/null @@ -1,7 +0,0 @@ -import validations from 'consul-ui/validations/nspace'; -import builderFactory from 'consul-ui/utils/form/builder'; -const builder = builderFactory(); -export default function(container, name = '', v = validations, form = builder) { - return form(name, {}) - .setValidators(v); -} diff --git a/ui/packages/consul-ui/app/router.js b/ui/packages/consul-ui/app/router.js index 540ae7093..6ecbd29a0 100644 --- a/ui/packages/consul-ui/app/router.js +++ b/ui/packages/consul-ui/app/router.js @@ -231,23 +231,6 @@ export const routes = merge.all( ) ); -if (env('CONSUL_NSPACES_ENABLED')) { - routes.dc.nspaces = { - _options: { - path: '/namespaces', - abilities: ['read nspaces'], - }, - edit: { - _options: { path: '/:name' }, - }, - create: { - _options: { - path: '/create', - abilities: ['create nspaces'], - }, - }, - }; -} runInDebug(() => { // check to see if we are running docfy and if so add its routes to our // route config diff --git a/ui/packages/consul-ui/app/routes/dc/nspaces/create.js b/ui/packages/consul-ui/app/routes/dc/nspaces/create.js deleted file mode 100644 index 323515187..000000000 --- a/ui/packages/consul-ui/app/routes/dc/nspaces/create.js +++ /dev/null @@ -1,5 +0,0 @@ -import Route from './edit'; - -export default class CreateRoute extends Route { - templateName = 'dc/nspaces/edit'; -} diff --git a/ui/packages/consul-ui/app/routes/dc/nspaces/edit.js b/ui/packages/consul-ui/app/routes/dc/nspaces/edit.js deleted file mode 100644 index 12c20d3bd..000000000 --- a/ui/packages/consul-ui/app/routes/dc/nspaces/edit.js +++ /dev/null @@ -1,8 +0,0 @@ -import { inject as service } from '@ember/service'; -import Route from 'consul-ui/routing/route'; - -import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions'; - -export default class EditRoute extends Route.extend(WithBlockingActions) { - @service('repository/nspace') repo; -} diff --git a/ui/packages/consul-ui/app/routes/dc/nspaces/index.js b/ui/packages/consul-ui/app/routes/dc/nspaces/index.js deleted file mode 100644 index 449b32dc1..000000000 --- a/ui/packages/consul-ui/app/routes/dc/nspaces/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import { inject as service } from '@ember/service'; -import Route from 'consul-ui/routing/route'; - -import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions'; -export default class IndexRoute extends Route.extend(WithBlockingActions) { - @service('repository/nspace') repo; - - queryParams = { - sortBy: 'sort', - searchproperty: { - as: 'searchproperty', - empty: [['Name', 'Description', 'Role', 'Policy']], - }, - search: { - as: 'filter', - replace: true, - }, - }; -} diff --git a/ui/packages/consul-ui/app/routing/route.js b/ui/packages/consul-ui/app/routing/route.js index 6e4ae8784..02b1edf2d 100644 --- a/ui/packages/consul-ui/app/routing/route.js +++ b/ui/packages/consul-ui/app/routing/route.js @@ -22,11 +22,14 @@ export default class BaseRoute extends Route { .filter(item => item !== 'index') .join('.'); const template = get(routes, `${routeName}._options.template`); - if(template) { + if (template) { this.templateName = template; } const queryParams = get(routes, `${routeName}._options.queryParams`); - if(queryParams && (this.routeName === 'dc.partitions.index' || this.routeName === 'oauth-provider-debug')) { + if ( + queryParams && + ['dc.partitions.index', 'dc.nspaces.index', 'oauth-provider-debug'].includes(this.routeName) + ) { this.queryParams = queryParams; } } diff --git a/ui/packages/consul-ui/app/serializers/nspace.js b/ui/packages/consul-ui/app/serializers/nspace.js index 9be706bae..a5fbba736 100644 --- a/ui/packages/consul-ui/app/serializers/nspace.js +++ b/ui/packages/consul-ui/app/serializers/nspace.js @@ -13,7 +13,7 @@ export default class NspaceSerializer extends Serializer { cb( headers, body.map(function(item) { - item.Namespace = item.Name; + item.Namespace = '*'; item.Datacenter = query.dc; if (get(item, 'ACLs.PolicyDefaults')) { item.ACLs.PolicyDefaults = item.ACLs.PolicyDefaults.map(function(item) { @@ -45,7 +45,7 @@ export default class NspaceSerializer extends Serializer { cb => respond((headers, body) => { body.Datacenter = serialized.dc; - body.Namespace = body.Name; + body.Namespace = '*'; return cb(headers, body); }), serialized, @@ -58,7 +58,7 @@ export default class NspaceSerializer extends Serializer { cb => respond((headers, body) => { body.Datacenter = serialized.dc; - body.Namespace = body.Name; + body.Namespace = '*'; return cb(headers, body); }), serialized, diff --git a/ui/packages/consul-ui/app/serializers/partition.js b/ui/packages/consul-ui/app/serializers/partition.js index bdf56008a..8be29799b 100644 --- a/ui/packages/consul-ui/app/serializers/partition.js +++ b/ui/packages/consul-ui/app/serializers/partition.js @@ -12,8 +12,8 @@ export default class PartitionSerializer extends Serializer { return cb( headers, body.Partitions.map(item => { - item.Partition = item.Name; - item.Namespace = ''; + item.Partition = '*'; + item.Namespace = '*'; return item; }) ); diff --git a/ui/packages/consul-ui/app/services/data-sink/protocols/http.js b/ui/packages/consul-ui/app/services/data-sink/protocols/http.js index 4a44710a8..21467648b 100644 --- a/ui/packages/consul-ui/app/services/data-sink/protocols/http.js +++ b/ui/packages/consul-ui/app/services/data-sink/protocols/http.js @@ -5,6 +5,7 @@ export default class HttpService extends Service { @service('settings') settings; @service('repository/intention') intention; @service('repository/kv') kv; + @service('repository/nspace') nspace; @service('repository/partition') partition; @service('repository/session') session; diff --git a/ui/packages/consul-ui/app/services/form.js b/ui/packages/consul-ui/app/services/form.js index faec09a6e..d580ec911 100644 --- a/ui/packages/consul-ui/app/services/form.js +++ b/ui/packages/consul-ui/app/services/form.js @@ -6,8 +6,6 @@ import token from 'consul-ui/forms/token'; import policy from 'consul-ui/forms/policy'; import role from 'consul-ui/forms/role'; import intention from 'consul-ui/forms/intention'; -import nspace from 'consul-ui/forms/nspace'; -import partition from 'consul-ui/forms/partition'; const builder = builderFactory(); @@ -17,8 +15,6 @@ const forms = { policy: policy, role: role, intention: intention, - nspace: nspace, - partition: partition, }; export default class FormService extends Service { diff --git a/ui/packages/consul-ui/app/services/repository/nspace.js b/ui/packages/consul-ui/app/services/repository/nspace.js index 0327c4810..51fac2f92 100644 --- a/ui/packages/consul-ui/app/services/repository/nspace.js +++ b/ui/packages/consul-ui/app/services/repository/nspace.js @@ -4,6 +4,8 @@ import RepositoryService, { softDelete } from 'consul-ui/services/repository'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace'; import dataSource from 'consul-ui/decorators/data-source'; +import { defaultChangeset as changeset } from 'consul-ui/utils/form/builder'; + const findActiveNspace = function(nspaces, nspace) { let found = nspaces.find(function(item) { return item.Name === nspace.Name; @@ -24,7 +26,7 @@ const findActiveNspace = function(nspaces, nspace) { return found; }; const modelName = 'nspace'; -export default class NspaceEnabledService extends RepositoryService { +export default class NspaceService extends RepositoryService { @service('router') router; @service('container') container; @service('env') env; @@ -68,10 +70,7 @@ export default class NspaceEnabledService extends RepositoryService { } else { item = await super.findBySlug(...arguments); } - return this.form - .form(this.getModelName()) - .setData(item) - .getData(); + return changeset(item); } remove(item) { diff --git a/ui/packages/consul-ui/app/services/repository/partition.js b/ui/packages/consul-ui/app/services/repository/partition.js index 37baf8c02..118e7e2be 100644 --- a/ui/packages/consul-ui/app/services/repository/partition.js +++ b/ui/packages/consul-ui/app/services/repository/partition.js @@ -4,6 +4,8 @@ import RepositoryService, { softDelete } from 'consul-ui/services/repository'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/partition'; import dataSource from 'consul-ui/decorators/data-source'; +import { defaultChangeset as changeset } from 'consul-ui/utils/form/builder'; + const findActive = function(items, item) { let found = items.find(function(i) { return i.Name === item.Name; @@ -61,10 +63,7 @@ export default class PartitionRepository extends RepositoryService { } else { item = await super.findBySlug(...arguments); } - return this.form - .form(this.getModelName()) - .setData(item) - .getData(); + return changeset(item); } remove(item) { diff --git a/ui/packages/consul-ui/app/templates/dc/nspaces/-form.hbs b/ui/packages/consul-ui/app/templates/dc/nspaces/-form.hbs deleted file mode 100644 index 8a807af2f..000000000 --- a/ui/packages/consul-ui/app/templates/dc/nspaces/-form.hbs +++ /dev/null @@ -1,80 +0,0 @@ - -
      -{{#if create }} - -{{/if}} - -
      -{{#if (env 'CONSUL_ACLS_ENABLED')}} -
      -

      Roles

      -

      - {{#if (can "write nspace" item=item)}} - By adding roles to this namespaces, you will apply them to all tokens created within this namespace. - {{else}} - The following roles are applied to all tokens created within this namespace. - {{/if}} -

      - -
      -
      -

      Policies

      -

      - {{#if (can "write nspace" item=item)}} - By adding policies to this namespaces, you will apply them to all tokens created within this namespace. - {{else}} - The following policies are applied to all tokens created within this namespace. - {{/if}} -

      - -
      -{{/if}} -
      -{{#if (and create (can "create nspaces")) }} - -{{else}} - {{#if (can "write nspace" item=item)}} - - {{/if}} -{{/if}} - -{{# if (and (not create) (can "delete nspace" item=item) ) }} - - - - - - - - -{{/if}} -
      -
    6. - diff --git a/ui/packages/consul-ui/app/templates/debug.hbs b/ui/packages/consul-ui/app/templates/debug.hbs index 7559e37c8..b767b5197 100644 --- a/ui/packages/consul-ui/app/templates/debug.hbs +++ b/ui/packages/consul-ui/app/templates/debug.hbs @@ -1,6 +1,16 @@ {{page-title 'Engineering Docs - Consul' separator=' - '}} {{document-attrs class="is-debug"}} +{{! Tell CSS what we have enabled }} +{{#if (can "use acls")}} + {{document-attrs class="has-acls"}} +{{/if}} +{{#if (can "use nspaces")}} + {{document-attrs class="has-nspaces"}} +{{/if}} +{{#if (can "use partitions")}} + {{document-attrs class="has-partitions"}} +{{/if}} <:notifications as |app|> diff --git a/ui/packages/consul-ui/app/templates/nspace.hbs b/ui/packages/consul-ui/app/templates/nspace.hbs deleted file mode 100644 index a02351727..000000000 --- a/ui/packages/consul-ui/app/templates/nspace.hbs +++ /dev/null @@ -1,10 +0,0 @@ - - - {{outlet}} - - diff --git a/ui/packages/consul-ui/app/utils/form/builder.js b/ui/packages/consul-ui/app/utils/form/builder.js index b0091ee56..8d3276891 100644 --- a/ui/packages/consul-ui/app/utils/form/builder.js +++ b/ui/packages/consul-ui/app/utils/form/builder.js @@ -6,7 +6,7 @@ import lookupValidator from 'ember-changeset-validations'; // Keep these here for now so forms are easy to make // TODO: Probably move this to utils/form/parse-element-name import parseElementName from 'consul-ui/utils/get-form-name-property'; -const defaultChangeset = function(data, validators) { +export const defaultChangeset = function(data, validators) { return createChangeset(data, lookupValidator(validators), validators, { changeset: Changeset }); }; /** diff --git a/ui/packages/consul-ui/app/validations/nspace.js b/ui/packages/consul-ui/app/validations/nspace.js deleted file mode 100644 index 56a6ff554..000000000 --- a/ui/packages/consul-ui/app/validations/nspace.js +++ /dev/null @@ -1,4 +0,0 @@ -import { validateFormat } from 'ember-changeset-validations/validators'; -export default { - Name: validateFormat({ regex: /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?$/ }), -}; diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index 0634511c9..4bff448c2 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -28,7 +28,8 @@ module.exports = function(defaults, $ = process.env) { const apps = [ 'consul-acls', - 'consul-partitions' + 'consul-partitions', + 'consul-nspaces' ].map(item => { return { name: item, diff --git a/ui/packages/consul-ui/lib/startup/index.js b/ui/packages/consul-ui/lib/startup/index.js index 41dcd8990..5a2f6b534 100644 --- a/ui/packages/consul-ui/lib/startup/index.js +++ b/ui/packages/consul-ui/lib/startup/index.js @@ -54,6 +54,11 @@ module.exports = { environment: config.environment, rootURL: config.environment === 'production' ? '{{.ContentPath}}' : config.rootURL, config: config, + env: function(key) { + if (process.env[key]) { + return process.env[key]; + } + }, }; switch (type) { case 'head': diff --git a/ui/packages/consul-ui/lib/startup/templates/body.html.js b/ui/packages/consul-ui/lib/startup/templates/body.html.js index fe1a75f3c..cb9016821 100644 --- a/ui/packages/consul-ui/lib/startup/templates/body.html.js +++ b/ui/packages/consul-ui/lib/startup/templates/body.html.js @@ -15,7 +15,7 @@ const hbs = (path, attrs = {}) => const BrandLoader = attrs => hbs('brand-loader/index.hbs', attrs); const Enterprise = attrs => hbs('brand-loader/enterprise.hbs', attrs); -module.exports = ({ appName, environment, rootURL, config }) => ` +module.exports = ({ appName, environment, rootURL, config, env }) => `