From c7166f20fb61d24de9416511f145bd02e3c23eb5 Mon Sep 17 00:00:00 2001
From: Hiveer
Date: Tue, 3 Dec 2024 19:48:53 +0800
Subject: [PATCH] Remove cookie admin_user and get user roles from userStore
(#833)
---
.../application_spaces/NewApplicationSpace.vue | 16 ++++++----------
frontend/src/stores/UserStore.js | 8 ++++++--
internal/handlers/render/session.go | 1 -
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/frontend/src/components/application_spaces/NewApplicationSpace.vue b/frontend/src/components/application_spaces/NewApplicationSpace.vue
index c7cc70a6b..bb981b229 100644
--- a/frontend/src/components/application_spaces/NewApplicationSpace.vue
+++ b/frontend/src/components/application_spaces/NewApplicationSpace.vue
@@ -210,7 +210,7 @@
Streamlit
Nginx
{
const uuid = ref('')
const homepage = ref('')
const bio = ref('')
- const roles = ref('')
+ const roles = ref([])
const orgs = ref([])
const lastLoginTime = ref('')
const initialized = ref(false)
const isLoggedIn = computed(() => username.value !== '')
+ const isAdmin = computed(() => roles.value.includes('admin') || roles.value.includes('super_user'))
+ const isSuperUser = computed(() => roles.value.includes('super_user'))
async function initialize(initialData) {
username.value = initialData.username || ''
@@ -48,7 +50,9 @@ const useUserStore = defineStore('User', () => {
roles,
orgs,
lastLoginTime,
- initialized
+ initialized,
+ isAdmin,
+ isSuperUser
}
})
diff --git a/internal/handlers/render/session.go b/internal/handlers/render/session.go
index b736c6b76..6a3ecefc5 100644
--- a/internal/handlers/render/session.go
+++ b/internal/handlers/render/session.go
@@ -135,7 +135,6 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {
ctx.SetCookie("login_identity", user.LoginIdentity, cookieMaxAge, "/", "", false, false)
ctx.SetCookie("current_user", userResp.Username, cookieMaxAge, "/", "", false, false)
- ctx.SetCookie("admin_user", fmt.Sprintf("%t", user.IsAdmin()), cookieMaxAge, "/", "", false, false)
user.SessionIP = ctx.ClientIP()
err = i.userModel.Update(ctx, user)