Commit 70f40d5
committed
feat: give the identity an ordered role instead of a single is_admin boolean
Add `UserRole`, an ordered `StrEnum` (none < viewer < editor < admin <
super_admin) whose members compare by rank rather than alphabetically, and a
required `role` field on `BaseUser`. `is_admin` becomes a computed property
equal to `role >= UserRole.ADMIN`, so every consumer keeps reading the same
boolean and admits the same identities.
Each of the five construction paths sets `role` explicitly: the two Grafana
record mappings flatten org memberships by rank (server-admin flag outranking
them), the Casdoor payload derives it from the admin flag, and the service
principal takes `VIEWER`. Both inbound legacy-claim paths reconstruct the role
through one shared helper that validates the flag with Pydantic's boolean
semantics, so a payload spelling the flag "false" or "0" still means non-admin.
The minted assertion is unchanged, so tokens issued before this change keep
decoding; Editor and Viewer therefore stay indistinguishable on bearer
requests until the assertion carries a real role claim.
`role` is required with no default so a construction path that forgets it fails
loudly instead of silently yielding the lowest role. This breaks out-of-tree
`CUSTOM` providers that build identities from `is_admin` alone, which ships as
a breaking changelog fragment.1 parent c3e1d57 commit 70f40d5
19 files changed
Lines changed: 826 additions & 75 deletions
File tree
- .github/instructions
- app
- api
- core/auth
- providers
- casdoor
- grafana
- changelog.d
- docs/development
- frontend/packages/api
- specs
- src/generated
- tests/app
- api
- routes
- core/auth
- providers
- casdoor
- grafana
- sep
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
169 | | - | |
170 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 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 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
128 | 192 | | |
129 | 193 | | |
130 | 194 | | |
| |||
133 | 197 | | |
134 | 198 | | |
135 | 199 | | |
136 | | - | |
137 | | - | |
| 200 | + | |
138 | 201 | | |
139 | 202 | | |
140 | 203 | | |
| |||
146 | 209 | | |
147 | 210 | | |
148 | 211 | | |
149 | | - | |
| 212 | + | |
150 | 213 | | |
151 | 214 | | |
152 | 215 | | |
| |||
171 | 234 | | |
172 | 235 | | |
173 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
174 | 269 | | |
175 | 270 | | |
176 | 271 | | |
| |||
195 | 290 | | |
196 | 291 | | |
197 | 292 | | |
| 293 | + | |
198 | 294 | | |
199 | 295 | | |
200 | 296 | | |
201 | | - | |
202 | 297 | | |
203 | 298 | | |
204 | 299 | | |
| |||
209 | 304 | | |
210 | 305 | | |
211 | 306 | | |
| 307 | + | |
212 | 308 | | |
213 | 309 | | |
214 | 310 | | |
215 | | - | |
216 | | - | |
217 | 311 | | |
218 | 312 | | |
219 | 313 | | |
| |||
222 | 316 | | |
223 | 317 | | |
224 | 318 | | |
225 | | - | |
| 319 | + | |
226 | 320 | | |
227 | 321 | | |
228 | 322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
| 31 | + | |
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
| |||
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | | - | |
| 117 | + | |
| 118 | + | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
| |||
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
129 | 163 | | |
130 | 164 | | |
131 | 165 | | |
| |||
0 commit comments