From 0232570831ef6c2596542f58c2326a80460cffd3 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 20 Aug 2021 14:58:43 -0400 Subject: [PATCH] feature(capabilities): preliminary user create/list abilities --- addons/api/addon/models/base.js | 5 +++ addons/api/mirage/factories/scope.js | 13 +++++++ ui/admin/app/routes/scopes/scope/users.js | 8 +++-- .../app/routes/scopes/scope/users/index.js | 12 ++++++- ui/admin/app/templates/scopes/scope.hbs | 12 ++++--- .../templates/scopes/scope/users/index.hbs | 35 ++++++++++++++----- 6 files changed, 68 insertions(+), 17 deletions(-) diff --git a/addons/api/addon/models/base.js b/addons/api/addon/models/base.js index f99e0351a..7fd41ec64 100644 --- a/addons/api/addon/models/base.js +++ b/addons/api/addon/models/base.js @@ -42,6 +42,11 @@ export default class BaseModel extends Model { }) authorized_actions; + @attr({ + readOnly: true, + }) + authorized_collection_actions; + set scopeModel(model) { if (model) { const json = model.serialize(); diff --git a/addons/api/mirage/factories/scope.js b/addons/api/mirage/factories/scope.js index fe41f3866..4ac77e576 100644 --- a/addons/api/mirage/factories/scope.js +++ b/addons/api/mirage/factories/scope.js @@ -4,6 +4,19 @@ import { trait } from 'ember-cli-mirage'; export default factory.extend({ type: 'global', + authorized_collection_actions: () => { + return { + users: ['create', ''], + // groups: ['create', 'list'], + // roles: ['create', 'list'], + // 'auth-methods': ['create', 'list'], + // sessopms: ['list'], + // targets: ['create', 'list'], + // 'host-catalogs': ['create', 'list'], + // 'credential-stores': ['create', 'list'], + }; + }, + /** * Generates realistic-ish IDs while still being deterministic. */ diff --git a/ui/admin/app/routes/scopes/scope/users.js b/ui/admin/app/routes/scopes/scope/users.js index 42f9c8832..aa3dde96a 100644 --- a/ui/admin/app/routes/scopes/scope/users.js +++ b/ui/admin/app/routes/scopes/scope/users.js @@ -11,6 +11,7 @@ export default class ScopesScopeUsersRoute extends Route { @service intl; @service notify; @service session; + @service can; // =methods @@ -26,8 +27,11 @@ export default class ScopesScopeUsersRoute extends Route { * @return {Promise{[UserModel]}} */ async model() { - const { id: scope_id } = this.modelFor('scopes.scope'); - return this.store.query('user', { scope_id }); + const scope = this.modelFor('scopes.scope'); + const { id: scope_id } = scope; + if (this.can.can('list collection', scope, { collection: 'users' })) { + return this.store.query('user', { scope_id }); + } } // =actions diff --git a/ui/admin/app/routes/scopes/scope/users/index.js b/ui/admin/app/routes/scopes/scope/users/index.js index f59170106..8d3bc89c6 100644 --- a/ui/admin/app/routes/scopes/scope/users/index.js +++ b/ui/admin/app/routes/scopes/scope/users/index.js @@ -1,3 +1,13 @@ import Route from '@ember/routing/route'; -export default class ScopesScopeUsersIndexRoute extends Route {} +export default class ScopesScopeUsersIndexRoute extends Route { + + // =methods + + setupController(controller) { + const scope = this.modelFor('scopes.scope'); + super.setupController(...arguments); + controller.setProperties({ scope }); + } + +} diff --git a/ui/admin/app/templates/scopes/scope.hbs b/ui/admin/app/templates/scopes/scope.hbs index 65e456c51..825be5d14 100644 --- a/ui/admin/app/templates/scopes/scope.hbs +++ b/ui/admin/app/templates/scopes/scope.hbs @@ -94,10 +94,12 @@ {{#unless @model.isProject}} - - - {{t 'resources.user.title_plural'}} - + {{#if (can 'navigate collection' @model collection='users')}} + + + {{t 'resources.user.title_plural'}} + + {{/if}} {{t 'resources.group.title_plural'}} @@ -140,4 +142,4 @@ - \ No newline at end of file + diff --git a/ui/admin/app/templates/scopes/scope/users/index.hbs b/ui/admin/app/templates/scopes/scope/users/index.hbs index ab31bc1cf..61d80197b 100644 --- a/ui/admin/app/templates/scopes/scope/users/index.hbs +++ b/ui/admin/app/templates/scopes/scope/users/index.hbs @@ -15,10 +15,12 @@ - {{#if @model}} - {{t - 'titles.new' - }} + {{#if (can 'create collection' this.scope collection='users')}} + {{#if @model}} + {{t + 'titles.new' + }} + {{/if}} {{/if}} @@ -69,11 +71,26 @@ > {{t 'resources.user.description'}} + {{#if (can 'create collection' this.scope collection='users')}} + {{#unless (can 'list collection' this.scope collection='users')}} +
+
+ + Oh noes! Resources you create won't appear here because you + have create permission, but not list. + + {{/unless}} + {{/if}}
- - - {{t 'titles.new'}} - + {{#if (can 'create collection' this.scope collection='users')}} + + + {{t 'titles.new'}} + + {{/if}} @@ -81,4 +98,4 @@ - \ No newline at end of file +