@@ -37,7 +37,7 @@ import { getRoleCredentials } from "api/functions/sts.js";
3737import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager" ;
3838import { createAuditLogEntry } from "api/functions/auditLog.js" ;
3939import { Modules } from "common/modules.js" ;
40- import { groupId , withTags } from "api/components/index.js" ;
40+ import { groupId , withRoles , withTags } from "api/components/index.js" ;
4141import {
4242 FastifyZodOpenApiTypeProvider ,
4343 serializerCompiler ,
@@ -81,6 +81,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
8181 {
8282 schema : withTags ( [ "IAM" ] , {
8383 body : entraProfilePatchRequest ,
84+ summary : "Update user's profile." ,
8485 } ) ,
8586 onRequest : async ( request , reply ) => {
8687 await fastify . authorize ( request , reply , [ ] ) ;
@@ -103,20 +104,22 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
103104 userOid ,
104105 request . body ,
105106 ) ;
106- reply . status ( 201 ) ;
107+ reply . status ( 201 ) . send ( ) ;
107108 } ,
108109 ) ;
109110 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
110111 "/groups/:groupId/roles" ,
111112 {
112- schema : withTags ( [ "IAM" ] , {
113- params : z . object ( {
114- groupId,
113+ schema : withRoles (
114+ [ AppRoles . IAM_ADMIN ] ,
115+ withTags ( [ "IAM" ] , {
116+ params : z . object ( {
117+ groupId,
118+ } ) ,
119+ summary : "Get a group's application role mappings." ,
115120 } ) ,
116- } ) ,
117- onRequest : async ( request , reply ) => {
118- await fastify . authorize ( request , reply , [ AppRoles . IAM_ADMIN ] ) ;
119- } ,
121+ ) ,
122+ onRequest : fastify . authorizeFromSchema ,
120123 } ,
121124 async ( request , reply ) => {
122125 try {
@@ -142,15 +145,17 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
142145 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . post (
143146 "/groups/:groupId/roles" ,
144147 {
145- schema : withTags ( [ "IAM" ] , {
146- params : z . object ( {
147- groupId,
148+ schema : withRoles (
149+ [ AppRoles . IAM_ADMIN ] ,
150+ withTags ( [ "IAM" ] , {
151+ params : z . object ( {
152+ groupId,
153+ } ) ,
154+ body : groupMappingCreatePostSchema ,
155+ summary : "Update a group's application role mappings." ,
148156 } ) ,
149- body : groupMappingCreatePostSchema ,
150- } ) ,
151- onRequest : async ( request , reply ) => {
152- await fastify . authorize ( request , reply , [ AppRoles . IAM_ADMIN ] ) ;
153- } ,
157+ ) ,
158+ onRequest : fastify . authorizeFromSchema ,
154159 } ,
155160 async ( request , reply ) => {
156161 const groupId = ( request . params as Record < string , string > ) . groupId ;
@@ -198,13 +203,15 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
198203 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . post (
199204 "/inviteUsers" ,
200205 {
201- schema : withTags ( [ "IAM" ] , {
202- body : invitePostRequestSchema ,
203- // response: { 202: entraActionResponseSchema },
204- } ) ,
205- onRequest : async ( request , reply ) => {
206- await fastify . authorize ( request , reply , [ AppRoles . IAM_INVITE_ONLY ] ) ;
207- } ,
206+ schema : withRoles (
207+ [ AppRoles . IAM_INVITE_ONLY , AppRoles . IAM_ADMIN ] ,
208+ withTags ( [ "IAM" ] , {
209+ body : invitePostRequestSchema ,
210+ summary : "Invite a user to the ACM @ UIUC Entra ID tenant." ,
211+ // response: { 202: entraActionResponseSchema },
212+ } ) ,
213+ ) ,
214+ onRequest : fastify . authorizeFromSchema ,
208215 } ,
209216 async ( request , reply ) => {
210217 const emails = request . body . emails ;
@@ -274,15 +281,17 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
274281 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . patch (
275282 "/groups/:groupId" ,
276283 {
277- schema : withTags ( [ "IAM" ] , {
278- params : z . object ( {
279- groupId,
284+ schema : withRoles (
285+ [ AppRoles . IAM_ADMIN ] ,
286+ withTags ( [ "IAM" ] , {
287+ params : z . object ( {
288+ groupId,
289+ } ) ,
290+ body : groupModificationPatchSchema ,
291+ summary : "Update the members of a group." ,
280292 } ) ,
281- body : groupModificationPatchSchema ,
282- } ) ,
283- onRequest : async ( request , reply ) => {
284- await fastify . authorize ( request , reply , [ AppRoles . IAM_ADMIN ] ) ;
285- } ,
293+ ) ,
294+ onRequest : fastify . authorizeFromSchema ,
286295 } ,
287296 async ( request , reply ) => {
288297 const groupId = ( request . params as Record < string , string > ) . groupId ;
@@ -421,15 +430,17 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
421430 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
422431 "/groups/:groupId" ,
423432 {
424- schema : withTags ( [ "IAM" ] , {
425- // response: { 200: entraGroupMembershipListResponse },
426- params : z . object ( {
427- groupId,
433+ schema : withRoles (
434+ [ AppRoles . IAM_ADMIN ] ,
435+ withTags ( [ "IAM" ] , {
436+ // response: { 200: entraGroupMembershipListResponse },
437+ params : z . object ( {
438+ groupId,
439+ } ) ,
440+ summary : "Get the members of a group." ,
428441 } ) ,
429- } ) ,
430- onRequest : async ( request , reply ) => {
431- await fastify . authorize ( request , reply , [ AppRoles . IAM_ADMIN ] ) ;
432- } ,
442+ ) ,
443+ onRequest : fastify . authorizeFromSchema ,
433444 } ,
434445 async ( request , reply ) => {
435446 const groupId = ( request . params as Record < string , string > ) . groupId ;
0 commit comments