Skip to content

Commit

Permalink
Remove cookie admin_user and get user roles from userStore (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiveer authored Dec 3, 2024
1 parent baab464 commit c7166f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
16 changes: 6 additions & 10 deletions frontend/src/components/application_spaces/NewApplicationSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<p class="font-semibold text-md">Streamlit</p>
</el-radio>
<el-radio
v-if="isAdmin"
v-if="userStore.isAdmin"
class="rounded-md !border-[2px] !h-[120px] flex justify-center"
size="large"
label="nginx"
Expand All @@ -225,7 +225,7 @@
<p class="font-semibold text-md">Nginx</p>
</el-radio>
<el-radio
v-if="!isAdmin"
v-if="!userStore.isAdmin"
class="rounded-md !border-[2px] !h-[120px] flex justify-center"
size="large"
label="docker"
Expand Down Expand Up @@ -338,22 +338,18 @@
import { useI18n } from 'vue-i18n'
import useFetchApi from '../../packs/useFetchApi'
import useUserStore from '../../stores/UserStore'
import { useCookies } from 'vue3-cookies'
import PublicAndPrivateRadioGroup from '../shared/form/PublicAndPrivateRadioGroup.vue'
const userStore = useUserStore()
const props = defineProps({
licenses: Array
})
const { cookies } = useCookies()
const userStore = useUserStore()
const dataFormRef = ref(null)
const imageUploaded = ref(false)
const images = ref([])
const { t } = useI18n()
const nameRule = inject('nameRule')
const isAdmin = cookies.isKey('admin_user')
const props = defineProps({
licenses: Array
})
const dataForm = ref({
owner: '',
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/stores/UserStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const useUserStore = defineStore('User', () => {
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 || ''
Expand Down Expand Up @@ -48,7 +50,9 @@ const useUserStore = defineStore('User', () => {
roles,
orgs,
lastLoginTime,
initialized
initialized,
isAdmin,
isSuperUser
}
})

Expand Down
1 change: 0 additions & 1 deletion internal/handlers/render/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c7166f2

Please sign in to comment.