16811: Fix public favorites.
[arvados-workbench2.git] / src / services / favorite-service / favorite-service.ts
index fbb2a52f448920e8b34cccaac6219709193534c7..37c1380b6a6856eea91f43b17784e976601782d4 100644 (file)
@@ -23,20 +23,38 @@ export class FavoriteService {
     ) { }
 
     create(data: { userUuid: string; resource: { uuid: string; name: string } }) {
-        return this.linkService.create({
-            ownerUuid: data.userUuid,
+        const l = this.linkService.create({
+            // If this is for the all users group, it must be owned by
+            // the system user.
+            ownerUuid: (data.userUuid.substr(-22) === "-j7d0g-fffffffffffffff" ?
+                data.userUuid.substr(0, 5) + "-tpzed-000000000000000"
+                : data.userUuid),
             tailUuid: data.userUuid,
             headUuid: data.resource.uuid,
             linkClass: LinkClass.STAR,
             name: data.resource.name
         });
+
+        if (data.userUuid.substr(-22) === "-j7d0g-fffffffffffffff") {
+            // If this is for the all users group, we need to create a
+            // permission link as well.
+            l.then(result =>
+                this.linkService.create({
+                    tailUuid: data.userUuid,
+                    headUuid: result.uuid,
+                    linkClass: LinkClass.PERMISSION,
+                    name: "can_read"
+                }));
+        }
+
+        return l;
     }
 
     delete(data: { userUuid: string; resourceUuid: string; }) {
         return this.linkService
             .list({
                 filters: new FilterBuilder()
-                    .addEqual('owner_uuid', data.userUuid)
+                    .addEqual('tail_uuid', data.userUuid)
                     .addEqual('head_uuid', data.resourceUuid)
                     .addEqual('link_class', LinkClass.STAR)
                     .getFilters()
@@ -75,7 +93,7 @@ export class FavoriteService {
             .list({
                 filters: new FilterBuilder()
                     .addIn("head_uuid", resourceUuids)
-                    .addEqual("owner_uuid", userUuid)
+                    .addEqual("tail_uuid", userUuid)
                     .addEqual("link_class", LinkClass.STAR)
                     .getFilters()
             })