@@ -94,12 +94,11 @@ func (controller *AdminController) AddAdminToOrg(ctx shared.Context) error {
9494 orgID := ctx .Param ("orgID" )
9595 parsedOrgID , err := uuid .Parse (orgID )
9696 if err != nil {
97- return echo .NewHTTPError (400 , "missing or invalid user id" )
97+ return echo .NewHTTPError (400 , "missing or invalid org id" )
9898 }
9999
100- user := ctx .Param ("userID" )
101-
102- if ! utils .IsEmail (user ) {
100+ user , err := extractMailFromRequest (ctx )
101+ if err != nil {
103102 return echo .NewHTTPError (400 , "user is not a valid mail address" )
104103 }
105104
@@ -124,43 +123,32 @@ func (controller *AdminController) AddAdminToOrg(ctx shared.Context) error {
124123 if err != nil {
125124 return echo .NewHTTPError (500 , "could not add admin to organization" ).WithInternal (err )
126125 }
127- return ctx .JSON (201 , nil )
126+ return ctx .NoContent (201 )
128127}
129128
130129func (controller * AdminController ) RevokeAdmin (ctx shared.Context ) error {
131130 orgID := ctx .Param ("orgID" )
132131 parsedOrgID , err := uuid .Parse (orgID )
133132 if err != nil {
134- return echo .NewHTTPError (400 , "missing or invalid user id" )
133+ return echo .NewHTTPError (400 , "missing or invalid org id" )
135134 }
136135
137- user := ctx .Param ("userID" )
138-
139- if ! utils . IsEmail ( user ) {
140- return echo .NewHTTPError (400 , "user is not a valid mail address " )
136+ userID := ctx .Param ("userID" )
137+ parsedUserID , err := uuid . Parse ( userID )
138+ if err != nil {
139+ return echo .NewHTTPError (400 , "missing or invalid user id " )
141140 }
142141
143142 authAdminClient := shared .GetAuthAdminClient (ctx )
144143 if authAdminClient == nil {
145144 return echo .NewHTTPError (500 , "could not get auth client" )
146145 }
147- userID , err := controller .adminService .GetUserIDFromMail (context .Background (), authAdminClient , user )
148- if err != nil {
149- switch err .Error () {
150- case dtos .CouldNotFindUserWithMail :
151- return echo .NewHTTPError (404 , "could not find a user associated with this email" )
152- case dtos .CouldNotFindDefinitiveUserWithMail :
153- return echo .NewHTTPError (400 , "could not find a definitive user associated with this email" )
154- default :
155- return echo .NewHTTPError (500 , "could not determine user based on email" )
156- }
157- }
158146
159- err = controller .adminService .RevokeAdminFromOrg (context .Background (), parsedOrgID , userID )
147+ err = controller .adminService .RevokeAdminFromOrg (context .Background (), parsedOrgID , parsedUserID )
160148 if err != nil {
161149 return echo .NewHTTPError (500 , "could not revoke admin role from user" )
162150 }
163- return ctx .JSON (204 , nil )
151+ return ctx .NoContent (204 )
164152}
165153
166154// checkCooldown reads the config DB for the last trigger time and returns an
@@ -420,3 +408,15 @@ func (controller *AdminController) runDaemonSSE(
420408 // Return nil so Echo does not try to write again.
421409 return nil
422410}
411+
412+ func extractMailFromRequest (ctx shared.Context ) (string , error ) {
413+ userID , err := shared .GetURLDecodedParam (ctx , "userMail" )
414+ if err != nil {
415+ return "" , err
416+ }
417+
418+ if ! utils .IsEmail (userID ) {
419+ return "" , fmt .Errorf ("mail is invalid" )
420+ }
421+ return userID , nil
422+ }
0 commit comments