Flagsmith / Flagsmith/flagsmith

Replace the PermissionModel reference table with an enum

Open
#7,850 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

`permissions.PermissionModel` is a reference table holding the fixed set of permission types. Its rows are seeded by data migrations spread across three apps. Permission assignments are M2M foreign keys to it. This breaks tests, and forces us to maintain unneeded complexity.

### Proposal

Model permissions as an enum / constant set in code (`key`, `description`, `type`) and store assignments by key directly (e.g. a `choices` field on the through tables, or an array of keys), dropping the `PermissionModel` table. The set is fixed, so it does not belong in a mutable table.

### Blast radius

- The shared `permissions` M2M base and every model that inherits it (OSS: `environments`, `environments/permissions`, `organisations/permissions`, `projects`), plus the `Role*Permission` models in `flagsmith-private/rbac`.
- A data migration converting existing `permissionmodel_id` links across all those through tables to the new representation.
- The permissions API exposes `("key", "description", "supports_tag")`, so descriptions and the tag-support flag must keep being served from the enum definition.

## Acceptance

- `PermissionModel` removed; permissions represented as an enum/constant set.
- `api/core/db_backends/postgresql/` and the `DATABASES["default"]["ENGINE"]` override in `app/settings/test.py` are deleted.

Contributor guide

Open the contributing guide

Research direction

Trace the shared permissions M2M base and its users in environments, environments/permissions, organisations/permissions, projects, and flagsmith-private/rbac. Review the existing data migrations and the permissions API, then inspect api/core/db_backends/postgresql/ and the DATABASES override in app/settings/test.py. Done means PermissionModel and those PostgreSQL overrides are removed, existing assignments are migrated, and the API still serves key, description, and supports_tag.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
api, authorization, backend, database
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.