From 2404ef48996bfe7d2eba57e617e373b3a6bc5f6e Mon Sep 17 00:00:00 2001
From: Nick Muerdter <12112+GUI@users.noreply.github.com>
Date: Tue, 23 Jan 2024 14:15:15 -0700
Subject: [PATCH] More work on read-only views for admin_view permissions.
---
.../components/admin-groups/record-form.js | 15 +-
.../app/components/admins/record-form.js | 7 +-
.../app/components/api-scopes/record-form.js | 7 +-
.../app/components/api-users/record-form.js | 9 +-
.../app/controllers/admin-groups/index.js | 10 ++
.../admin-ui/app/controllers/admins/index.js | 10 ++
.../app/controllers/api-scopes/index.js | 10 ++
.../app/templates/admin-groups/index.hbs | 8 +-
.../admin-ui/app/templates/admins/index.hbs | 8 +-
.../app/templates/api-scopes/index.hbs | 8 +-
.../components/admin-groups/record-form.hbs | 16 +-
.../components/admins/record-form.hbs | 4 +-
.../components/api-scopes/record-form.hbs | 16 +-
src/api-umbrella/web-app/models/admin.lua | 8 +-
.../v1/admin_groups/test_admin_permissions.rb | 10 +-
test/apis/v1/admins/test_admin_permissions.rb | 37 +++-
.../v1/api_scopes/test_admin_permissions.rb | 10 +-
test/apis/v1/users/test_admin_permissions.rb | 161 ++++++++++++++++++
test/apis/v1/users/test_permissions.rb | 8 -
.../admin_permissions.rb | 45 ++++-
20 files changed, 346 insertions(+), 61 deletions(-)
create mode 100644 src/api-umbrella/admin-ui/app/controllers/admin-groups/index.js
create mode 100644 src/api-umbrella/admin-ui/app/controllers/admins/index.js
create mode 100644 src/api-umbrella/admin-ui/app/controllers/api-scopes/index.js
create mode 100644 test/apis/v1/users/test_admin_permissions.rb
diff --git a/src/api-umbrella/admin-ui/app/components/admin-groups/record-form.js b/src/api-umbrella/admin-ui/app/components/admin-groups/record-form.js
index 45185e0ab..ae058d592 100644
--- a/src/api-umbrella/admin-ui/app/components/admin-groups/record-form.js
+++ b/src/api-umbrella/admin-ui/app/components/admin-groups/record-form.js
@@ -1,6 +1,8 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
-import { action } from '@ember/object';
+import { action, computed } from '@ember/object';
+import { reads } from '@ember/object/computed';
+import { inject } from '@ember/service';
import { tagName } from '@ember-decorators/component';
// eslint-disable-next-line ember/no-mixins
import Save from 'api-umbrella-admin-ui/mixins/save';
@@ -10,6 +12,17 @@ import escape from 'lodash-es/escape';
@classic
@tagName("")
export default class RecordForm extends Component.extend(Save) {
+ @inject()
+ session;
+
+ @reads('session.data.authenticated.admin')
+ currentAdmin;
+
+ @computed('currentAdmin.permissions.admin_manage')
+ get isDisabled() {
+ return !this.currentAdmin.permissions.admin_manage;
+ }
+
@action
submitForm(event) {
event.preventDefault();
diff --git a/src/api-umbrella/admin-ui/app/components/admins/record-form.js b/src/api-umbrella/admin-ui/app/components/admins/record-form.js
index 1709b939d..b1f5d5b21 100644
--- a/src/api-umbrella/admin-ui/app/components/admins/record-form.js
+++ b/src/api-umbrella/admin-ui/app/components/admins/record-form.js
@@ -1,6 +1,6 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
-import { action } from '@ember/object';
+import { action, computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import { inject } from '@ember/service';
import { tagName } from '@ember-decorators/component';
@@ -20,6 +20,11 @@ export default class RecordForm extends Component.extend(Save) {
@reads('session.data.authenticated.admin')
currentAdmin;
+ @computed('currentAdmin.permissions.admin_manage')
+ get isDisabled() {
+ return !this.currentAdmin.permissions.admin_manage;
+ }
+
get usernameLabel() {
return usernameLabel();
}
diff --git a/src/api-umbrella/admin-ui/app/components/api-scopes/record-form.js b/src/api-umbrella/admin-ui/app/components/api-scopes/record-form.js
index bdbf3f107..0f147ef0b 100644
--- a/src/api-umbrella/admin-ui/app/components/api-scopes/record-form.js
+++ b/src/api-umbrella/admin-ui/app/components/api-scopes/record-form.js
@@ -1,6 +1,6 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
-import { action } from '@ember/object';
+import { action, computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import { inject } from '@ember/service';
import { tagName } from '@ember-decorators/component';
@@ -18,6 +18,11 @@ export default class RecordForm extends Component.extend(Save) {
@reads('session.data.authenticated.admin')
currentAdmin;
+ @computed('currentAdmin.permissions.admin_manage')
+ get isDisabled() {
+ return !this.currentAdmin.permissions.admin_manage;
+ }
+
@action
submitForm(event) {
event.preventDefault();
diff --git a/src/api-umbrella/admin-ui/app/components/api-users/record-form.js b/src/api-umbrella/admin-ui/app/components/api-users/record-form.js
index f49b63149..b11ad81dc 100644
--- a/src/api-umbrella/admin-ui/app/components/api-users/record-form.js
+++ b/src/api-umbrella/admin-ui/app/components/api-users/record-form.js
@@ -1,6 +1,7 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
import { action, computed } from '@ember/object';
+import { reads } from '@ember/object/computed';
import { inject } from '@ember/service';
// eslint-disable-next-line ember/no-mixins
import Save from 'api-umbrella-admin-ui/mixins/save';
@@ -24,10 +25,12 @@ export default class RecordForm extends Component.extend(Save) {
{ id: false, name: 'Disabled' },
];
- @computed('session.data.authenticated.admin')
+ @reads('session.data.authenticated.admin')
+ currentAdmin;
+
+ @computed('currentAdmin.permissions.user_manage')
get isDisabled() {
- const currentAdmin = this.session.data.authenticated.admin;
- return !currentAdmin.permissions.user_manage;
+ return !this.currentAdmin.permissions.user_manage;
}
@action
diff --git a/src/api-umbrella/admin-ui/app/controllers/admin-groups/index.js b/src/api-umbrella/admin-ui/app/controllers/admin-groups/index.js
new file mode 100644
index 000000000..76a86edaa
--- /dev/null
+++ b/src/api-umbrella/admin-ui/app/controllers/admin-groups/index.js
@@ -0,0 +1,10 @@
+import Controller from '@ember/controller';
+import { inject as service } from '@ember/service';
+
+export default class IndexController extends Controller {
+ @service session;
+
+ get currentAdmin() {
+ return this.session.data.authenticated.admin;
+ }
+}
diff --git a/src/api-umbrella/admin-ui/app/controllers/admins/index.js b/src/api-umbrella/admin-ui/app/controllers/admins/index.js
new file mode 100644
index 000000000..76a86edaa
--- /dev/null
+++ b/src/api-umbrella/admin-ui/app/controllers/admins/index.js
@@ -0,0 +1,10 @@
+import Controller from '@ember/controller';
+import { inject as service } from '@ember/service';
+
+export default class IndexController extends Controller {
+ @service session;
+
+ get currentAdmin() {
+ return this.session.data.authenticated.admin;
+ }
+}
diff --git a/src/api-umbrella/admin-ui/app/controllers/api-scopes/index.js b/src/api-umbrella/admin-ui/app/controllers/api-scopes/index.js
new file mode 100644
index 000000000..76a86edaa
--- /dev/null
+++ b/src/api-umbrella/admin-ui/app/controllers/api-scopes/index.js
@@ -0,0 +1,10 @@
+import Controller from '@ember/controller';
+import { inject as service } from '@ember/service';
+
+export default class IndexController extends Controller {
+ @service session;
+
+ get currentAdmin() {
+ return this.session.data.authenticated.admin;
+ }
+}
diff --git a/src/api-umbrella/admin-ui/app/templates/admin-groups/index.hbs b/src/api-umbrella/admin-ui/app/templates/admin-groups/index.hbs
index c7a572ada..ccf4b99e7 100644
--- a/src/api-umbrella/admin-ui/app/templates/admin-groups/index.hbs
+++ b/src/api-umbrella/admin-ui/app/templates/admin-groups/index.hbs
@@ -1,7 +1,9 @@
Admin Groups
-
- Add New Admin Group
-
+{{#if this.currentAdmin.permissions.admin_manage}}
+
+ Add New Admin Group
+
+{{/if}}
diff --git a/src/api-umbrella/admin-ui/app/templates/admins/index.hbs b/src/api-umbrella/admin-ui/app/templates/admins/index.hbs
index cd0c7fcb6..7b7407048 100644
--- a/src/api-umbrella/admin-ui/app/templates/admins/index.hbs
+++ b/src/api-umbrella/admin-ui/app/templates/admins/index.hbs
@@ -1,7 +1,9 @@
Admins
-
- Add New Admin
-
+{{#if this.currentAdmin.permissions.admin_manage}}
+
+ Add New Admin
+
+{{/if}}
diff --git a/src/api-umbrella/admin-ui/app/templates/api-scopes/index.hbs b/src/api-umbrella/admin-ui/app/templates/api-scopes/index.hbs
index ea2be760d..a23cfd061 100644
--- a/src/api-umbrella/admin-ui/app/templates/api-scopes/index.hbs
+++ b/src/api-umbrella/admin-ui/app/templates/api-scopes/index.hbs
@@ -1,7 +1,9 @@
API Scopes
-
- Add New API Scope
-
+{{#if this.currentAdmin.permissions.admin_manage}}
+
+ Add New API Scope
+
+{{/if}}
diff --git a/src/api-umbrella/admin-ui/app/templates/components/admin-groups/record-form.hbs b/src/api-umbrella/admin-ui/app/templates/components/admin-groups/record-form.hbs
index ae5143af9..951b80f72 100644
--- a/src/api-umbrella/admin-ui/app/templates/components/admin-groups/record-form.hbs
+++ b/src/api-umbrella/admin-ui/app/templates/components/admin-groups/record-form.hbs
@@ -3,7 +3,7 @@
-
\ No newline at end of file
+
diff --git a/src/api-umbrella/admin-ui/app/templates/components/admins/record-form.hbs b/src/api-umbrella/admin-ui/app/templates/components/admins/record-form.hbs
index 9d1b93be9..b2e9f277e 100644
--- a/src/api-umbrella/admin-ui/app/templates/components/admins/record-form.hbs
+++ b/src/api-umbrella/admin-ui/app/templates/components/admins/record-form.hbs
@@ -54,8 +54,8 @@
{{/if}}
- {{#if this.currentAdmin.permissions.admin_manage}}
-