Skip to content
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
17 changes: 17 additions & 0 deletions apps/data-management/src/components/base/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
title="About"
/>

<v-list-item
v-if="user.isStaff"
:prepend-icon="mdiViewDashboardOutline"
:href="adminDashboardUrl"
data-testid="admin-menu-item"
title="Admin dashboard"
/>

<v-divider />

<v-list-item
Expand Down Expand Up @@ -153,6 +161,13 @@
data-testid="about-drawer-item"
>About</v-list-item
>
<v-list-item
v-if="user.isStaff"
:href="adminDashboardUrl"
:prepend-icon="mdiViewDashboardOutline"
data-testid="admin-drawer-item"
>Admin dashboard</v-list-item
>
<v-list-item
:prepend-icon="mdiLogout"
@click.prevent="onLogout"
Expand Down Expand Up @@ -202,13 +217,15 @@ import {
mdiShieldCheckOutline,
mdiShieldEditOutline,
mdiTransitConnectionVariant,
mdiViewDashboardOutline,
} from '@mdi/js'

const route = useRoute()
const { resetState } = useDataVisStore()
const { user } = storeToRefs(useUserStore())
const signupEnabled =
import.meta.env.VITE_APP_DISABLE_ACCOUNT_CREATION !== 'true'
const adminDashboardUrl = hs.resolveUrl('/admin/')

const sidebar = useSidebarStore()
const drawer = ref(false)
Expand Down
88 changes: 88 additions & 0 deletions apps/data-management/src/components/base/__tests__/Navbar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { shallowMount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'
import { User } from '@hydroserver/client'
import { useUserStore } from '@/store/user'
import Navbar from '@/components/base/Navbar.vue'

vi.mock('vue-router', () => ({
useRoute: () => ({ meta: {}, name: 'Workspaces', path: '/workspaces' }),
}))

vi.mock('@/router/router', () => ({
default: {
push: vi.fn(),
resolve: () => ({ meta: {} }),
},
}))

vi.mock('@/store/dataVisualization', () => ({
useDataVisStore: () => ({ resetState: vi.fn() }),
}))

vi.mock('@hydroserver/client', () => ({
default: {
resolveUrl: (path: string) => `https://hydro.example.com${path}`,
session: {
isAuthenticated: true,
getAccountSignupUrl: () => '',
},
},
User: class {
firstName = ''
lastName = ''
isStaff = false
},
}))

const ADMIN_URL = 'https://hydro.example.com/admin/'

/** `compact` mirrors the narrow-viewport media query that swaps in the drawer. */
async function mountNavbar(isStaff: boolean, compact = false) {
const user = new User()
user.isStaff = isStaff
useUserStore().user = user

window.matchMedia = vi.fn().mockReturnValue({
matches: compact,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
})

const wrapper = shallowMount(Navbar, {
global: { renderStubDefaultSlot: true },
})
await nextTick()
return wrapper
}

describe('Navbar admin dashboard link', () => {
beforeEach(() => {
setActivePinia(createPinia())
})

it('shows staff users the link in the account menu', async () => {
const wrapper = await mountNavbar(true)

expect(
wrapper.get('[data-testid="admin-menu-item"]').attributes('href')
).toBe(ADMIN_URL)
})

it('shows staff users the link in the compact drawer', async () => {
const wrapper = await mountNavbar(true, true)

expect(
wrapper.get('[data-testid="admin-drawer-item"]').attributes('href')
).toBe(ADMIN_URL)
})

it('hides the link from non-staff users', async () => {
for (const compact of [false, true]) {
const wrapper = await mountNavbar(false, compact)

expect(wrapper.find('[data-testid^="admin-"]').exists()).toBe(false)
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useWorkspacePermissions(
}

function isAdmin() {
return user.value?.accountType === 'admin'
return user.value?.isSuperuser === true
}
const getUserRoleName = (workspace: Workspace): string => {
if (isOwner(workspace)) return 'Owner'
Expand Down
4 changes: 1 addition & 3 deletions apps/data-management/src/pages/Workspaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ watch(
{ immediate: true }
)

const canCreateWorkspace = computed(() =>
['admin', 'standard'].includes(user.value?.accountType ?? '')
)
const canCreateWorkspace = computed(() => user.value?.ownedWorkspaceLimit !== 0)

/** Workspaces that are pending a transfer to the current user */
const pendingWorkspaces = computed(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ vi.mock('@hydroserver/client', () => ({
},
DataConnection: class {},
User: class {
accountType = 'standard'
isSuperuser = false
email = 'user@example.com'
},
PermissionAction: {
Expand Down
Loading
Loading