Skip to content

Commit

Permalink
Merge pull request #1719 from sul-dlss/simplify-restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Nov 10, 2023
2 parents 4388120 + b6d6c6f commit 5edbaa6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 0 additions & 2 deletions app/components/embed/media_tag_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def media_tag # rubocop:disable Metrics/MethodLength
data: {
src: streaming_url_for(:dash),
auth_url: authentication_url,
stanford_only: stanford_only?,
location_restricted: location_restricted?,
media_tag_target: 'mediaTag'
},
poster: poster_url_for,
Expand Down
11 changes: 3 additions & 8 deletions app/javascript/src/controllers/media_tag_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export default class extends Controller {

validateMedia(completeCallback) {
const validators = this.mediaTagTargets
.map((mediaTag) => {
const mediaContext = { isRestricted: mediaTag.dataset.stanfordOnly === "true" || mediaTag.dataset.locationRestricted === "true" }
return validator(mediaTag.dataset.authUrl, mediaTagTokenWriter(mediaTag), mediaContext)
})
.map((mediaTag) => validator(mediaTag.dataset.authUrl, mediaTagTokenWriter(mediaTag)))
Promise.all(validators).then((values) => {
values.forEach((result) => {
return this.afterValidate(result, completeCallback)})
Expand All @@ -32,10 +29,8 @@ export default class extends Controller {
afterValidate(result, completeCallback) {
if (result.authResponse.status === 'success') {
this.initializeVideoJSPlayer()
if (result.mediaContext.isRestricted) {
const event = new CustomEvent('auth-success')
window.dispatchEvent(event)
}
const event = new CustomEvent('auth-success')
window.dispatchEvent(event)
} else {
const event = new CustomEvent('auth-denied', { detail: result.authResponse })
window.dispatchEvent(event)
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/src/modules/validator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Calls the passed in URL to validate the user has permission to use an item
export default function(url, tokenWriter, mediaContext) {
export default function(url, tokenWriter) {
return new Promise((resolve, reject) => {
fetch(url, { credentials: 'include' })
.then((data) => data.json())
.then((authResponse) => {
tokenWriter(authResponse.token)
resolve({ authResponse, mediaContext })
resolve({ authResponse })
}).catch((error) => reject(error))
})
}

0 comments on commit 5edbaa6

Please sign in to comment.