Skip to content

Commit

Permalink
Add feedback for disabled/unauthorized users (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippluca authored Jan 19, 2024
2 parents 6836920 + 8d2d762 commit 94c1b3c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/client/public/locale/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"user": "",
"username": "",
"usersMap": "",
"userUnauthorized": "",
"validationErrorHeader": "",
"version": "",
"viewas": "",
Expand Down
1 change: 1 addition & 0 deletions src/client/public/locale/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"user": "Benutzer",
"username": "Benutzername",
"usersMap": "Karten für Benutzer",
"userUnauthorized": "Sie verfügen nicht über ausreichende Rechte, um die Applikation zu benutzen. Bitte melden Sie sich beim Administrator.",
"validationErrorHeader": "Validierungsfehler",
"version": "Version",
"viewas": "Ansicht als",
Expand Down
1 change: 1 addition & 0 deletions src/client/public/locale/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"user": "User",
"username": "Username",
"usersMap": "Maps for users",
"userUnauthorized": "You do not have sufficient privileges to use the application. Please contact the administrator.",
"validationErrorHeader": "Validation errors",
"version": "Version",
"viewas": "View as",
Expand Down
1 change: 1 addition & 0 deletions src/client/public/locale/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"user": "Utilisateur",
"username": "Nom d'utilisateur",
"usersMap": "Cartes pour les utilisateurs",
"userUnauthorized": "Vous n'avez pas les privilèges suffisants pour utiliser l'application. Veuillez contacter l'administrateur.",
"validationErrorHeader": "Erreurs de validation",
"version": "Version",
"viewas": "Aperçu en tant que",
Expand Down
1 change: 1 addition & 0 deletions src/client/public/locale/it/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"user": "Utente",
"username": "Nome utente",
"usersMap": "Mappe dell'utente",
"userUnauthorized": "Non si dispone dei privilegi sufficienti per utilizzare l'applicazione. Si prega di contattare l'amministratore.",
"validationErrorHeader": "Errori di convalida",
"version": "Versione",
"viewas": "Visualizza come",
Expand Down
1 change: 1 addition & 0 deletions src/client/src/api-lib/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function user() {
case "GET_CONNECTION_ERROR": {
let copy = {
...state,
error: action.error.response.status === 401 ? true : state.error,
fcnt: state.fcnt + 1,
isFetching: false,
rtime: new Date().getTime() - state.rtime,
Expand Down
46 changes: 33 additions & 13 deletions src/client/src/pages/settings/dataLoader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { Fragment } from "react";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import { withTranslation } from "react-i18next";
Expand All @@ -7,6 +7,7 @@ import Markdown from "markdown-to-jsx";
import TranslationKeys from "../../commons/translationKeys";

import { Button } from "semantic-ui-react";
import Alert from "@mui/material/Alert";

import {
loadDomains,
Expand Down Expand Up @@ -60,10 +61,14 @@ class DataLoader extends React.Component {
}

render() {
const { t } = this.props;
const isLoading =
!this.props.auth ||
this.props.auth.isLoading ||
this.props.user?.authentication;

const authorizationFailed =
this.props.user?.authentication && this.props.user.error;
return (
<div
style={{
Expand Down Expand Up @@ -151,38 +156,53 @@ class DataLoader extends React.Component {
}}>
Sign in
</div>
{isLoading ? (
{!(isLoading || authorizationFailed) ? (
<Button
disabled
color={"green"}
compact
loading
primary
content="Login"
fluid
onClick={() => {
this.props.auth.signinRedirect();
}}
size="small"
style={{
marginTop: "1.5em",
}}
data-cy="login-button"
/>
) : (
) : null}
{isLoading && !authorizationFailed ? (
<Button
disabled
color={"green"}
compact
primary
loading
content="Login"
fluid
onClick={() => {
this.props.auth.signinRedirect();
}}
size="small"
style={{
marginTop: "1.5em",
}}
data-cy="login-button"
/>
)}
) : null}
{authorizationFailed ? (
<>
<Alert severity="error">{t("userUnauthorized")}</Alert>
<Button
compact
fluid
color="red"
content="Logout"
onClick={() => this.props.auth.signoutRedirect()}
style={{
marginTop: "1em",
}}
/>
</>
) : null}
</div>
</div>

<div
style={{
display: "flex",
Expand Down

0 comments on commit 94c1b3c

Please sign in to comment.