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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { useIsProtectedSchema } from 'hooks/useProtectedSchemas'
import { parseAsBoolean, useQueryState } from 'nuqs'
import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
import {
Button,
Expand All @@ -51,6 +52,11 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
const { data: project } = useSelectedProjectQuery()
const { data: org } = useSelectedOrganizationQuery()

const [showWarning, setShowWarning] = useQueryState(
'showWarning',
parseAsBoolean.withDefault(false)
)

// need project lints to get security status for views
const { data: lints = [] } = useProjectLintsQuery({ projectRef: project?.ref })

Expand Down Expand Up @@ -261,7 +267,7 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
)}
</>
) : (
<Popover_Shadcn_ modal={false}>
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
<Button type="warning" icon={<Lock strokeWidth={1.5} />}>
RLS disabled
Expand Down Expand Up @@ -301,7 +307,7 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
)
) : null}
{isView && viewHasLints && (
<Popover_Shadcn_ modal={false}>
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
<Button type="warning" icon={<Unlock strokeWidth={1.5} />}>
Security Definer view
Expand Down Expand Up @@ -351,7 +357,7 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
</Popover_Shadcn_>
)}
{isMaterializedView && materializedViewHasLints && (
<Popover_Shadcn_ modal={false}>
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
<Button type="warning" icon={<Unlock strokeWidth={1.5} />}>
Security Definer view
Expand Down Expand Up @@ -393,7 +399,7 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
</Popover_Shadcn_>
)}
{isForeignTable && table.schema === 'public' && (
<Popover_Shadcn_ modal={false}>
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
<Button type="warning" icon={<Unlock strokeWidth={1.5} />}>
Unprotected Data API access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from 'next/link'
import Papa from 'papaparse'
import { toast } from 'sonner'

import { IS_PLATFORM } from 'common'
import { IS_PLATFORM, useParams } from 'common'
import {
MAX_EXPORT_ROW_COUNT,
MAX_EXPORT_ROW_COUNT_MESSAGE,
Expand All @@ -16,6 +16,7 @@ import {
} from 'components/interfaces/TableGridEditor/TableEntity.utils'
import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
import type { ItemRenderer } from 'components/ui/InfiniteList'
import { InlineLink } from 'components/ui/InlineLink'
import { getTableDefinition } from 'data/database/table-definition-query'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { Entity } from 'data/entity-types/entity-types-infinite-query'
Expand Down Expand Up @@ -453,28 +454,53 @@ const EntityTooltipTrigger = ({
materializedViewHasLints: boolean
foreignTableHasLints: boolean
}) => {
let tooltipContent = ''
const { ref } = useParams()

let tooltipContent = null
const accessWarning = 'Data is publicly accessible via API'
const learnMoreCTA = (
<InlineLink
href={`/project/${ref}/editor/${entity.id}?schema=${entity.schema}&showWarning=true`}
>
Learn more
</InlineLink>
)

switch (entity.type) {
case ENTITY_TYPE.TABLE:
if (tableHasLints) {
tooltipContent = `${accessWarning} as RLS is disabled`
tooltipContent = (
<>
{accessWarning} as RLS is disabled. {learnMoreCTA}.
</>
)
}
break
case ENTITY_TYPE.VIEW:
if (viewHasLints) {
tooltipContent = `${accessWarning} as this is a Security definer view`
tooltipContent = (
<>
{accessWarning} as this is a Security definer view. {learnMoreCTA}.
</>
)
}
break
case ENTITY_TYPE.MATERIALIZED_VIEW:
if (materializedViewHasLints) {
tooltipContent = `${accessWarning} Security definer view`
tooltipContent = (
<>
{accessWarning} as this is a Security definer view {learnMoreCTA}.
</>
)
}
break
case ENTITY_TYPE.FOREIGN_TABLE:
if (foreignTableHasLints) {
tooltipContent = `${accessWarning} as RLS is not enforced on foreign tables`
tooltipContent = (
<>
{accessWarning} as RLS is not enforced on foreign tables. {learnMoreCTA}.
</>
)
}
break
default:
Expand All @@ -483,12 +509,12 @@ const EntityTooltipTrigger = ({

if (tooltipContent) {
return (
<Tooltip disableHoverableContent={true}>
<Tooltip>
<TooltipTrigger className="min-w-4">
<Badge variant="destructive">Unrestricted</Badge>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-44 text-center">
<span>{tooltipContent}</span>
<TooltipContent side="right" className="max-w-52 text-center">
{tooltipContent}
</TooltipContent>
</Tooltip>
)
Expand Down
Loading