From 2c8ff79d369494d6f7c1105f6f3d20e1ee79d7c8 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 27 Oct 2020 16:50:10 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20scopes=20index=20p?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/router.js | 1 + ui/core/app/routes/scopes/scope/index.js | 4 + ui/core/app/routes/scopes/scope/scopes.js | 39 ++++++++ .../app/routes/scopes/scope/scopes/index.js | 4 + ui/core/app/templates/scopes/scope.hbs | 10 +-- ui/core/app/templates/scopes/scope/scopes.hbs | 18 ++++ .../templates/scopes/scope/scopes/index.hbs | 90 +++++++++++++++++++ .../tests/acceptance/authentication-test.js | 4 +- ui/core/tests/acceptance/scopes-test.js | 10 +-- .../unit/routes/scopes/scope/scopes-test.js | 11 +++ .../routes/scopes/scope/scopes/index-test.js | 11 +++ 11 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 ui/core/app/routes/scopes/scope/scopes.js create mode 100644 ui/core/app/routes/scopes/scope/scopes/index.js create mode 100644 ui/core/app/templates/scopes/scope/scopes.hbs create mode 100644 ui/core/app/templates/scopes/scope/scopes/index.hbs create mode 100644 ui/core/tests/unit/routes/scopes/scope/scopes-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/scopes/index-test.js diff --git a/ui/core/app/router.js b/ui/core/app/router.js index 88358232c..df0228147 100644 --- a/ui/core/app/router.js +++ b/ui/core/app/router.js @@ -53,6 +53,7 @@ Router.map(function () { }); this.route('new'); }); + this.route('scopes', function() {}); }); }); diff --git a/ui/core/app/routes/scopes/scope/index.js b/ui/core/app/routes/scopes/scope/index.js index 796253603..958b958ec 100644 --- a/ui/core/app/routes/scopes/scope/index.js +++ b/ui/core/app/routes/scopes/scope/index.js @@ -10,10 +10,14 @@ export default class ScopesScopeIndexRoute extends Route { /** * Redirects to scopes/scope/authenticate for further processing. + * If already authenticated, redirects to scopes/scope/scopes to display + * list of sub scopes. */ redirect() { if (!this.session.isAuthenticated) { this.transitionTo('scopes.scope.authenticate'); + } else { + this.transitionTo('scopes.scope.scopes'); } } } diff --git a/ui/core/app/routes/scopes/scope/scopes.js b/ui/core/app/routes/scopes/scope/scopes.js new file mode 100644 index 000000000..520215dcd --- /dev/null +++ b/ui/core/app/routes/scopes/scope/scopes.js @@ -0,0 +1,39 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeScopesRoute extends Route { + // =services + + @service session; + + // =methods + + /** + * Redirects to scopes/scope/authenticate if unauthenticated. + */ + beforeModel() { + if (!this.session.isAuthenticated) { + this.transitionTo('scopes.scope.authenticate'); + } + } + + /** + * Loads sub scopes for the current scope. + * @param {object} params + * @param {string} params.scope_id + * @return {Promise{ScopeModel}} + */ + async model() { + const currentScope = this.modelFor('scopes.scope'); + const parentScope = !currentScope.isGlobal + ? await this.store.findRecord('scope', currentScope.scopeID) + : null; + const subScopes = + await this.store.query('scope', { scope_id: currentScope.id }); + return { + currentScope, + parentScope, + subScopes + }; + } +} diff --git a/ui/core/app/routes/scopes/scope/scopes/index.js b/ui/core/app/routes/scopes/scope/scopes/index.js new file mode 100644 index 000000000..4c30c0049 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/scopes/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeScopesIndexRoute extends Route { +} diff --git a/ui/core/app/templates/scopes/scope.hbs b/ui/core/app/templates/scopes/scope.hbs index a490c2148..8ae14473a 100644 --- a/ui/core/app/templates/scopes/scope.hbs +++ b/ui/core/app/templates/scopes/scope.hbs @@ -5,7 +5,7 @@ {{#if @model.isGlobal}} - + @@ -17,14 +17,14 @@ {{#if @model.isOrg}} {{#if this.session.data.authenticated.isGlobal}} - + {{t "resources.org.title_plural"}} {{/if}} - + @@ -36,14 +36,14 @@ {{#if @model.isProject}} {{#if this.session.data.authenticated.isGlobal}} - + {{t "resources.org.title_plural"}} {{/if}} - + diff --git a/ui/core/app/templates/scopes/scope/scopes.hbs b/ui/core/app/templates/scopes/scope/scopes.hbs new file mode 100644 index 000000000..c1cefb761 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/scopes.hbs @@ -0,0 +1,18 @@ +{{#if @model.currentScope.isGlobal}} + {{title (t "resources.org.title_plural") }} +{{/if}} + +{{#if @model.currentScope.isOrg}} + {{title (t "resources.org.title_plural") }} + {{title @model.currentScope.displayName}} + {{title (t "resources.project.title_plural") }} +{{/if}} + +{{#if @model.currentScope.isProject}} + {{title (t "resources.org.title_plural") }} + {{title @model.parentScope.displayName}} + {{title (t "resources.project.title_plural") }} + {{title @model.currentScope.displayName}} +{{/if}} + +{{outlet}} diff --git a/ui/core/app/templates/scopes/scope/scopes/index.hbs b/ui/core/app/templates/scopes/scope/scopes/index.hbs new file mode 100644 index 000000000..ba21bb6b8 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/scopes/index.hbs @@ -0,0 +1,90 @@ + + + + + + + + {{#if @model.currentScope.isGlobal}} +

+ {{t "resources.org.title_plural"}} + +

+ {{#if @model.subScopes}} +

{{t "resources.org.description"}}

+ {{/if}} + {{/if}} + {{#if @model.currentScope.isOrg}} +

+ {{t "resources.project.title_plural"}} + +

+ {{#if @model.subScopes}} +

{{t "resources.project.description"}}

+ {{/if}} + {{/if}} +
+ + + {{#if @model.subScopes}} + + {{t 'titles.new'}} + + {{/if}} + + + + + {{#if @model.subScopes}} + + + {{#each @model.subScopes as |scope|}} + + {{/each}} + + + {{else}} + + {{#if @model.currentScope.isGlobal}} + + + + {{t 'resources.org.description'}} + + + + {{t 'titles.new'}} + + + + {{/if}} + + {{#if @model.currentScope.isOrg}} + + + + {{t 'resources.project.description'}} + + + + {{t 'titles.new'}} + + + + {{/if}} + + {{/if}} + + + +
diff --git a/ui/core/tests/acceptance/authentication-test.js b/ui/core/tests/acceptance/authentication-test.js index d6c23666f..d9d5c3a0e 100644 --- a/ui/core/tests/acceptance/authentication-test.js +++ b/ui/core/tests/acceptance/authentication-test.js @@ -72,8 +72,8 @@ module('Acceptance | authentication', function (hooks) { authMethodGlobalAuthenticateURL = `/scopes/global/authenticate/${globalAuthMethodID}`; authMethodAuthenticateURL = `/scopes/${orgScopeID}/authenticate/${authMethodID}`; changePasswordURL = `/account/change-password`; - orgsURL = `/scopes/global`; - projectsURL = `/scopes/${orgScopeID}`; + orgsURL = `/scopes/global/scopes`; + projectsURL = `/scopes/${orgScopeID}/scopes`; usersURL = `/scopes/${orgScopeID}/users`; groupsURL = `/scopes/${orgScopeID}/groups`; rolesURL = `/scopes/${orgScopeID}/roles`; diff --git a/ui/core/tests/acceptance/scopes-test.js b/ui/core/tests/acceptance/scopes-test.js index 2894c32c4..4473e2aee 100644 --- a/ui/core/tests/acceptance/scopes-test.js +++ b/ui/core/tests/acceptance/scopes-test.js @@ -51,11 +51,11 @@ module('Acceptance | scopes', function (hooks) { scope: { id: instances.scopes.org.id, type: 'org' }, }); // Generate route URLs for resources - urls.globalScope = `/scopes/global`; - urls.orgScope = `/scopes/${instances.scopes.org.id}`; - urls.org2Scope = `/scopes/${instances.scopes.org2.id}`; - urls.projectScope = `/scopes/${instances.scopes.project.id}`; - urls.project2Scope = `/scopes/${instances.scopes.project2.id}`; + urls.globalScope = `/scopes/global/scopes`; + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; + urls.org2Scope = `/scopes/${instances.scopes.org2.id}/scopes`; + urls.projectScope = `/scopes/${instances.scopes.project.id}/scopes`; + urls.project2Scope = `/scopes/${instances.scopes.project2.id}/scopes`; authenticateSession({}); }); diff --git a/ui/core/tests/unit/routes/scopes/scope/scopes-test.js b/ui/core/tests/unit/routes/scopes/scope/scopes-test.js new file mode 100644 index 000000000..7cb21ef85 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/scopes-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/scopes', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/scopes'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/scopes/index-test.js b/ui/core/tests/unit/routes/scopes/scope/scopes/index-test.js new file mode 100644 index 000000000..ca7e3fb91 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/scopes/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/scopes/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/scopes/index'); + assert.ok(route); + }); +});