|
15 | 15 | using Newtonsoft.Json; |
16 | 16 | using AzureFunctions.OidcAuthentication; |
17 | 17 | using TwoWeeksReady.Common.EmergencyKits; |
| 18 | +using TwoWeeksReady.Authorization; |
18 | 19 |
|
19 | 20 | namespace TwoWeeksReady.EmergencyKits |
20 | 21 | { |
@@ -74,7 +75,13 @@ public async Task<IActionResult> CreateBaseKit( |
74 | 75 | return new UnauthorizedResult(); |
75 | 76 | } |
76 | 77 |
|
77 | | - var content = await new StreamReader(req.Body).ReadToEndAsync(); |
| 78 | + if (!authorizationResult.IsInRole(Roles.Admin)) |
| 79 | + { |
| 80 | + log.LogWarning($"User is not in the {Roles.Admin} role"); |
| 81 | + return new UnauthorizedResult(); |
| 82 | + } |
| 83 | + |
| 84 | + var content = await new StreamReader(req.Body).ReadToEndAsync(); |
78 | 85 | var newBaseKit = JsonConvert.DeserializeObject<BaseKit>(content); |
79 | 86 | newBaseKit.Id = Guid.NewGuid().ToString(); |
80 | 87 | if(newBaseKit.Items.Count > 0) |
@@ -105,6 +112,12 @@ public async Task<IActionResult> UpdateBaseKit( |
105 | 112 | return new UnauthorizedResult(); |
106 | 113 | } |
107 | 114 |
|
| 115 | + if (!authorizationResult.IsInRole(Roles.Admin)) |
| 116 | + { |
| 117 | + log.LogWarning($"User is not in the {Roles.Admin} role"); |
| 118 | + return new UnauthorizedResult(); |
| 119 | + } |
| 120 | + |
108 | 121 | var content = await new StreamReader(req.Body).ReadToEndAsync(); |
109 | 122 | var kit = JsonConvert.DeserializeObject<BaseKit>(content); |
110 | 123 |
|
@@ -154,8 +167,13 @@ public async Task<IActionResult> DeleteBaseKit( |
154 | 167 | log.LogWarning(authorizationResult.FailureReason); |
155 | 168 | return new UnauthorizedResult(); |
156 | 169 | } |
| 170 | + if (!authorizationResult.IsInRole(Roles.Admin)) |
| 171 | + { |
| 172 | + log.LogWarning($"User is not in the {Roles.Admin} role"); |
| 173 | + return new UnauthorizedResult(); |
| 174 | + } |
157 | 175 |
|
158 | | - if(String.IsNullOrWhiteSpace(id)) |
| 176 | + if (String.IsNullOrWhiteSpace(id)) |
159 | 177 | { |
160 | 178 | return new BadRequestObjectResult("Base Kit id was not specified."); |
161 | 179 | } |
|
0 commit comments