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
53 changes: 9 additions & 44 deletions api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,31 +584,12 @@ const defs = {
'GET/api/deployment/query': route({
authorize: withUserSession,
fn: async (ctx, { deployment, sql }) => {
const dep = DeploymentsCollection.get(deployment)

if (!dep) {
throw new respond.NotFoundError({ message: 'Deployment not found' })
}

if (!dep.databaseEnabled) {
throw new respond.BadRequestError({
message: 'Database not enabled for deployment',
})
}

const project = ProjectsCollection.get(dep.projectId)
if (!project) throw respond.NotFound({ message: 'Project not found' })
if (!project.isPublic && !ctx.session.isAdmin) {
if (!(await userInTeam(project.teamId, ctx.session.email))) {
throw new respond.ForbiddenError({
message: 'Access to project queries denied',
})
}
}

const { sqlEndpoint, sqlToken } = dep
const { sqlEndpoint, sqlToken } = await withDeploymentTableAccess(
ctx,
deployment,
)
if (!sqlEndpoint || !sqlToken) {
throw new respond.BadRequestError({
throw respond.BadRequest({
message: 'SQL endpoint or token not configured for deployment',
})
}
Expand Down Expand Up @@ -649,26 +630,10 @@ const defs = {
'GET/api/deployment/metrics-sql': route({
authorize: withUserSession,
fn: async (ctx, { deployment }) => {
const dep = DeploymentsCollection.get(deployment)
if (!dep) throw respond.NotFound({ message: 'Deployment not found' })

if (!dep.databaseEnabled) {
throw respond.BadRequest({
message: 'Database not enabled for deployment',
})
}

const project = ProjectsCollection.get(dep.projectId)
if (!project) throw respond.NotFound({ message: 'Project not found' })
if (!project.isPublic && !ctx.session.isAdmin) {
if (!(await userInTeam(project.teamId, ctx.session.email))) {
throw respond.Forbidden({
message: 'Access to project metrics denied',
})
}
}

const { sqlEndpoint, sqlToken } = dep
const { sqlEndpoint, sqlToken } = await withDeploymentTableAccess(
ctx,
deployment,
)
if (!sqlEndpoint || !sqlToken) {
throw respond.BadRequest({
message: 'SQL endpoint or token not configured for deployment',
Expand Down
2 changes: 1 addition & 1 deletion web/pages/ProjectsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const EmptyState = (
const ProjectCard = (
{ project, members }: { project: Project; members: string[] },
) => {
const isMember = members.includes(user.data?.id || '')
const isMember = user.data?.isAdmin || members.includes(user.data?.id || '')
return (
<A
key={project.slug}
Expand Down
Loading