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 unnecessary requests for user data on frontend #2

Merged
merged 1 commit into from
Sep 11, 2023
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
2 changes: 1 addition & 1 deletion main/handlers/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ func GetProfilePhotoHandler(e echo.Context) error {

err := userService.GetProfilePhoto(sess, id, c.Response().Writer)
if err != nil {
return c.NoContent(http.StatusNotFound)
return c.NoContent(http.StatusNoContent)
}
c.Response().Committed = true
c.Response().Header().Set("Content-Type", "image/jpeg")
Expand Down
36 changes: 23 additions & 13 deletions ui/core/src/baseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ export default {
if (this.me.role >= 100) {
return true
}
} catch (e) {
}
} catch (e) {}
try {
// check public
if (item.publicByID[0] === 2) {
return true
}
} catch (e) {
}
} catch (e) {}

try {
// check owner
Expand All @@ -92,8 +90,7 @@ export default {
item.grant[this.me.id][0] === 2) {
return true
}
} catch (e) {
}
} catch (e) {}
try {
// check group
if (this.me.role !== 0) {
Expand All @@ -102,17 +99,15 @@ export default {
return true
}
}
} catch (e) {
}
} catch (e) {}

// check others
try {
if (this.me.role >= 1 && item.groupAndOthers.rights[1] === 2) {
// others have write rights
return true
}
} catch (e) {
}
} catch (e) {}
return false
},
handleError (o) {
Expand Down Expand Up @@ -152,14 +147,29 @@ export default {
},
setSelectedLang (lang) {
if (lang) {
this.$cookie.set('lang', lang, { expires: '1Y' })
this.$cookie.set('lang', lang, {
expires: '1Y'
})
this.reloadI18n()
} else {
this.$cookie.delete('lang')
this.$i18n.set(this.fallbackLang())
}
},
checkUserHasSession () {
return !!localStorage.getItem('userhassession')
},
initUserHasSession () {
localStorage.setItem('userhassession', true)
},
deleteUserHasSession () {
localStorage.removeItem('userhassession')
},
loadMe (clb) {
if (!this.checkUserHasSession()) {
return
}

axios.get('/api/me').then((response) => {
this.me = response.data
this.$root.$emit('me', this.me)
Expand All @@ -171,6 +181,7 @@ export default {
}
}
}, (err) => {
this.deleteUserHasSession()
this.handleError(err)
})
},
Expand Down Expand Up @@ -396,8 +407,7 @@ export default {
get () {
return this.$root.$children[0]
},
set (a) {
}
set (a) {}
}
},
created () {
Expand Down
1 change: 1 addition & 0 deletions ui/core/src/components/user/TopRightProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default {
},
logout () {
axios.post('/api/logout', null).then(response => {
this.app.deleteUserHasSession()
window.location.replace('/')
}, (err) => {
this.app.handleError(err)
Expand Down
2 changes: 2 additions & 0 deletions ui/core/src/views/AdminLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ export default {
this.pwlogin = true
if (this.checkTermsAndConditions()) {
axios.post('/api/login', { email: this.email, password: this.password }).then(res => {
this.app.initUserHasSession()
this.hasError = false
window.location = res.data.location || '/admin/workflow'
}, (err) => {
this.app.deleteUserHasSession()
this.app.handleError(err)
this.loginErrorMessage = this.$t('You have entered an invalid username or password')
this.hasError = true
Expand Down