mock-permissions.ts 780 B

1234567891011121314151617181920212223242526272829
  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. }