Skip to content

Commit

Permalink
Fixes #336
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 13, 2024
1 parent aac0258 commit 166878d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
4 changes: 2 additions & 2 deletions client/src/__tests__/utils/UserRole.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ test("Allowed to delete Invitation", () => {
role: {id: "2", applicationUsages: applicationUsagesForManageId("11")}
};
const user = {userRoles: [mail, research]}
const invitation = {intendedAuthority: AUTHORITIES.GUEST, roles: [mail, research]};
const invitation = {intended_authority: AUTHORITIES.GUEST, roles: [mail, research]};
expect(allowedToDeleteInvitation(user, invitation)).toBeTruthy();

invitation.intendedAuthority = AUTHORITIES.INVITER;
invitation.intended_authority = AUTHORITIES.INVITER;
expect(allowedToDeleteInvitation(user, invitation)).toBeFalsy();
});

Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/System.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const System = () => {
name="invitations"
label={I18n.t("tabs.invitations")}
>
<Invitations standAlone={true} systemView={true}/>
<Invitations systemView={true}/>
</Page>,
<Page key="unknownRoles"
name="unknownRoles"
Expand Down
39 changes: 15 additions & 24 deletions client/src/tabs/Invitations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import ConfirmationDialog from "../components/ConfirmationDialog";
import {useAppStore} from "../stores/AppStore";
import {isEmpty, pseudoGuid} from "../utils/Utils";
import {allowedToDeleteInvitation, AUTHORITIES, INVITATION_STATUS, isUserAllowed} from "../utils/UserRole";
import {UnitHeader} from "../components/UnitHeader";
import {ReactComponent as TrashIcon} from "@surfnet/sds/icons/functional-icons/bin.svg";
import {ReactComponent as ResendIcon} from "@surfnet/sds/icons/functional-icons/go-to-other-website.svg";
import {defaultPagination, pageCount} from "../utils/Pagination";
Expand All @@ -22,10 +21,7 @@ import debounce from "lodash.debounce";

export const Invitations = ({
role,
standAlone = false,
systemView = false,
history = false,
pending = true
systemView = false
}) => {
const navigate = useNavigate();
const {user, setFlash} = useAppStore(state => state);
Expand All @@ -38,17 +34,6 @@ export const Invitations = ({
const [confirmation, setConfirmation] = useState({});
const [confirmationOpen, setConfirmationOpen] = useState(false);

useEffect(() => {
if (history) {
useAppStore.setState({
breadcrumbPath: [
{path: "/inviter", value: I18n.t("tabs.home")},
{value: I18n.t("tabs.invitations")}
]
});
}
}, [history])

useEffect(() => {
searchInvitations(systemView ? null : role.id, paginationQueryParams)
.then(page => {
Expand All @@ -59,6 +44,16 @@ export const Invitations = ({
.map(role => role.name).join(", ");
const now = new Date();
invitation.status = new Date(invitation.expiryDate * 1000) < now ? INVITATION_STATUS.EXPIRED : invitation.status;
//We don't get the invitation.user_roles.role.applicationUsages from the server anymore due to custom pagination queries
(invitation.roles || []).forEach(invitationRole => {
invitationRole.role = {
id: invitationRole.id,
applicationUsages: invitationRole.manageIdentifiers.map(mi => ({application: {manageId: mi}})),
user_id: invitationRole.user_id,
authority: invitationRole.intended_authority
}
});

});
setInvitations(content);
setSelectedInvitations(content
Expand Down Expand Up @@ -141,8 +136,7 @@ export const Invitations = ({
.then(() => {
setConfirmationOpen(false);
setFlash(I18n.t("invitations.resendFlash"));
const path = encodeURIComponent(window.location.pathname);
navigate(`/refresh-route/${path}`, {replace: true});
setPaginationQueryParams({...paginationQueryParams});
})
}
};
Expand Down Expand Up @@ -180,8 +174,7 @@ export const Invitations = ({
.then(() => {
setConfirmationOpen(false);
setFlash(I18n.t("invitations.deleteFlash"));
const path = encodeURIComponent(window.location.pathname);
navigate(`/refresh-route/${path}`, {replace: true});
setPaginationQueryParams({...paginationQueryParams});
})
}
};
Expand All @@ -200,8 +193,7 @@ export const Invitations = ({
.then(() => {
setConfirmationOpen(false);
setFlash(I18n.t("invitations.deleteFlash"));
const path = encodeURIComponent(window.location.pathname);
navigate(`/refresh-route/${path}`, {replace: true});
setPaginationQueryParams({...paginationQueryParams});
})
}
};
Expand Down Expand Up @@ -338,13 +330,12 @@ export const Invitations = ({
confirm={confirmation.action}
confirmationTxt={confirmation.confirmationTxt}
question={confirmation.question}/>}
{history && <UnitHeader obj={{name: I18n.t("inviter.history")}} actions={getActions()}/>}
<Entities entities={invitations}
modelName="invitations"
defaultSort="email"
columns={columns}
newLabel={I18n.t("invitations.newInvite")}
showNew={!!role && (isUserAllowed(AUTHORITIES.MANAGER, user) || standAlone) && !role.unknownInManage}
showNew={!!role && isUserAllowed(AUTHORITIES.MANAGER, user) && !role.unknownInManage}
newEntityFunc={role ? () => navigate("/invitation/new", {state: role.id}) : null}
customNoEntities={I18n.t(`invitations.noResults`)}
loading={false}
Expand Down
5 changes: 3 additions & 2 deletions client/src/tabs/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useAppStore} from "../stores/AppStore";
import React, {useEffect, useState} from "react";
import {Entities} from "../components/Entities";
import I18n from "../locale/I18n";
import {Button, ButtonSize, Chip, Loader, Tooltip} from "@surfnet/sds";
import {Button, ButtonSize, Chip, Tooltip} from "@surfnet/sds";
import {useNavigate} from "react-router-dom";
import {AUTHORITIES, highestAuthority, isUserAllowed, markAndFilterRoles} from "../utils/UserRole";
import {rolesByApplication} from "../api";
Expand Down Expand Up @@ -140,7 +140,8 @@ export const Roles = () => {
const authority = authorityForRole(user, role);
const label = authority ? I18n.t(`access.${authority}`) : I18n.t("roles.noMember");
return <Chip type={chipTypeForUserRole(authority)}
label={label}/>}
label={label}/>
}
},
{
key: "userRoleCount",
Expand Down
7 changes: 1 addition & 6 deletions client/src/tabs/UserRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ export const UserRoles = ({role, guests}) => {
})
}, 375);

// if (loading) {
// return <Loader/>
// }

const showCheckAllHeader = () => {
return Object.entries(selectedUserRoles)
.filter(entry => entry[1].allowed)
Expand All @@ -104,8 +100,7 @@ export const UserRoles = ({role, guests}) => {
.then(() => {
setConfirmationOpen(false);
setFlash(I18n.t("userRoles.updateFlash", {roleName: userRole.role.name}));
const path = encodeURIComponent(window.location.pathname);
navigate(`/refresh-route/${path}`, {replace: true});
setPaginationQueryParams({...paginationQueryParams});
})
}
};
Expand Down
8 changes: 4 additions & 4 deletions client/src/tabs/UserRoles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
}

&.name {
width: 22%;
width: 24%;
}

&.me {
width: 8%;
}

&.schac_home_organization {
width: 14%;
width: 16%;
}

&.authority {
Expand All @@ -42,11 +42,11 @@
}

&.endDate {
width: 22%;
width: 20%;
}

&.createdAt {
width: 14%;
width: 12%;
}

&.adminIcons {
Expand Down

0 comments on commit 166878d

Please sign in to comment.