SecurityDefinerViewPopover.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { useParams } from 'common'
  2. import { Unlock } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { Button, Popover, PopoverContent, PopoverTrigger } from 'ui'
  5. import { type Lint } from '@/data/lint/lint-query'
  6. export const SecurityDefinerViewPopover = ({
  7. lint,
  8. onAutofix,
  9. }: {
  10. lint: Lint | null
  11. onAutofix?: () => void
  12. }) => {
  13. const { ref } = useParams()
  14. return (
  15. <Popover modal={false}>
  16. <PopoverTrigger asChild>
  17. <Button type="warning" icon={<Unlock strokeWidth={1.5} />}>
  18. Security Definer view
  19. </Button>
  20. </PopoverTrigger>
  21. <PopoverContent className="min-w-[395px] text-sm" align="end">
  22. <h4 className="flex items-center gap-2">
  23. <Unlock size={14} /> Secure your view
  24. </h4>
  25. <div className="grid gap-2 mt-2 text-foreground-light text-sm">
  26. <p>
  27. This view is defined with the Security Definer property, giving it permissions of the
  28. view's creator (Postgres), rather than the permissions of the querying user.
  29. </p>
  30. <p>Since this view is in the public schema, it is accessible via your project's APIs.</p>
  31. <div className="mt-2 flex items-center gap-2">
  32. {!!onAutofix && (
  33. <Button type="secondary" onClick={onAutofix}>
  34. Autofix
  35. </Button>
  36. )}
  37. <Button type="default" asChild>
  38. <Link
  39. target="_blank"
  40. rel="noopener noreferrer"
  41. href={`/project/${ref}/advisors/security?preset=${lint?.level}&id=${lint?.cache_key}`}
  42. >
  43. Learn more
  44. </Link>
  45. </Button>
  46. </div>
  47. </div>
  48. </PopoverContent>
  49. </Popover>
  50. )
  51. }