Skip to content

Commit

Permalink
fix: permission description showing unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng authored and timopollmeier committed Dec 2, 2024
1 parent d2103cb commit 553eb90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/gmp/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
26 changes: 15 additions & 11 deletions src/web/pages/permissions/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React from 'react';

import Model from 'gmp/model';
Expand Down Expand Up @@ -157,6 +156,11 @@ const PermissionDialog = ({
userId,
};

const handleNameValueChange = onValueChange => (name, value) => {
onValueChange(name, value);
onValueChange(undefined, 'resourceType');
};

return (
<SaveDialog
title={title}
Expand All @@ -168,17 +172,17 @@ const PermissionDialog = ({
const showResourceId = NEED_RESOURCE_ID.includes(state.name);

const [type] = split(name, '_', 1);

const resourceNameOrId = isDefined(state.resourceName)
? state.resourceName
: state.resourceId;
const resourceTypeOrType = isDefined(state.resourceType)
? state.resourceType
: type;

const resource = isDefined(state.resourceType)
? Model.fromElement(
{
name: isDefined(state.resourceName)
? state.resourceName
: state.resourceId,
},
isDefined(state.resourceType) ? state.resourceType : type,
)
? Model.fromElement({name: resourceNameOrId}, resourceTypeOrType)
: undefined;

let subject;
if (state.subjectType === 'user') {
subject = users.find(user => user.id === state.userId);
Expand Down Expand Up @@ -207,7 +211,7 @@ const PermissionDialog = ({
name="name"
value={state.name}
items={permItems}
onChange={onValueChange}
onChange={handleNameValueChange(onValueChange)}
/>
</FormGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/web/utils/render.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 553eb90

Please sign in to comment.