Skip to content

Commit

Permalink
Only show guest roles in inviter
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 1, 2023
1 parent f3e36bd commit ed08bb1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
17 changes: 11 additions & 6 deletions client/src/components/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect, useRef, useState} from "react";
import "./User.scss";
import InputField from "./InputField";
import {dateFromEpoch} from "../utils/Date";
import {highestAuthority} from "../utils/UserRole";
import {AUTHORITIES, highestAuthority} from "../utils/UserRole";
import I18n from "../locale/I18n";
import Logo from "./Logo";
import {Card, CardType} from "@surfnet/sds";
Expand All @@ -11,8 +11,9 @@ import {deriveRemoteApplicationAttributes} from "../utils/Manage";
import {ReactComponent as SearchIcon} from "@surfnet/sds/icons/functional-icons/search.svg";
import {MoreLessText} from "./MoreLessText";
import {RoleCard} from "./RoleCard";
import DOMPurify from "dompurify";

export const User = ({user, other}) => {
export const User = ({user, other, config}) => {
const searchRef = useRef();

const [query, setQuery] = useState("");
Expand Down Expand Up @@ -104,18 +105,22 @@ export const User = ({user, other}) => {
user.highestAuthority = I18n.t(`access.${highestAuthority(user)}`);
const attributes = [["name"], ["sub"], ["eduPersonPrincipalName"], ["schacHomeOrganization"], ["email"], ["highestAuthority"],
["lastActivity", true]];
const filteredUserRoles = user.userRoles.filter(filterUserRole);
const filteredUserRoles = user.userRoles.filter(filterUserRole).filter(role => role.authority !== AUTHORITIES.GUEST);
const filteredApplications = (user.applications || []).filter(filterApplication);
const hasRoles = !isEmpty(user.userRoles.filter(role => role.authority !== AUTHORITIES.GUEST))
return (
<section className={"user"}>
{attributes.map((attr, index) => attribute(index, attr[0], attr[1]))}

<h3 className={"title span-row "}>{I18n.t("users.roles")}</h3>
{(isEmpty(user.userRoles) && user.superUser) &&
{highestAuthority(user) === AUTHORITIES.GUEST &&
<p className={"span-row"}
dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(I18n.t("users.guestRoleOnly", {welcomeUrl: config.welcomeUrl}))}}/>}
{(!hasRoles && user.superUser) &&
<p className={"span-row "}>{I18n.t("users.noRolesInfo")}</p>}
{(isEmpty(user.userRoles) && user.institutionAdmin) &&
{(!hasRoles && user.institutionAdmin) &&
<p className={"span-row "}>{I18n.t("users.noRolesInstitutionAdmin")}</p>}
{!isEmpty(user.userRoles) &&
{hasRoles &&
<>
<div className="roles-search span-row">
<p>
Expand Down
3 changes: 3 additions & 0 deletions client/src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const en = {
applications: "Applications",
noRolesInfo: "You have no roles (which means you must be super-user)",
noRolesInstitutionAdmin: "As an institution admin you have no roles (but you do have access to applications)",
guestRoleOnly: "You are a guest user. Are you looking for the <a href='{{welcomeUrl}}'>inviter app for guests</a>?",
rolesInfo: "You have the following roles",
applicationsInfo: "You have access to the following applications",
noRolesFound: "No roles are found.",
Expand Down Expand Up @@ -163,6 +164,8 @@ const en = {
multipleUserRoles: "user roles",
searchPlaceHolder: "Search for user roles...",
noResults: "No user roles where found",
guestRoles: "{{count}} guest users",
managerRoles: "{{count}} manager & inviter users",
notAllowed: "You're not allowed to delete this user role because of missing roles",
updateConfirmation: "Are you sure you want to change the end date of role {{roleName}} for {{userName}}",
updateConfirmationRemoveEndDate: "Are you sure you want to remove the end date of role {{roleName}} for {{userName}}",
Expand Down
3 changes: 3 additions & 0 deletions client/src/locale/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const nl = {
applications: "Applicaties",
noRolesInfo: "Je hebt geen rollen (je bent een super-user)",
noRolesInstitutionAdmin: "Als een instellingsmanager heb je geen rollen (maar je hebt wel toegang tot je applicaties)",
guestRoleOnly: "Je bent een gast gebruiker. Was je op zoek naar <a href='{{welcomeUrl}}'>de inviter app voor gasten</a>?",
rolesInfo: "Je hebt de volgende rollen",
applicationsInfo: "Je hebt toegang tot de volgende applicaties",
noRolesFound: "Geen rollen gevonden.",
Expand Down Expand Up @@ -163,6 +164,8 @@ const nl = {
multipleUserRoles: "gebruikersrollen",
searchPlaceHolder: "Zoek gebruikersrollen...",
noResults: "Geen gebruikersrollen gevonden",
guestRoles: "{{count}} gast gebruiker",
managerRoles: "{{count}} managers & uitnodigers",
notAllowed: "Je kunt deze gebruikersrol niet verwijderen vanwege ontbrekende rollen",
updateConfirmation: "Weet je zeker dat je de einddatum wilt aanpassen van rol {{roleName}} voor {{userName}}",
updateConfirmationRemoveEndDate: "Weet je zeker dat je de einddatum wilt verwijderen van rol {{roleName}} voor {{userName}}",
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {isEmpty} from "../utils/Utils";

export const Profile = () => {
const {id} = useParams();
const {user: currentUser} = useAppStore(state => state);
const {user: currentUser, config} = useAppStore(state => state);
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);

Expand Down Expand Up @@ -56,7 +56,7 @@ export const Profile = () => {
})}</p>
</UnitHeader>
<div className="profile-container">
<User user={user} other={!isEmpty(id)}/>
<User user={user} other={!isEmpty(id)} config={config}/>
</div>
</div>);
};
5 changes: 3 additions & 2 deletions client/src/tabs/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ export const Roles = () => {
}, [user]);// eslint-disable-line react-hooks/exhaustive-deps

const initFilterValues = res => {
const userRoles = res.filter(role => !(role.isUserRole && role.authority === "GUEST"));
const newFilterOptions = [{
label: I18n.t("invitations.statuses.all", {nbr: res.length}),
label: I18n.t("invitations.statuses.all", {nbr: userRoles.length}),
value: allValue
}];
const reducedRoles = res.reduce((acc, role) => {
const reducedRoles = userRoles.reduce((acc, role) => {
const option = acc.find(opt => opt.manageId === role.manageId);
if (option) {
++option.nbr;
Expand Down
2 changes: 1 addition & 1 deletion client/src/tabs/UserRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const UserRoles = ({role, guests, userRoles}) => {
newEntityFunc={() => navigate(`/invitation/new?maintainer=${guests === false}`, {state: role.id})}
customNoEntities={I18n.t(`userRoles.noResults`)}
loading={false}
hideTitle={true}
title={I18n.t(guests ? "userRoles.guestRoles" : "userRoles.managerRoles", {count: userRoles.length})}
actions={actionButtons()}
searchCallback={searchCallback}
searchAttributes={["name", "email", "schacHomeOrganization"]}
Expand Down

0 comments on commit ed08bb1

Please sign in to comment.