-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_worlds.go
607 lines (524 loc) · 20.9 KB
/
handler_worlds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
package main
import (
"encoding/json"
"fmt"
res "github.com/gazebo-web/fuel-server/bundles/common_resources"
"github.com/gazebo-web/fuel-server/globals"
"github.com/gazebo-web/gz-go/v7"
"log"
"mime/multipart"
"net/http"
"os"
"time"
"github.com/gazebo-web/fuel-server/bundles/collections"
"github.com/gazebo-web/fuel-server/bundles/generics"
"github.com/gazebo-web/fuel-server/bundles/users"
"github.com/gazebo-web/fuel-server/bundles/worlds"
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
)
// parseMetadata will check if metadata exists in a request, and return a
// pointer to a worlds.WorldMetadata struct or nil.
func parseWorldMetadata(r *http.Request) *worlds.WorldMetadata {
var metadata *worlds.WorldMetadata
// Check if "metadata" exists
if _, valid := r.Form["metadata"]; valid {
// Process each metadata line
for _, meta := range r.Form["metadata"] {
// Unmarshall the meta data
var unmarshalled worlds.WorldMetadatum
err := json.Unmarshal([]byte(meta), &unmarshalled)
if err != nil {
continue
}
// Create the metadata array, if it is null.
if metadata == nil {
metadata = new(worlds.WorldMetadata)
}
// Store the meta data
*metadata = append(*metadata, unmarshalled)
}
}
return metadata
}
// WorldList returns the list of worlds from a team/user. The returned value
// will be of type "fuel.Worlds".
// It follows the func signature defined by type "searchHandler".
// You can request this method with the following curl request:
//
// curl -k -X GET --url https://localhost:4430/1.0/worlds
//
// or curl -k -X GET --url https://localhost:4430/1.0/worlds.proto
// or curl -k -X GET --url https://localhost:4430/1.0/worlds.json
// or curl -k -X GET --url https://localhost:4430/1.0/{username}/worlds with all the
// above format variants.
func WorldList(p *gz.PaginationRequest, owner *string, order, search string,
user *users.User, tx *gorm.DB, w http.ResponseWriter,
r *http.Request) (interface{}, *gz.PaginationResult, *gz.ErrMsg) {
ws := &worlds.Service{Storage: globals.Storage}
return ws.WorldList(p, tx, owner, order, search, nil, user)
}
// WorldLikeList returns the list of worlds liked by a certain user. The returned value
// will be of type "fuel.Worlds".
// It follows the func signature defined by type "searchHandler".
// You can request this method with the following curl request:
//
// curl -k -X GET --url https://localhost:4430/1.0/{username}/likes/worlds
func WorldLikeList(p *gz.PaginationRequest, owner *string, order, search string,
user *users.User, tx *gorm.DB, w http.ResponseWriter,
r *http.Request) (interface{}, *gz.PaginationResult, *gz.ErrMsg) {
likedBy, em := users.ByUsername(tx, *owner, true)
if em != nil {
return nil, nil, em
}
ws := &worlds.Service{Storage: globals.Storage}
return ws.WorldList(p, tx, owner, order, search, likedBy, user)
}
// WorldFileTree returns the file tree of a single world. The returned value
// will be of type "fuel.WorldFileTree".
// You can request this method with the following curl request:
//
// curl -k -X GET --url https://localhost:4430/1.0/{username}/worlds/{world_name}/{version}/files
func WorldFileTree(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Get the version
version, valid := mux.Vars(r)["version"]
// If the version does not exist
if !valid {
return nil, gz.NewErrorMessage(gz.ErrorWorldNotInRequest)
}
worldProto, em := (&worlds.Service{Storage: globals.Storage}).FileTree(r.Context(), tx, owner, name, version, user)
if em != nil {
return nil, em
}
writeIgnResourceVersionHeader(w, int(worldProto.GetVersion()))
return worldProto, em
}
// WorldIndex returns a single world. The returned value will be of
// type "fuel.World".
// You can request this method with the following curl request:
//
// curl -k -H "Content-Type: application/json" -X GET https://localhost:4430/1.0/{username}/worlds/{world_name}
func WorldIndex(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
ws := &worlds.Service{Storage: globals.Storage}
fuelWorld, em := ws.GetWorldProto(r.Context(), tx, owner, name, user)
if em != nil {
return nil, em
}
writeIgnResourceVersionHeader(w, int(fuelWorld.GetVersion()))
return fuelWorld, nil
}
// WorldRemove removes a world based on owner and name
// You can request this method with the following curl request:
//
// curl -k -X DELETE --url https://localhost:4430/1.0/{username}/worlds/{world_name}
func WorldRemove(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Get the world
world, em := (&worlds.Service{Storage: globals.Storage}).GetWorld(tx, owner, name, user)
if em != nil {
return nil, em
}
// Remove the world from the worlds table
if em := (&worlds.Service{Storage: globals.Storage}).RemoveWorld(r.Context(), tx, owner, name, user); em != nil {
return nil, em
}
// Remove the world from collections
if err := (&collections.Service{}).RemoveAssetFromAllCollections(tx, world.ID); err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorDbDelete, err)
}
// commit the DB transaction
// Note: we commit the TX here on purpose, to be able to detect DB errors
// before writing "data" to ResponseWriter. Once you write data (not headers)
// into it the status code is set to 200 (OK).
if err := tx.Commit().Error; err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorDbDelete, err)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
return nil, nil
}
// WorldLikeCreate likes a world from an owner
// You can request this method with the following cURL request:
//
// curl -k -X POST https://localhost:4430/1.0/{username}/worlds/{world_name}/likes
// --header 'authorization: Bearer <your-jwt-token-here>'
func WorldLikeCreate(owner, worldName string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
_, em := (&worlds.Service{Storage: globals.Storage}).CreateWorldLike(tx, owner, worldName, user)
if em != nil {
return nil, em
}
// commit the DB transaction
// Note: we commit the TX here on purpose, to be able to detect DB errors
// before writing "data" to ResponseWriter. Once you write data (not headers)
// into it the status code is set to 200 (OK).
if err := tx.Commit().Error; err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorDbSave, err)
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
return nil, nil
}
// WorldLikeRemove removes a like from a world.
// You can request this method with the following cURL request:
//
// curl -k -X DELETE https://localhost:4430/1.0/{username}/worlds/{world_name}/likes
// --header 'authorization: Bearer <your-jwt-token-here>'
func WorldLikeRemove(owner, worldName string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
_, em := (&worlds.Service{Storage: globals.Storage}).RemoveWorldLike(tx, owner, worldName, user)
if em != nil {
return nil, em
}
// commit the DB transaction
// Note: we commit the TX here on purpose, to be able to detect DB errors
// before writing "data" to ResponseWriter. Once you write data (not headers)
// into it the status code is set to 200 (OK).
if err := tx.Commit().Error; err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorDbSave, err)
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
return nil, nil
}
// WorldIndividualFileDownload downloads an individual world file
// based on owner, world name, and version.
// You can request this method with the following curl request:
//
// curl -k -X GET --url https://localhost:4430/1.0/{username}/worlds/{world_name}/{version}/files/{file-path}
//
// eg. curl -k -X GET --url https://localhost:4430/1.0/{username}/worlds/{world_name}/tip/files/model.config
func WorldIndividualFileDownload(owner, worldName string, user *users.User,
tx *gorm.DB, w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
s := &worlds.Service{Storage: globals.Storage}
return IndividualFileDownload(s, owner, worldName, user, tx, w, r)
}
// WorldZip returns a single world as a zip file
// You can request this method with the following curl request:
//
// curl -k -X GET --url https://localhost:4430/1.0/{username}/worlds/{world-name}/{version}/{world-name}.zip
func WorldZip(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Get the world version
version, valid := mux.Vars(r)["version"]
// If the version does not exist
if !valid {
version = ""
}
svc := &worlds.Service{Storage: globals.Storage}
zipGetter := res.DownloadZipFile
linkRequested := isLinkRequested(r)
if linkRequested {
zipGetter = res.GetZipLink(svc.Storage)
}
world, link, ver, em := svc.DownloadZip(r.Context(), tx, owner, name, version, user, r.UserAgent(), zipGetter)
if em != nil {
return nil, em
}
// commit the DB transaction
// Note: we commit the TX here on purpose, to be able to detect DB errors
// before writing "data" to ResponseWriter.
if err := tx.Commit().Error; err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorZipNotAvailable, err)
}
// If a link was requested, fuel will return a link to a cloud storage where the client can perform a subsequent request
// to download the resource. If a link was not requested or if it is not included, it will serve the file directly to the client.
if err := serveFileOrLink(w, r, linkRequested, *link, world, ver); err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorZipNotAvailable, err)
}
return nil, nil
}
// ReportWorldCreate reports a model.
// You can request this method with the following curl request:
//
// curl -k -X POST --url https://localhost:4430/1.0/{username}/worlds/{model-name}/report
func ReportWorldCreate(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Parse form's values
if err := r.ParseMultipartForm(0); err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorForm, err)
}
// Delete temporary files from r.ParseMultipartForm(0)
defer func(form *multipart.Form) {
err := form.RemoveAll()
if err != nil {
log.Println("Failed to close form:", err)
}
}(r.MultipartForm)
var createWorldReport worlds.CreateReport
if em := ParseStruct(&createWorldReport, r, true); em != nil {
return nil, em
}
if _, em := (&worlds.Service{Storage: globals.Storage}).CreateWorldReport(tx, owner, name, createWorldReport.Reason); em != nil {
return nil, em
}
if err := tx.Commit().Error; err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorDbSave, err)
}
if _, em := generics.SendReportEmail(name, owner, "worlds", createWorldReport.Reason, r); em != nil {
return nil, em
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
return nil, nil
}
// createWorldFn is a callback func that "creation handlers" will pass to doCreateWorld.
// It is expected that createFn will have the real logic for the world creation.
type createWorldFn func(tx *gorm.DB, jwtUser *users.User, w http.ResponseWriter, r *http.Request) (*worlds.World, *gz.ErrMsg)
// doCreateWorld provides the pre and post steps needed to create or clone a world.
// Handlers should invoke this function and pass a createWorldFn callback.
func doCreateWorld(tx *gorm.DB, cb createWorldFn, w http.ResponseWriter, r *http.Request) (*worlds.World, *gz.ErrMsg) {
// Extract the owner of the new world from the request.
jwtUser, ok, errMsg := getUserFromJWT(tx, r)
if !ok {
return nil, &errMsg
}
// invoke the actual createWorldFn (the callback function)
world, em := cb(tx, jwtUser, w, r)
if em != nil {
return nil, em
}
// commit the DB transaction
// Note: we commit the TX here on purpose, to be able to detect DB errors
// before writing "data" to ResponseWriter. Once you write data (not headers)
// into it the status code is set to 200 (OK).
if err := tx.Commit().Error; err != nil {
if err := os.RemoveAll(*world.Location); err != nil {
gz.LoggerFromContext(r.Context()).Error("Unable to remove directory: ", *world.Location)
}
return nil, gz.NewErrorMessageWithBase(gz.ErrorNoDatabase, err)
}
infoStr := "A new world has been created:" +
"\n\t name: " + *world.Name +
"\n\t owner: " + *world.Owner +
"\n\t creator: " + *world.Creator +
"\n\t uuid: " + *world.UUID +
"\n\t location: " + *world.Location +
"\n\t UploadDate: " + world.UploadDate.UTC().Format(time.RFC3339) +
"\n\t Tags:"
for _, t := range world.Tags {
infoStr += *t.Name
}
gz.LoggerFromRequest(r).Info(infoStr)
// TODO: we should NOT be returning the DB world (including ID) to users.
return world, nil
}
// WorldCreate creates a new world based on input form. It return a world.World or an error.
// You can request this method with the following cURL request:
//
// curl -k -X POST -F name=my_world -F license=1
// -F file=@<full-path-to-file>
// https://localhost:4430/1.0/worlds --header 'authorization: Bearer <your-jwt-token-here>'
func WorldCreate(tx *gorm.DB, w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
if err := r.ParseMultipartForm(0); err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorForm, err)
}
// Delete temporary files from r.ParseMultipartForm(0)
defer func(form *multipart.Form) {
err := form.RemoveAll()
if err != nil {
log.Println("Failed to close form:", err)
}
}(r.MultipartForm)
// worlds.CreateWorld is the input form
var cw worlds.CreateWorld
if em := ParseStruct(&cw, r, true); em != nil {
return nil, em
}
createFn := func(tx *gorm.DB, jwtUser *users.User, w http.ResponseWriter, r *http.Request) (*worlds.World, *gz.ErrMsg) {
owner := cw.Owner
if owner != "" {
// Ensure the passed in name exists before moving forward
_, em := users.OwnerByName(tx, owner, true)
if em != nil {
return nil, em
}
} else {
owner = *jwtUser.Username
}
// Get a new UUID and world folder
uuidStr, worldPath, err := users.NewUUID(owner, "worlds")
if err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorCreatingDir, err)
}
// move files from multipart form into new world's folder
_, em := populateTmpDir(r, true, worldPath)
if em != nil {
if err := os.RemoveAll(worldPath); err != nil {
gz.LoggerFromContext(r.Context()).Error("Unable to remove directory: ", worldPath)
}
return nil, em
}
// Create the world via the Worlds Service
ws := &worlds.Service{Storage: globals.Storage}
world, em := ws.CreateWorld(r.Context(), tx, cw, uuidStr, worldPath, jwtUser)
if em != nil {
if err := os.RemoveAll(worldPath); err != nil {
gz.LoggerFromContext(r.Context()).Error("Unable to remove directory: ", worldPath)
}
return nil, em
}
return world, nil
}
return doCreateWorld(tx, createFn, w, r)
}
// WorldClone clones a world. Cloning a world means internally creating a new repository
// (git clone) under the current username.
// You can request this method with the following curl request:
//
// curl -k -X POST --url https://localhost:4430/1.0/{other-username}/worlds/{world-name}/clone
// --header 'authorization: Bearer <your-jwt-token-here>'
func WorldClone(owner, name string, ignored *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Parse form's values and files. https://golang.org/pkg/net/http/#Request.ParseMultipartForm
if err := r.ParseMultipartForm(0); err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorForm, err)
}
// Delete temporary files from r.ParseMultipartForm(0)
defer func(form *multipart.Form) {
err := form.RemoveAll()
if err != nil {
log.Println("Failed to close form:", err)
}
}(r.MultipartForm)
// worlds.CloneWorld is the input form
var cw worlds.CloneWorld
if em := ParseStruct(&cw, r, true); em != nil {
return nil, em
}
createFn := func(tx *gorm.DB, jwtUser *users.User, w http.ResponseWriter, r *http.Request) (*worlds.World, *gz.ErrMsg) {
// Ask the Models Service to clone the model
ws := &worlds.Service{Storage: globals.Storage}
clone, em := ws.CloneWorld(r.Context(), tx, owner, name, cw, jwtUser)
if em != nil {
return nil, em
}
return clone, nil
}
return doCreateWorld(tx, createFn, w, r)
}
// WorldUpdate modifies an existing world.
// You can request this method with the following cURL request:
//
// curl -k -X PATCH -d '{"description":"New Description", "tags":"tag1,tag2"}'
// https://localhost:4430/1.0/{username}/worlds/{world-name} -H "Content-Type: application/json"
// -H 'Authorization: Bearer <A_VALID_AUTH0_JWT_TOKEN>'
func WorldUpdate(owner, worldName string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
err := r.ParseMultipartForm(0)
if err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorUnexpected, err)
}
// Delete temporary files from r.ParseMultipartForm(0)
defer func(form *multipart.Form) {
err := form.RemoveAll()
if err != nil {
log.Println("Failed to close form:", err)
}
}(r.MultipartForm)
// worlds.UpdateWorld is the input form
var uw worlds.UpdateWorld
if errMsg := ParseStruct(&uw, r, true); errMsg != nil {
return nil, errMsg
}
if uw.IsEmpty() && r.MultipartForm == nil {
return nil, gz.NewErrorMessage(gz.ErrorFormInvalidValue)
}
// If the user has also sent files, then update the world's version
var newFilesPath *string
if r.MultipartForm != nil && len(getRequestFiles(r)) > 0 {
// first, populate files into tmp dir to avoid overriding world
// files in case of error.
tmpDir, err := os.MkdirTemp("", worldName)
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
gz.LoggerFromContext(r.Context()).Error("Unable to remove directory: ", tmpDir)
}
}()
if err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorRepo, err)
}
if _, errMsg := populateTmpDir(r, true, tmpDir); errMsg != nil {
return nil, errMsg
}
newFilesPath = &tmpDir
}
uw.Metadata = parseWorldMetadata(r)
world, em := (&worlds.Service{Storage: globals.Storage}).UpdateWorld(r.Context(), tx, owner, worldName,
uw.Description, uw.Tags, newFilesPath, uw.Private, user, uw.Metadata)
if em != nil {
return nil, em
}
infoStr := "World has been updated:" +
"\n\t name: " + *world.Name +
"\n\t owner: " + *world.Owner +
"\n\t uuid: " + *world.UUID +
"\n\t location: " + *world.Location +
"\n\t UploadDate: " + world.UploadDate.UTC().Format(time.RFC3339) +
"\n\t Tags:"
for _, t := range world.Tags {
infoStr += *t.Name
}
gz.LoggerFromRequest(r).Info(infoStr)
// Encode world into a protobuf message
fuelWorld := (&worlds.Service{Storage: globals.Storage}).WorldToProto(world)
return &fuelWorld, nil
}
// WorldModelReferences returns the list of external models referenced by a world.
// The returned value will be of type "worlds.ModelIncludes"
// You can request this method with the following curl request:
//
// curl -k --url https://localhost:4430/1.0/{username}/worlds/{world_name}/{version}/{world_name}/modelrefs
func WorldModelReferences(owner, name string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Get the world version
version, valid := mux.Vars(r)["version"]
// If the version does not exist
if !valid {
version = ""
}
// Prepare pagination
pr, em := gz.NewPaginationRequest(r)
if em != nil {
return nil, em
}
ws := &worlds.Service{Storage: globals.Storage}
refs, pagination, em := ws.GetModelReferences(r.Context(), pr, tx, owner, name,
version, user)
if em != nil {
return nil, em
}
err := gz.WritePaginationHeaders(*pagination, w, r)
if err != nil {
return nil, gz.NewErrorMessageWithBase(gz.ErrorUnexpected, err)
}
return refs, nil
}
// WorldTransfer transfer ownership of a world to an organization. The source
// owner must have write permissions on the destination organization
//
// curl -k -X POST -H "Content-Type: application/json" http://localhost:8000/1.0/{username}/worlds/{worldname}/transfer --header "Private-Token: {private-token}" -d '{"destOwner":"{destination_owner_name"}'
//
// \todo Support transfer of worlds to owners other users and organizations.
// This will require some kind of email notifcation to the destination and
// acceptance form.
func WorldTransfer(sourceOwner, worldName string, user *users.User, tx *gorm.DB,
w http.ResponseWriter, r *http.Request) (interface{}, *gz.ErrMsg) {
// Read the request and check permissions.
transferAsset, em := processTransferRequest(sourceOwner, tx, r)
if em != nil {
return nil, em
}
// Get the world
ws := &worlds.Service{Storage: globals.Storage}
world, em := ws.GetWorld(tx, sourceOwner, worldName, user)
if em != nil {
extra := fmt.Sprintf("World [%s] not found", worldName)
return nil, gz.NewErrorMessageWithArgs(gz.ErrorNameNotFound, em.BaseError, []string{extra})
}
if em := transferMoveResource(tx, world, sourceOwner, transferAsset.DestOwner); em != nil {
return nil, em
}
tx.Save(&world)
return &world, nil
}