Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ICAT
Datahub
Commits
efe9e1e3
Commit
efe9e1e3
authored
Aug 23, 2021
by
Marjolaine Bodin
Browse files
#522
wip switch affiliation
parent
81fc6aed
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/actions/login.js
View file @
efe9e1e3
...
...
@@ -31,6 +31,7 @@ export function doSignIn(plugin, username, password) {
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
}
=
data
;
dispatch
({
type
:
LOGGED_IN
,
...
...
@@ -40,6 +41,7 @@ export function doSignIn(plugin, username, password) {
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
});
})
.
catch
((
error
)
=>
{
...
...
@@ -69,6 +71,7 @@ export function doSilentRefreshFromSSO() {
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
}
=
data
;
dispatch
({
type
:
LOGGED_IN
,
...
...
@@ -78,6 +81,7 @@ export function doSilentRefreshFromSSO() {
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
});
})
.
catch
((
error
)
=>
{
...
...
@@ -86,3 +90,44 @@ export function doSilentRefreshFromSSO() {
});
};
}
export
function
switchAffiliation
(
name
)
{
return
(
dispatch
)
=>
{
axios
.
post
(
`
${
ICATPLUS
.
server
}
/session`
,
{
plugin
:
ICAT
.
authentication
.
sso
.
plugin
,
username
:
null
,
password
:
keycloak
.
idToken
,
smisPk
:
name
.
split
(
'
-
'
)[
1
],
})
.
then
(({
data
})
=>
{
if
(
!
data
||
!
data
.
sessionId
)
{
throw
new
Error
(
'
Invalid switch authentication response
'
);
}
const
{
sessionId
,
name
,
fullName
,
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
}
=
data
;
dispatch
({
type
:
LOGGED_IN
,
sessionId
,
name
,
fullName
,
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
});
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
dispatch
({
type
:
LOGIN_ERROR
,
error
:
'
Switch authentication failed
'
});
});
};
}
src/components/Menu/AffiliationMenu.js
0 → 100644
View file @
efe9e1e3
import
React
from
'
react
'
;
import
{
MenuItem
,
NavDropdown
}
from
'
react-bootstrap
'
;
import
{
useSelector
}
from
'
react-redux
'
;
import
{
dateFormatter
}
from
'
../Investigation/utils
'
;
import
{
switchAffiliation
}
from
'
../../actions/login
'
;
function
AffiliationMenu
()
{
const
{
affiliations
}
=
useSelector
((
state
)
=>
state
.
user
);
function
getAffiliationName
(
createTime
)
{
return
dateFormatter
(
createTime
,
'
DD/MM/YYYY
'
,
false
);
}
function
handleAffiliation
(
name
)
{
switchAffiliation
(
name
);
}
return
(
<>
{
affiliations
&&
affiliations
.
length
>
0
&&
(
<
NavDropdown
eventKey
=
"
switchAffiliation
"
title
=
"
Switch Affiliation
"
id
=
"
basic-nav-dropdown
"
>
{
affiliations
.
map
(({
name
,
createTime
})
=>
(
<
MenuItem
eventKey
=
{
name
}
onClick
=
{
handleAffiliation
(
name
)}
>
{
getAffiliationName
(
createTime
)}
<
/MenuItem
>
))}
<
/NavDropdown
>
)}
;
<
/
>
);
}
export
default
AffiliationMenu
;
src/components/Menu/Menu.js
View file @
efe9e1e3
...
...
@@ -11,6 +11,7 @@ import { useSelector, useDispatch } from 'react-redux';
import
{
doLogOut
}
from
'
../../actions/login
'
;
import
styles
from
'
./Menu.module.css
'
;
import
LoadingBoundary
from
'
../LoadingBoundary
'
;
import
AffiliationMenu
from
'
./AffiliationMenu
'
;
function
Menu
()
{
const
user
=
useSelector
((
state
)
=>
state
.
user
);
...
...
@@ -142,6 +143,7 @@ function Menu() {
<
/Nav
>
<
Nav
pullRight
>
<
AffiliationMenu
><
/AffiliationMenu
>
<
NavItem
eventKey
=
"
logout
"
onClick
=
{
handleLogout
}
>
<
Glyphicon
glyph
=
"
log-out
"
style
=
{{
marginRight
:
'
1rem
'
}}
/
>
Log
out
<
strong
>
{
fullName
}
<
/strong
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment