Commit 394616d
feat: Add custom field (metadata) support
Adds support for reading and writing Flagsmith custom fields on features,
segments and environments, which terraform-provider-flagsmith#215 needs. Until
now the provider could not set a custom field at all, so an organisation with a
mandatory custom field could not create features through it.
The API takes a MetadataModelField ID, which is not the same as the custom
field's own ID: a single field bound to features, segments and environments has
three of them. Resolving a name to the right one is fiddly enough that it does
not belong in every caller, so this adds a MetadataFieldResolver that maps names
to model field IDs for one (project, entity) pair and back again.
Two API details drive the design:
- `GET /projects/{id}/metadata/fields/?entity=feature` filters which *fields*
are returned but does NOT filter each field's nested `model_fields`, so the
caller has to match on content type regardless. The entity param is therefore
not used, which also lets one response serve all three entity types.
- Django content type IDs are specific to an installation, so they are resolved
at runtime from the supported-content-types endpoint and never hardcoded.
`GET /features/get-by-uuid/` is served by CreateFeatureSerializer, which omits
metadata, so GetFeature hydrates it from the project scoped retrieve endpoint.
That costs one extra request per feature read. Segments and environments need no
workaround: their get-by-uuid responses already include metadata. See the TODO
for the upstream fix that would remove this.
Feature.UnmarshalJSON decodes into an explicit allowlist, so adding Metadata to
the struct alone would have silently dropped it on every read. The allowlist now
carries a warning, and a reflection based test fails if a future field is
missed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent d4a039a commit 394616d
5 files changed
Lines changed: 1228 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
135 | 148 | | |
136 | 149 | | |
137 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
138 | 175 | | |
139 | 176 | | |
140 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
23 | 63 | | |
24 | 64 | | |
25 | 65 | | |
| |||
0 commit comments