mock-permissions.ts 781 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useSessionStore } from '#shared/stores/session.ts'
  3. import { initializeStore } from './components/initializeStore.ts'
  4. export const mockPermissions = (permissions: string[]) => {
  5. initializeStore()
  6. const session = useSessionStore()
  7. if (!session.user) {
  8. session.user = {
  9. id: '123',
  10. internalId: 1,
  11. objectAttributeValues: [],
  12. }
  13. }
  14. session.user!.permissions = { names: permissions }
  15. if (Symbol.for('tests.permissions') in globalThis) return
  16. Object.defineProperty(globalThis, Symbol.for('tests.permissions'), {
  17. get() {
  18. const session = useSessionStore()
  19. return session.user?.permissions || { names: [] }
  20. },
  21. configurable: true,
  22. })
  23. }