Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added message to people without permissions #137

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions public/components/Callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ function Callback() {

const checkSuccess = useCallback(() => {
if (
(permissions || process.env.PERMISSIONS_DISABLED === "true") &&
(permissions.length > 0 || process.env.PERMISSIONS_DISABLED === "true") &&
Object.hasOwn(localStorage, "token")
) {
setInfoMessage(
"Everything is loaded, you should be sent to the homepage in a second.",
);
window.location.replace("/");
return true;
} else if (permissions.length === 0) {
setInfoMessage(
"You don't seem to have any permissions within this application. Please check with an admin if this is correct.",
);
}
return false;
}, [permissions]);
Expand All @@ -36,9 +40,16 @@ function Callback() {
} else {
getData(`${process.env.API_URL}/api/v1.0/auth/permissions`, token)
.then((data) => {
putPermissions(data);
setInfoMessage("You're logged in.");
window.location.replace("/");
if (data.length > 0) {
putPermissions(data);
setInfoMessage("You're logged in.");
window.location.replace("/");
} else {
putPermissions(data);
YotaYota marked this conversation as resolved.
Show resolved Hide resolved
setInfoMessage(
"You don't seem to have any permissions within this application. Please check with an admin if this is correct.",
);
}
})
.catch((e) => {
setInfoMessage(
Expand Down
24 changes: 24 additions & 0 deletions public/components/Callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,28 @@ describe("Callback Component", () => {
screen.getByText("Something went wrong. Retry the login."),
).toBeInTheDocument();
});

test("displays no permissions message when user has no permissions", async () => {
getData.mockResolvedValueOnce([]);

render(<Callback />);

await waitFor(() => {
expect(
screen.getByText(
"You don't seem to have any permissions within this application. Please check with an admin if this is correct.",
),
).toBeInTheDocument();
});

await waitFor(() => {
expect(mockPutToken).toHaveBeenCalledWith("some-valid-token");
});
await waitFor(() => {
expect(mockSetUsername).toHaveBeenCalledWith("testuser");
});
await waitFor(() => {
expect(mockPutPermissions).toHaveBeenCalledWith([]);
});
});
});