Remove user_only roles from User and Team permission modal

This commit is contained in:
Marliana Lara 2022-03-03 13:00:42 -05:00
parent 0eac63b844
commit a155f5561f
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE

View File

@ -1,6 +1,6 @@
import React, { useState, useCallback } from 'react';
import { t } from '@lingui/macro';
import { useParams } from 'react-router-dom';
import { useParams, useRouteMatch } from 'react-router-dom';
import styled from 'styled-components';
import useRequest from 'hooks/useRequest';
import useSelected from 'hooks/useSelected';
@ -27,6 +27,11 @@ function UserAndTeamAccessAdd({
const [selectedResourceType, setSelectedResourceType] = useState(null);
const [stepIdReached, setStepIdReached] = useState(1);
const { id: userId } = useParams();
const teamsRouteMatch = useRouteMatch({
path: '/teams/:id/roles',
exact: true,
});
const { selected: resourcesSelected, handleSelect: handleResourceSelect } =
useSelected([]);
@ -54,6 +59,19 @@ function UserAndTeamAccessAdd({
{}
);
// Object roles can be user only, so we remove them when
// showing role choices for team access
const selectableRoles = {
...resourcesSelected[0]?.summary_fields?.object_roles,
};
if (teamsRouteMatch && resourcesSelected[0]?.type === 'organization') {
Object.keys(selectableRoles).forEach((key) => {
if (selectableRoles[key].user_only) {
delete selectableRoles[key];
}
});
}
const steps = [
{
id: 1,
@ -101,7 +119,7 @@ function UserAndTeamAccessAdd({
component: resourcesSelected?.length > 0 && (
<SelectRoleStep
onRolesClick={handleRoleSelect}
roles={resourcesSelected[0].summary_fields.object_roles}
roles={selectableRoles}
selectedListKey={
selectedResourceType === 'users' ? 'username' : 'name'
}