Skip to content
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

Fix profile annotator auth issue #255

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 26 additions & 19 deletions pages/user/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ export default {
async setup() {
const config = useRuntimeConfig()
const { $axios } = useNuxtApp()
const mainStore = useMainStore()
let downloadsSummary = 0

try {
Expand All @@ -345,24 +344,8 @@ export default {
return 0
}

const headers = {
"Accept": "application/json; charset=utf-8",
"Cache-Control": "no-store"
}
let annotatorAuthenticated = false
const url = `${config.public.flatmap_api}/annotator/authenticate?key=${mainStore.userToken}`
annotatorAuthenticated = await $axios.get(url, { headers }).then((response) => {
if (response.data.data.canUpdate) {
return true
}
return false
}).catch(() => {
return false
})

return {
downloadsSummary,
annotatorAuthenticated
downloadsSummary
}
},
computed: {
Expand Down Expand Up @@ -394,9 +377,10 @@ export default {
if (newValue && newValue !== '') {
await this.fetchOrganizations()
this.fetchPublishedDatasets(newValue)
this.fetchInProgressDatasets()
await this.fetchInProgressDatasets()
this.fetchDatasetSubmissions()
this.fetchQuestions()
this.fetchAnnotatorAuthentication()
}
},
immediate: true
Expand Down Expand Up @@ -511,6 +495,29 @@ export default {
return []
})
},
async fetchAnnotatorAuthentication() {
let orgIntIds = undefined
this.organizations.forEach(org => {
if (org.name === 'SPARC') { orgIntIds = org.intId }
})
try {
await this.$axios.put(`${this.$config.public.LOGIN_API_URL}/session/switch-organization?organization_id=${orgIntIds}&api_key=${this.userToken}`)
} catch (e) {
}
const headers = {
"Accept": "application/json; charset=utf-8",
"Cache-Control": "no-store"
}
const url = `${this.$config.public.flatmap_api}/annotator/authenticate?key=${this.userToken}`
this.annotatorAuthenticated = await this.$axios.get(url, { headers }).then((response) => {
if (response.data.data.canUpdate) {
return true
}
return false
}).catch(() => {
return false
})
},
getDownloadsCount(id) {
let numDownloads = 0
this.downloadsSummary.filter(download => download.datasetId == id).forEach(item => {
Expand Down
Loading