@@ -315,6 +315,46 @@ func Startup(ctx context.Context, js jetstream.JetStream, logger *zap.Logger, po
315315 }
316316 }
317317
318+ // POST /resource/{id}/share: share ownership of the resource with another user
319+ r .HandleFunc ("/resource/{id}/share/{userid}" , func (writer http.ResponseWriter , request * http.Request ) {
320+ if stop := handleCors (writer , request ); stop {
321+ return
322+ }
323+
324+ if request .Method != "POST" {
325+ http .Error (writer , "Method Not Allowed" , http .StatusMethodNotAllowed )
326+ return
327+ }
328+
329+ ctx := getCorrelationId (ctx , & request .Header , nil )
330+ logRequest (logger , request , ctx )
331+
332+ vars := mux .Vars (request )
333+ id := & glue.StateId {
334+ Id : strings .TrimSpace (vars ["id" ]),
335+ }
336+
337+ // verify the user is authorized to access the resource
338+ ctx , done := authorize (writer , request , config , ctx , rm , id , logger , true , auth .Owner )
339+ if done {
340+ return
341+ }
342+
343+ r , err := rm .DiscoverResource (ctx , id , logger , true )
344+ if err != nil {
345+ logger .Error ("Failed to discover resource" , zap .Error (err ))
346+ http .Error (writer , "Not Found" , http .StatusNotFound )
347+ }
348+
349+ newUser := strings .TrimSpace (vars ["userid" ])
350+
351+ err = r .ShareOwnership (auth .UserId (newUser ), auth .GetUserFromContext (ctx ), true )
352+ if err != nil {
353+ logger .Error ("Failed to share ownership" , zap .Error (err ))
354+ http .Error (writer , "Internal Server Error" , http .StatusInternalServerError )
355+ }
356+ })
357+
318358 // GET /entity/{name}/{id}
319359 // get an entity state and status
320360 // PUT /entity/{name}/{id}
0 commit comments