[ARVADOS] updated: 1.3.0-3126-g7e358c012

Git user git at public.arvados.org
Mon Sep 14 21:14:55 UTC 2020


Summary of changes:
 .../app/controllers/application_controller.rb      |  2 +-
 doc/api/methods/links.html.textile.liquid          | 19 +++++--------
 services/api/app/models/arvados_model.rb           |  7 ++++-
 services/api/app/models/database_seeds.rb          |  2 ++
 .../20200914203202_public_favorites_project.rb     | 20 +++++++++++++
 services/api/db/structure.sql                      |  3 +-
 services/api/lib/current_api_client.rb             | 33 ++++++++++++++++++++++
 7 files changed, 71 insertions(+), 15 deletions(-)
 create mode 100644 services/api/db/migrate/20200914203202_public_favorites_project.rb

       via  7e358c01226d55a44ca7b6224f9c33c38510572b (commit)
      from  3c893d29ad7a9acda0c25b47fd0c9ba5a4a5193a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 7e358c01226d55a44ca7b6224f9c33c38510572b
Author: Peter Amstutz <peter.amstutz at curii.com>
Date:   Mon Sep 14 16:42:07 2020 -0400

    16811: Add "Public project" for storing favorites.
    
    Workbench and documentation updated for "public favorites" group
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index c626e97f1..cf4bfa8c5 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -927,7 +927,7 @@ class ApplicationController < ActionController::Base
   helper_method :my_starred_projects
   def my_starred_projects user
     return if defined?(@starred_projects) && @starred_projects
-    links = Link.filter([['tail_uuid', 'in', ["#{Rails.configuration.ClusterID}-j7d0g-fffffffffffffff", user.uuid]],
+    links = Link.filter([['owner_uuid', 'in', ["#{Rails.configuration.ClusterID}-j7d0g-publicfavorites", user.uuid]],
                          ['link_class', '=', 'star'],
                          ['head_uuid', 'is_a', 'arvados#group']]).with_count("none").select(%w(head_uuid))
     uuids = links.collect { |x| x.head_uuid }
diff --git a/doc/api/methods/links.html.textile.liquid b/doc/api/methods/links.html.textile.liquid
index 98ff23ffb..c71105c74 100644
--- a/doc/api/methods/links.html.textile.liquid
+++ b/doc/api/methods/links.html.textile.liquid
@@ -43,32 +43,27 @@ h3. star
 
 A **star** link is a shortcut to a project that is displayed in the user interface (Workbench) as "favorites".  Users can mark their own favorites (implemented by creating or deleting **star** links).
 
-An admin can also create **star** links owned by the system user, with @tail_uuid@ as the "All Users" group.  These are "public favorites" that will be displayed to all users that have permission to read the project that has been favorited.  Note: setting a public favorite also requires creating a @can_read@ permission link from @All Users@ to the 'star' link record.
+An admin can also create **star** links owned by the "Public favorites" project.  These are favorites will be displayed to all users that have permission to read the project that has been favorited.
 
 The schema for a star link is:
 
 table(table table-bordered table-condensed).
 |_. Field|_. Value|_. Description|
-|tail_uuid|user or group uuid|Either the user that owns the favorite, or the "All Users" group for public favorites.|
+|owner_uuid|user or group uuid|Either the user that owns the favorite, or the "Public favorites" group.|
+|tail_uuid|user or group uuid|Should be the same as owner_uuid|
 |head_uuid|project uuid|The project being favorited|
 |link_class|string of value "star"|Indicates this represents a link to a user favorite|
 
 h4. Creating a public favorite
 
- at tail_uuid@ is either an individual user, or the "All Users" group.  The @head_uuid@ is the project being favorited.
+ at owner_uuid@ is either an individual user, or the "Public favorites" group.  The @head_uuid@ is the project being favorited.
 
 <pre>
 $ linkuuid=$(arv --format=uuid link create --link '{
     "link_class": "star",
-    "owner_uuid": "zzzzz-tpzed-000000000000000",
-    "tail_uuid": "zzzzz-j7d0g-fffffffffffffff",
+    "owner_uuid": "zzzzz-j7d0g-publicfavorites",
+    "tail_uuid": "zzzzz-j7d0g-publicfavorites",
     "head_uuid":  "zzzzz-j7d0g-theprojectuuid"}')
-
-$ arv link create --link '{
-    "link_class": "permission",
-    "name": "can_read",
-    "tail_uuid": "zzzzz-j7d0g-fffffffffffffff",
-    "head_uuid":  "zzzzz-o0j2j-'$linkuuid'"}'
 </pre>
 
 h4. Removing a favorite
@@ -84,7 +79,7 @@ To list all 'star' links that will be displayed for a user:
 <pre>
 $ arv link list --filters '[
   ["link_class", "=", "star"],
-  ["tail_uuid", "in", ["zzzzz-j7d0g-fffffffffffffff", "zzzzz-tpzed-currentuseruuid"]]]'
+  ["tail_uuid", "in", ["zzzzz-j7d0g-publicfavorites", "zzzzz-tpzed-currentuseruuid"]]]'
 </pre>
 
 h3. tag
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 6fb8ff2b3..07bedebfa 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -627,7 +627,12 @@ class ArvadosModel < ApplicationRecord
   end
 
   def permission_to_destroy
-    permission_to_update
+    if [system_user_uuid, system_group_uuid, anonymous_group_uuid,
+        anonymous_user_uuid, public_project_uuid].include? uuid
+      false
+    else
+      permission_to_update
+    end
   end
 
   def maybe_update_modified_by_fields
diff --git a/services/api/app/models/database_seeds.rb b/services/api/app/models/database_seeds.rb
index d7c5e04df..abfb672af 100644
--- a/services/api/app/models/database_seeds.rb
+++ b/services/api/app/models/database_seeds.rb
@@ -14,6 +14,8 @@ class DatabaseSeeds
     anonymous_group_read_permission
     anonymous_user
     system_root_token_api_client
+    public_project_group
+    public_project_read_permission
     empty_collection
     refresh_permissions
     refresh_trashed
diff --git a/services/api/db/migrate/20200914203202_public_favorites_project.rb b/services/api/db/migrate/20200914203202_public_favorites_project.rb
new file mode 100644
index 000000000..0718778dd
--- /dev/null
+++ b/services/api/db/migrate/20200914203202_public_favorites_project.rb
@@ -0,0 +1,20 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class PublicFavoritesProject < ActiveRecord::Migration[5.2]
+  include CurrentApiClient
+  def change
+    act_as_system_user do
+      public_project_group
+      public_project_read_permission
+      Link.where(link_class: "star",
+                 owner_uuid: system_user_uuid,
+                 tail_uuid: all_users_group_uuid).each do |ln|
+        ln.owner_uuid = public_project_uuid
+        ln.tail_uuid = public_project_uuid
+        ln.save!
+      end
+    end
+  end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index 83987d051..a5740834c 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -3197,6 +3197,7 @@ INSERT INTO "schema_migrations" (version) VALUES
 ('20190809135453'),
 ('20190905151603'),
 ('20200501150153'),
-('20200602141328');
+('20200602141328'),
+('20200914203202');
 
 
diff --git a/services/api/lib/current_api_client.rb b/services/api/lib/current_api_client.rb
index cfdae0bdd..dc40f158e 100644
--- a/services/api/lib/current_api_client.rb
+++ b/services/api/lib/current_api_client.rb
@@ -9,6 +9,8 @@ $anonymous_user = nil
 $anonymous_group = nil
 $anonymous_group_read_permission = nil
 $empty_collection = nil
+$public_project_group = nil
+$public_project_group_read_permission = nil
 
 module CurrentApiClient
   def current_user
@@ -65,6 +67,12 @@ module CurrentApiClient
      'anonymouspublic'].join('-')
   end
 
+  def public_project_uuid
+    [Rails.configuration.ClusterID,
+     Group.uuid_prefix,
+     'publicfavorites'].join('-')
+  end
+
   def system_user
     $system_user = check_cache $system_user do
       real_current_user = Thread.current[:user]
@@ -189,6 +197,31 @@ module CurrentApiClient
     end
   end
 
+  def public_project_group
+    $public_project_group = check_cache $public_project_group do
+      act_as_system_user do
+        ActiveRecord::Base.transaction do
+          Group.where(uuid: public_project_uuid).
+            first_or_create!(group_class: "project",
+                             name: "Public favorites",
+                             description: "Public favorites")
+        end
+      end
+    end
+  end
+
+  def public_project_read_permission
+    $public_project_group_read_permission =
+        check_cache $public_project_group_read_permission do
+      act_as_system_user do
+        Link.where(tail_uuid: anonymous_group.uuid,
+                   head_uuid: public_project_group.uuid,
+                   link_class: "permission",
+                   name: "can_read").first_or_create!
+      end
+    end
+  end
+
   def system_root_token_api_client
     $system_root_token_api_client = check_cache $system_root_token_api_client do
       act_as_system_user do

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list