Skip to content

Cada función de cursos declara su nivel de acceso - #59

Open
Gaspilabastie wants to merge 9 commits into
mainfrom
access-levels
Open

Gaspilabastie wants to merge 9 commits into
mainfrom
access-levels

Conversation

@Gaspilabastie

Copy link
Copy Markdown
Collaborator

Qué pedía la tarea

Hacer que cada función del backend de ASTN declare su nivel de acceso. Hoy cada función de Convex tiene que acordarse de chequear el acceso por su cuenta, y los tests de permisos encontraron agujeros de funciones que se olvidaron. Este PR cubre las funciones de cursos.

Qué cambia

  • convex/lib/access.ts trae wrappers que corren el chequeo antes del handler:
    • publicQuery / publicMutation: sin login (links de apply, poll y encuesta).
    • memberQuery / memberMutation: alguien logueado actuando sobre lo suyo.
    • courseQuery / courseMutation / courseAction con level: 'read' | 'edit' | 'admin': cargan el registro desde los argumentos (la oportunidad, o el poll, encuesta, postulación o borrador y su oportunidad) y chequean contra la org y el curso de esa oportunidad con getOrgAccess / canAccessOpportunity. Nunca con un orgId o userId que mande el que llama. El handler recibe lo cargado, userId y access.
    • orgQuery / orgMutation: lo que es de toda la org (canónicos, footer, conteos, la lista de oportunidades).
  • Migradas todas las funciones públicas de orgOpportunities, opportunityApplications, availabilityPolls, feedbackSurveys, applicationInvites y emails/{outbox,templateLibrary,outboxSend,adminBroadcastAction}. Las internas quedan como están.
  • pnpm run lint:convex rechaza query / mutation / action sueltos en esos archivos (ACCESS_DECLARED_FILES en eslint.config.mjs, fácil de extender).
  • Nota en CLAUDE.md (Conventions).

Cómo declarar una función nueva

export const algo = courseQuery({
  level: 'read',
  args: { pollId: v.id('availabilityPolls') },
  returns: ...,
  load: (ctx, { pollId }) => loadPoll(ctx, pollId),
  missing: 'Poll not found',      // o () => null para devolver algo
  denied: () => null,             // opcional: no tirar error si no tiene acceso
  handler: async (ctx, args, { poll, opportunity, userId }) => { ... },
})

Comportamiento

No cambia quién puede llamar qué: la matriz de permisos y scenarios.test.ts pasan sin tocarlos. Diferencias menores: los errores de acceso ahora son ConvexError con el mismo texto, y si alguien sin login pide algo que no existe ve "Not authenticated" en vez de "not found".

Checks

  • pnpm run lint && pnpm run lint:convex (solo los 3 warnings que ya estaban)
  • pnpm exec tsc -p convex/tsconfig.json --noEmit
  • bun test src convex: 3331 pass, 0 fail
  • vp check --no-fmt
  • npx convex codegen necesita un deployment; agregué a mano la entrada de lib/access en _generated/api.d.ts, igual a la que genera codegen. vp build no corre en esta Mac; lo corre CI.

🤖 Generated with Claude Code

Gaspilabastie and others added 9 commits November 20, 2026 15:26
publicQuery/publicMutation, memberQuery/memberMutation,
courseQuery/courseMutation/courseAction and orgQuery/orgMutation run the
access check before the handler. Course levels load the record from the
arguments and check its opportunity's org and course through getOrgAccess
and canAccessOpportunity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astn Ready Ready Preview Nov 20, 2026 6:38pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — a0556373 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant