| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import { OAuthScope } from '@supabase/shared-types/out/constants'
- import { Check } from 'lucide-react'
- import { PERMISSIONS_DESCRIPTIONS } from './OAuthApps.constants'
- export interface AuthorizeRequesterDetailsProps {
- icon: string | null
- name: string
- domain: string
- scopes: OAuthScope[]
- showOnlyScopes?: boolean
- }
- export const ScopeSection = ({
- description,
- hasReadScope,
- hasWriteScope,
- }: {
- description: string
- hasReadScope: boolean
- hasWriteScope: boolean
- }) => {
- if (hasReadScope || hasWriteScope) {
- const perms = [hasReadScope ? 'Read' : null, hasWriteScope ? 'Write' : null]
- .filter(Boolean)
- .map((str) => (
- <span key={str} className="font-semibold text-foreground">
- {str}
- </span>
- ))
- .reduce((acc, v) => (
- <>
- {acc}
- <span> and </span>
- {v}
- </>
- ))
- return (
- <div className="first:border-t border-b flex flex-row space-x-1 text-sm text-foreground-light py-2 px-1">
- <div className="pt-0.5">
- <Check stroke="green" height={18} width={18} strokeWidth={1.5} />
- </div>
- <div>
- {perms} {description}
- </div>
- </div>
- )
- }
- return null
- }
- export const AuthorizeRequesterDetails = ({
- icon,
- name,
- domain,
- scopes,
- showOnlyScopes = false,
- }: AuthorizeRequesterDetailsProps) => {
- return (
- <div className="flex gap-y-4 flex-col">
- {!showOnlyScopes && (
- <div className="flex flex-row gap-x-4 items-center">
- <div className="flex items-center">
- <div
- className="w-12 h-12 md:w-14 md:h-14 bg-center bg-no-repeat bg-cover flex items-center justify-center rounded-md border border-control"
- style={{
- backgroundImage: !!icon ? `url('${icon}')` : 'none',
- }}
- >
- {!icon && <p className="text-foreground-light text-lg">{name[0]}</p>}
- </div>
- </div>
- <p className="text-foreground">
- {name} ({domain}) is requesting API access to an organization.
- </p>
- </div>
- )}
- <div>
- {!showOnlyScopes && (
- <>
- <h3>Permissions</h3>
- <p className="text-sm text-foreground-light">
- The following scopes will apply for the{' '}
- <span className="text-amber-900">selected organization and all of its projects.</span>
- </p>
- </>
- )}
- <div className="pt-2">
- {scopes.length === 0 && (
- <p className="text-foreground-lighter text-sm">
- No permissions requested, {name} will not have access to your organization or projects
- </p>
- )}
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.ANALYTICS}
- hasReadScope={scopes.includes(OAuthScope.ANALYTICS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.ANALYTICS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.ANALYTICS_CONFIG}
- hasReadScope={scopes.includes(OAuthScope.ANALYTICS_CONFIG_READ)}
- hasWriteScope={scopes.includes(OAuthScope.ANALYTICS_CONFIG_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.AUTH}
- hasReadScope={scopes.includes(OAuthScope.AUTH_READ)}
- hasWriteScope={scopes.includes(OAuthScope.AUTH_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.DATABASE}
- hasReadScope={scopes.includes(OAuthScope.DATABASE_READ)}
- hasWriteScope={scopes.includes(OAuthScope.DATABASE_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.DOMAINS}
- hasReadScope={scopes.includes(OAuthScope.DOMAINS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.DOMAINS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.EDGE_FUNCTIONS}
- hasReadScope={scopes.includes(OAuthScope.EDGE_FUNCTIONS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.EDGE_FUNCTIONS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.ENVIRONMENT}
- hasReadScope={scopes.includes(OAuthScope.ENVIRONMENT_READ)}
- hasWriteScope={scopes.includes(OAuthScope.ENVIRONMENT_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.ORGANIZATIONS}
- hasReadScope={scopes.includes(OAuthScope.ORGANIZATIONS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.ORGANIZATIONS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.PROJECTS}
- hasReadScope={scopes.includes(OAuthScope.PROJECTS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.PROJECTS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.REST}
- hasReadScope={scopes.includes(OAuthScope.REST_READ)}
- hasWriteScope={scopes.includes(OAuthScope.REST_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.SECRETS}
- hasReadScope={scopes.includes(OAuthScope.SECRETS_READ)}
- hasWriteScope={scopes.includes(OAuthScope.SECRETS_WRITE)}
- />
- <ScopeSection
- description={PERMISSIONS_DESCRIPTIONS.STORAGE}
- hasReadScope={scopes.includes(OAuthScope.STORAGE_READ)}
- hasWriteScope={scopes.includes(OAuthScope.STORAGE_WRITE)}
- />
- </div>
- </div>
- </div>
- )
- }
|