Permission sets cannot confine instrument deletion to the holder's groups

Abierto
#1,914 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Start with packages/schemas/src/core/core.ts, apps/api/src/auth/ability.factory.ts, apps/api/prisma/schema.prisma, and the permission editor code named in the issue; read .agents/docs/architecture/auth-and-permissions.md and packages/schemas/AGENTS.md for the current scope rules. Trace how permission rules are validated, applied, and presented for Instrument, including the existing GROUP_MANAGER condition. Done means the chosen action and group scope behave consistently across schema, API, web, and documentation, with tests covering the read and delete behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Area: API Area: Shared Area: Web Difficulty: Medium Enhancement Needs Decision Priority: Medium Security

Problem

A permission set rule on Instrument can only have the scope "Every group". As a result, a set cannot grant deleting series instruments only within the holder's groups. The GROUP_MANAGER base level grants exactly that:

// apps/api/src/auth/ability.factory.ts
ability.can('delete', 'Instrument', { seriesGroupId: { in: groupIds } });

To let someone delete series instruments through a set, an admin has to add delete Instrument with ALL_GROUPS. InstrumentsService.deleteById filters only by the ability, so a holder of that set can delete any group's series instrument that has no records or assignments yet, not only their own groups' series.

Cause

packages/schemas/src/core/core.ts excludes Instrument from the subjects that can be confined to a group:

export const $GroupScopableSubjectName = $AppSubjectName.exclude(['all', 'Instrument']);

.agents/docs/architecture/auth-and-permissions.md gives the reason: an instrument is "a shared asset with no owning group". That holds for shared instruments but not for series instruments, which have seriesGroupId (apps/api/prisma/schema.prisma). That field was added in 87ce6b5d9, before this exclusion was written in 8c4cbeeed.

Every layer follows the exclusion:

  • Schema: $PermissionSetRule and $UserPermission reject a group scope on Instrument.
  • API: GROUP_SCOPED_CONDITIONS has no Instrument entry, and grantWithin throws on one.
  • Web: toPermissionSetRule and PermissionSetRulesEditor force and display "Every group".

Per-user additional permissions have the same gap, since they are checked against the same list.

Proposed fix

Make Instrument group-scopable with the condition { seriesGroupId: { in: groupIds } }. That condition matches what the group manager rule already uses.

Decision needed

With that condition, any HOLDER_GROUPS instrument rule matches only series owned by the holder's groups:

  • For delete, that is the intended meaning.
  • For read, it would hide every shared instrument, which is almost certainly not what an admin choosing "Holder's groups" expects.
  • create is already checked against the target group in InstrumentsService.

Options:

  1. Allow the group scope on Instrument for delete only. The scopable check would then depend on the action as well as the subject, which is a bigger change to the schema and the editor.
  2. Allow it for every action, and document in the editor what it means for read.

Either way, the "shared asset with no owning group" rule in packages/schemas/AGENTS.md and .agents/docs/architecture/auth-and-permissions.md needs updating.

Lenguaje dominante
TypeScript
Estrellas
119
Forks
19
Merge medio
1 d 18 h
PR fusionados (30 d)
61

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DouglasNeuroInformatics/OpenDataCapture

Todos los issues de DouglasNeuroInformatics/OpenDataCapture

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.