Provide current-user application-wide

* This change allows us to reuse the current user in multiple places.
* Sentry still receives the same information as before.
This commit is contained in:
Sebastian Serth
2023-09-06 22:22:33 +02:00
committed by Sebastian Serth
parent 50a4707f65
commit 33aa0cecba
3 changed files with 8 additions and 6 deletions

View File

@ -36,6 +36,9 @@ $(document).on('turbolinks:load', function() {
window.location.reload();
});
// Set current user
window.current_user = JSON.parse($('meta[name="current-user"]')?.attr('content') || null);
// Set locale for all JavaScript functions
const htmlTag = $('html')
I18n.defaultLocale = htmlTag.data('default-locale');
@ -59,10 +62,8 @@ $(document).on('turbolinks:load', function() {
integrations: window.SentryIntegrations(),
profilesSampleRate: 1.0,
initialScope: scope =>{
const user = $('meta[name="current-user"]').attr('content');
if (user) {
scope.setUser(JSON.parse(user));
if (current_user) {
scope.setUser(_.omit(current_user, 'displayname'));
}
return scope;
}