From 553eb9047cea455aa12576425a899e4469d3c731 Mon Sep 17 00:00:00 2001 From: daniele-mng Date: Fri, 22 Nov 2024 11:43:23 +0100 Subject: [PATCH] fix: permission description showing unknown --- src/gmp/model.js | 4 ++-- src/web/pages/permissions/dialog.jsx | 26 +++++++++++++++----------- src/web/utils/render.jsx | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/gmp/model.js b/src/gmp/model.js index caf0594b8b..8c7c93cf4c 100644 --- a/src/gmp/model.js +++ b/src/gmp/model.js @@ -45,8 +45,8 @@ class Model { }, {}); } - static fromElement(element = {}) { - const f = new this(); + static fromElement(element = {}, type) { + const f = new this(type); f.setProperties(this.parseElement(element)); return f; } diff --git a/src/web/pages/permissions/dialog.jsx b/src/web/pages/permissions/dialog.jsx index 124a172b3c..7b514ada28 100644 --- a/src/web/pages/permissions/dialog.jsx +++ b/src/web/pages/permissions/dialog.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import Model from 'gmp/model'; @@ -157,6 +156,11 @@ const PermissionDialog = ({ userId, }; + const handleNameValueChange = onValueChange => (name, value) => { + onValueChange(name, value); + onValueChange(undefined, 'resourceType'); + }; + return ( user.id === state.userId); @@ -207,7 +211,7 @@ const PermissionDialog = ({ name="name" value={state.name} items={permItems} - onChange={onValueChange} + onChange={handleNameValueChange(onValueChange)} /> diff --git a/src/web/utils/render.jsx b/src/web/utils/render.jsx index 6abb0ec7fa..ab84cd1c89 100644 --- a/src/web/utils/render.jsx +++ b/src/web/utils/render.jsx @@ -206,7 +206,7 @@ export const permissionDescriptionResource = (name, resource) => { if (isDefined(resource)) { name = name.toLowerCase(); const resourceType = { - type: typeName(getEntityType(resource)), + type: typeName(getEntityType(resource))?.toLowerCase(), name: resource.name, };