Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador Video
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador Video
Commits
5bc07298
Commit
5bc07298
authored
4 years ago
by
Chris Beer
Browse files
Options
Downloads
Patches
Plain Diff
Move canvas auth selectors into auth
parent
c8fdd86a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/containers/IIIFAuthentication.js
+3
-4
3 additions, 4 deletions
src/containers/IIIFAuthentication.js
src/state/selectors/auth.js
+75
-0
75 additions, 0 deletions
src/state/selectors/auth.js
src/state/selectors/canvases.js
+0
-58
0 additions, 58 deletions
src/state/selectors/canvases.js
with
78 additions
and
62 deletions
src/containers/IIIFAuthentication.js
+
3
−
4
View file @
5bc07298
...
...
@@ -7,6 +7,7 @@ import * as actions from '../state/actions';
import
{
getCurrentCanvas
,
getAuth
,
isInteractiveAuth
,
selectCanvasAuthService
,
getAccessTokens
,
}
from
'
../state/selectors
'
;
...
...
@@ -37,8 +38,6 @@ const mapStateToProps = (state, { windowId }) => {
e
=>
e
.
id
===
accessTokenService
.
id
,
);
const
profile
=
service
&&
service
.
getProfile
();
let
status
;
if
(
!
authStatus
)
{
...
...
@@ -57,7 +56,7 @@ const mapStateToProps = (state, { windowId }) => {
status
=
'
failed
'
;
}
const
isInteractive
=
profile
!==
'
http://iiif.io/api/auth/1/external
'
&&
profile
!==
'
http://iiif.io/api/auth/1/kiosk
'
;
const
isInteractive
=
isInteractiveAuth
(
state
,
{
canvasId
,
windowId
})
;
return
{
accessTokenServiceId
:
accessTokenService
&&
accessTokenService
.
id
,
...
...
@@ -70,7 +69,7 @@ const mapStateToProps = (state, { windowId }) => {
isInteractive
,
label
:
service
&&
service
.
getLabel
()[
0
].
value
,
logoutServiceId
:
logoutService
&&
logoutService
.
id
,
profile
,
profile
:
service
&&
service
.
getProfile
()
,
status
,
};
};
...
...
This diff is collapsed.
Click to expand it.
src/state/selectors/auth.js
+
75
−
0
View file @
5bc07298
import
{
createSelector
}
from
'
reselect
'
;
import
{
Utils
}
from
'
manifesto.js/dist-esmodule/Utils
'
;
import
MiradorCanvas
from
'
../../lib/MiradorCanvas
'
;
import
{
miradorSlice
}
from
'
./utils
'
;
import
{
getConfig
}
from
'
./config
'
;
import
{
selectInfoResponse
,
getCanvas
}
from
'
./canvases
'
;
/** */
export
const
getAccessTokens
=
state
=>
miradorSlice
(
state
).
accessTokens
||
{};
/** */
export
const
getAuth
=
state
=>
miradorSlice
(
state
).
auth
||
{};
export
const
selectCanvasAuthService
=
createSelector
(
[
selectInfoResponse
,
getCanvas
,
getConfig
,
getAuth
,
],
(
infoResponse
,
canvas
,
{
auth
:
{
serviceProfiles
=
[]
}
},
auth
)
=>
{
let
iiifResource
;
iiifResource
=
infoResponse
&&
infoResponse
.
json
&&
{
...
infoResponse
.
json
,
options
:
{}
};
if
(
!
iiifResource
&&
canvas
)
{
const
miradorCanvas
=
new
MiradorCanvas
(
canvas
);
const
[
image
]
=
miradorCanvas
.
iiifImageResources
;
iiifResource
=
image
&&
image
.
getServices
()[
0
];
}
if
(
!
iiifResource
)
return
undefined
;
const
orderedAuthServiceProfiles
=
serviceProfiles
.
map
(
p
=>
p
.
profile
);
let
lastAttemptedService
;
for
(
const
profile
of
orderedAuthServiceProfiles
)
{
const
services
=
getServices
(
iiifResource
,
profile
);
for
(
const
service
of
services
)
{
if
(
!
auth
[
service
.
id
])
return
service
;
lastAttemptedService
=
service
;
if
(
auth
[
service
.
id
].
isFetching
||
auth
[
service
.
id
].
ok
)
return
service
;
}
}
return
lastAttemptedService
;
},
);
/** */
export
function
selectAuthStatus
({
auth
},
service
)
{
if
(
!
service
)
return
null
;
if
(
!
auth
[
service
.
id
])
return
null
;
if
(
auth
[
service
.
id
].
isFetching
)
return
'
fetching
'
;
if
(
auth
[
service
.
id
].
ok
)
return
'
ok
'
;
return
'
failed
'
;
}
/** Get all the services that match a profile */
function
getServices
(
resource
,
profile
)
{
const
services
=
Utils
.
getServices
(
resource
);
return
services
.
filter
(
service
=>
service
.
getProfile
()
===
profile
);
}
/** check if the current auth service is "interactive" */
export
const
isInteractiveAuth
=
createSelector
(
[
selectCanvasAuthService
,
getConfig
,
],
(
service
,
{
auth
:
{
serviceProfiles
=
[]
}
})
=>
{
const
profile
=
service
&&
service
.
getProfile
();
return
serviceProfiles
.
some
(
config
=>
config
.
profile
===
profile
&&
!
(
config
.
external
||
config
.
kiosk
),
);
},
);
This diff is collapsed.
Click to expand it.
src/state/selectors/canvases.js
+
0
−
58
View file @
5bc07298
import
{
createSelector
}
from
'
reselect
'
;
import
{
Utils
}
from
'
manifesto.js/dist-esmodule/Utils
'
;
import
flatten
from
'
lodash/flatten
'
;
import
CanvasGroupings
from
'
../../lib/CanvasGroupings
'
;
import
MiradorCanvas
from
'
../../lib/MiradorCanvas
'
;
import
{
miradorSlice
}
from
'
./utils
'
;
import
{
getWindow
}
from
'
./getters
'
;
import
{
getConfig
}
from
'
./config
'
;
import
{
getAuth
}
from
'
./auth
'
;
import
{
getSequence
}
from
'
./sequences
'
;
import
{
getWindowViewType
}
from
'
./windows
'
;
...
...
@@ -208,58 +205,3 @@ export const selectInfoResponse = createSelector(
&&
infoResponses
[
iiifServiceId
];
},
);
export
const
selectCanvasAuthService
=
createSelector
(
[
selectInfoResponse
,
getCanvas
,
getConfig
,
getAuth
,
],
(
infoResponse
,
canvas
,
{
auth
:
{
serviceProfiles
=
[]
}
},
auth
)
=>
{
let
iiifResource
;
iiifResource
=
infoResponse
&&
infoResponse
.
json
&&
{
...
infoResponse
.
json
,
options
:
{}
};
if
(
!
iiifResource
&&
canvas
)
{
const
miradorCanvas
=
new
MiradorCanvas
(
canvas
);
const
[
image
]
=
miradorCanvas
.
iiifImageResources
;
iiifResource
=
image
&&
image
.
getServices
()[
0
];
}
if
(
!
iiifResource
)
return
undefined
;
const
orderedAuthServiceProfiles
=
serviceProfiles
.
map
(
p
=>
p
.
profile
);
let
lastAttemptedService
;
for
(
const
profile
of
orderedAuthServiceProfiles
)
{
const
services
=
getServices
(
iiifResource
,
profile
);
for
(
const
service
of
services
)
{
if
(
!
auth
[
service
.
id
])
return
service
;
lastAttemptedService
=
service
;
if
(
auth
[
service
.
id
].
isFetching
||
auth
[
service
.
id
].
ok
)
return
service
;
}
}
return
lastAttemptedService
;
},
);
/** */
export
function
selectAuthStatus
({
auth
},
service
)
{
if
(
!
service
)
return
null
;
if
(
!
auth
[
service
.
id
])
return
null
;
if
(
auth
[
service
.
id
].
isFetching
)
return
'
fetching
'
;
if
(
auth
[
service
.
id
].
ok
)
return
'
ok
'
;
return
'
failed
'
;
}
/** Get all the services that match a profile */
function
getServices
(
resource
,
profile
)
{
const
services
=
Utils
.
getServices
(
resource
);
return
services
.
filter
(
service
=>
service
.
getProfile
()
===
profile
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment