Skip to content

Convert SelectProposal to function component and other fixes #1496

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

Merged
merged 5 commits into from
Nov 25, 2024
Merged
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
16 changes: 8 additions & 8 deletions docs/source/dev/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ and authentication has to be delegated to a process dedicated to authentication.
The authorization for a user to use a beamline is performed via the user portal
or LIMS system.

### Authentication with single sign on
### Authentication with single sign-on

MXCUBE can be configured to use Single sign-on (SSO) through OpenIDConnect for
MXCUBE can be configured to use single sign-on (SSO) through OpenIDConnect for
user authentication. The OpenIDConnect configuration is located in the
`server.yaml` file, which should contain an `sso` section like the one below.
`server.yaml` file, which should contain an `sso` section like the one below:

```
sso:
USE_SSO: false # True to use SSO false otherwise
USE_SSO: false # `true` to use SSO
ISSUER: https://websso.[site].[com]/realms/[site]/ # OpenIDConnect issuer URI
LOGOUT_URI: "" # OpenIDConnect logout URI
TOKEN_INFO_URI: "" # OpenIDConnect token info URI
CLIENT_SECRET: ASECRETKEY # OpenIDConnect client secret
CLIENT_ID: mxcube # OpenIDConnect client ID
SCOPE: openid email profile # OpenIDConnect defualt scopes, none scope is actually beeing used
SCOPE: openid email profile # OpenIDConnect default scopes, none scope is actually being used
CODE_CHALLANGE_METHOD: S256 # OpenIDConnect challange method
```

User authorization is delegated to the LIMS client inheriting `AbstractLims` and is performed in the `login` method.

## HTTP Session management
## HTTP session management

MXCuBE web sessions are meant to expire when there is no activity
MXCuBE web sessions are meant to expire when there is no activity.

For this purpose:

- Flask configuration setting `PERMANENT_SESSION_LIFETIME` is set
to the preferred value (seconds).

- Flask configuration setting `SESSION_REFRESH_EACH_REQUEST` is set,
- Flask configuration setting `SESSION_REFRESH_EACH_REQUEST` is enabled,
which is the default anyway.

- Flask session setting `session.permanent` is set
Expand Down
27 changes: 8 additions & 19 deletions ui/src/actions/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,18 @@ export function hideProposalsForm() {
};
}

export function selectProposalAction(prop) {
return {
type: 'SELECT_PROPOSAL',
proposal: prop,
};
}
Comment on lines -57 to -62
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used


export function setInitialState(data) {
return { type: 'SET_INITIAL_STATE', data };
}

export function selectProposal(number, navigate) {
export function selectProposal(number) {
return async (dispatch) => {
try {
await sendSelectProposal(number);
navigate('/');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to navigate after selecting a proposal. The redirect to /login actually had no effect since the user was redirected right away to /datacollection.

dispatch(hideProposalsForm());
dispatch(getLoginInfo());
} catch {
dispatch(showErrorPanel(true, 'Server refused to select proposal'));
navigate('/login');
}
};
}
Expand Down Expand Up @@ -108,16 +99,14 @@ export function ssoLogIn() {

export function signOut() {
return async (dispatch) => {
dispatch(resetLoginInfo()); // disconnect sockets before actually logging out (cf. `App.jsx`)
dispatch(applicationFetched(false));
// We make sure that user data is reseted so that websockets
// are keept dicconnected while logging out.
dispatch(resetLoginInfo());
await sendSignOut().finally(() =>
dispatch(
// Retreiving the user data from the backend
getLoginInfo(),
),
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, ok :)

try {
await sendSignOut();
} finally {
dispatch(getLoginInfo());
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/actions/remoteAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getLoginInfo } from './login';
import { showWaitDialog } from './waitDialog';

export function getRaState() {
return async (dispatch, getState) => {
return async (dispatch) => {
const data = await fetchRemoteAccessState();
dispatch({ type: 'SET_RA_STATE', data: data.data });
};
Expand Down
38 changes: 38 additions & 0 deletions ui/src/components/LoginForm/ActionButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { Button } from 'react-bootstrap';

function ActionButton(props) {
const { selectedSession, onClick } = props;

if (!selectedSession) {
return (
<Button variant="primary" disabled data-default-styles>
Select Proposal
</Button>
);
}

if (!selectedSession.is_scheduled_beamline) {
return (
<Button variant="danger" data-default-styles onClick={onClick}>
Move here
</Button>
);
}

if (!selectedSession.is_scheduled_time) {
return (
<Button variant="warning" data-default-styles onClick={onClick}>
Reschedule
</Button>
);
}

return (
<Button variant="primary" data-default-styles onClick={onClick}>
Select {selectedSession.code}-{selectedSession.number}
</Button>
);
}

export default ActionButton;
Loading
Loading