[ARVADOS] updated: 9fcabe977798468f2ee896b5f5c1ba6d80703341

git at public.curoverse.com git at public.curoverse.com
Tue Feb 3 13:59:52 EST 2015


Summary of changes:
 ...203180223_set_group_class_on_anonymous_group.rb |  14 +++
 services/api/db/structure.sql                      |   4 +-
 services/api/lib/current_api_client.rb             | 130 ++++++++++-----------
 3 files changed, 77 insertions(+), 71 deletions(-)
 create mode 100644 services/api/db/migrate/20150203180223_set_group_class_on_anonymous_group.rb

       via  9fcabe977798468f2ee896b5f5c1ba6d80703341 (commit)
       via  9ea36303cc851a5ffa8d61695c8b4ed14e8954d5 (commit)
      from  89a8208e6f88de78991c654ce001b26519b99f0c (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 9fcabe977798468f2ee896b5f5c1ba6d80703341
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Feb 3 13:56:32 2015 -0500

    2659: Reload seeds (system_user et al.) after cache is cleared. Be more careful about errors while creating seeds.

diff --git a/services/api/lib/current_api_client.rb b/services/api/lib/current_api_client.rb
index 729806f..404de4f 100644
--- a/services/api/lib/current_api_client.rb
+++ b/services/api/lib/current_api_client.rb
@@ -54,48 +54,43 @@ module CurrentApiClient
   end
 
   def system_user
-    if not $system_user
+    $system_user = check_cache $system_user do
       real_current_user = Thread.current[:user]
-      Thread.current[:user] = User.new(is_admin: true,
-                                       is_active: true,
-                                       uuid: system_user_uuid)
-      $system_user = User.where('uuid=?', system_user_uuid).first
-      if !$system_user
-        $system_user = User.new(uuid: system_user_uuid,
-                                is_active: true,
-                                is_admin: true,
-                                email: 'root',
-                                first_name: 'root',
-                                last_name: '')
-        $system_user.save!
-        $system_user.reload
+      begin
+        Thread.current[:user] = User.new(is_admin: true,
+                                         is_active: true,
+                                         uuid: system_user_uuid)
+        User.where('uuid=?', system_user_uuid).
+          first_or_create!(is_active: true,
+                           is_admin: true,
+                           email: 'root',
+                           first_name: 'root',
+                           last_name: '')
+      ensure
+        Thread.current[:user] = real_current_user
       end
-      Thread.current[:user] = real_current_user
     end
-    $system_user
   end
 
   def system_group
-    if not $system_group
+    $system_group = check_cache $system_group do
       act_as_system_user do
         ActiveRecord::Base.transaction do
-          $system_group = Group.
-            where(uuid: system_group_uuid).first_or_create do |g|
-            g.update_attributes(name: "System group",
-                                description: "System group")
+          Group.where(uuid: system_group_uuid).
+            first_or_create!(name: "System group",
+                             description: "System group") do |g|
             User.all.collect(&:uuid).each do |user_uuid|
-              Link.create(link_class: 'permission',
-                          name: 'can_manage',
-                          tail_kind: 'arvados#group',
-                          tail_uuid: system_group_uuid,
-                          head_kind: 'arvados#user',
-                          head_uuid: user_uuid)
+              Link.create!(link_class: 'permission',
+                           name: 'can_manage',
+                           tail_kind: 'arvados#group',
+                           tail_uuid: system_group_uuid,
+                           head_kind: 'arvados#user',
+                           head_uuid: user_uuid)
             end
           end
         end
       end
     end
-    $system_group
   end
 
   def all_users_group_uuid
@@ -105,19 +100,16 @@ module CurrentApiClient
   end
 
   def all_users_group
-    if not $all_users_group
+    $all_users_group = check_cache $all_users_group do
       act_as_system_user do
         ActiveRecord::Base.transaction do
-          $all_users_group = Group.
-            where(uuid: all_users_group_uuid).first_or_create do |g|
-            g.update_attributes(name: "All users",
-                                description: "All users",
-                                group_class: "role")
-          end
+          Group.where(uuid: all_users_group_uuid).
+            first_or_create!(name: "All users",
+                             description: "All users",
+                             group_class: "role")
         end
       end
     end
-    $all_users_group
   end
 
   def act_as_system_user
@@ -141,50 +133,35 @@ module CurrentApiClient
   end
 
   def anonymous_group
-    if not $anonymous_group
+    $anonymous_group = check_cache $anonymous_group do
       act_as_system_user do
         ActiveRecord::Base.transaction do
-          $anonymous_group = Group.
-          where(uuid: anonymous_group_uuid).first_or_create do |g|
-            g.update_attributes(group_class: "role",
-                                name: "Anonymous users",
-                                description: "Anonymous users")
-          end
+          Group.where(uuid: anonymous_group_uuid).
+            first_or_create!(group_class: "role",
+                             name: "Anonymous users",
+                             description: "Anonymous users")
         end
       end
     end
-    $anonymous_group
   end
 
   def anonymous_user
-    if not $anonymous_user
+    $anonymous_user = check_cache $anonymous_user do
       act_as_system_user do
-        $anonymous_user = User.where('uuid=?', anonymous_user_uuid).first
-        if !$anonymous_user
-          $anonymous_user = User.new(uuid: anonymous_user_uuid,
-                                     is_active: false,
-                                     is_admin: false,
-                                     email: 'anonymouspublic',
-                                     first_name: 'anonymouspublic',
-                                     last_name: 'anonymouspublic')
-          $anonymous_user.save!
-          $anonymous_user.reload
-        end
-
-        group_perms = Link.where(tail_uuid: anonymous_user_uuid,
-                                 head_uuid: anonymous_group_uuid,
-                                 link_class: 'permission',
-                                 name: 'can_read')
-
-        if !group_perms.any?
-          group_perm = Link.create!(tail_uuid: anonymous_user_uuid,
-                                    head_uuid: anonymous_group_uuid,
-                                    link_class: 'permission',
-                                    name: 'can_read')
-        end
+        anon = User.where('uuid=?', anonymous_user_uuid).
+          first_or_create!(is_active: false,
+                           is_admin: false,
+                           email: 'anonymous',
+                           first_name: 'Anonymous',
+                           last_name: '')
+        Link.where(tail_uuid: anonymous_user_uuid,
+                   head_uuid: anonymous_group_uuid,
+                   link_class: 'permission',
+                   name: 'can_read').
+          first_or_create!
+        anon
       end
     end
-    $anonymous_user
   end
 
   def empty_collection_uuid
@@ -192,7 +169,7 @@ module CurrentApiClient
   end
 
   def empty_collection
-    if not $empty_collection
+    $empty_collection = check_cache $empty_collection do
       act_as_system_user do
         ActiveRecord::Base.transaction do
           $empty_collection = Collection.
@@ -201,6 +178,18 @@ module CurrentApiClient
         end
       end
     end
-    $empty_collection
+  end
+
+  private
+
+  # If the given value is nil, or the cache has been cleared since it
+  # was set, yield. Otherwise, return the given value.
+  def check_cache value
+    Rails.cache.fetch "CurrentApiClient.$globals" do
+      value = nil
+      true
+    end
+    return value unless value.nil?
+    yield
   end
 end

commit 9ea36303cc851a5ffa8d61695c8b4ed14e8954d5
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Feb 3 13:34:34 2015 -0500

    2659: Set group_class=role on anonymous group, change name to "Anonymous users".

diff --git a/services/api/db/migrate/20150203180223_set_group_class_on_anonymous_group.rb b/services/api/db/migrate/20150203180223_set_group_class_on_anonymous_group.rb
new file mode 100644
index 0000000..d182006
--- /dev/null
+++ b/services/api/db/migrate/20150203180223_set_group_class_on_anonymous_group.rb
@@ -0,0 +1,14 @@
+class SetGroupClassOnAnonymousGroup < ActiveRecord::Migration
+  include CurrentApiClient
+  def up
+    act_as_system_user do
+      anonymous_group.update_attributes group_class: 'role', name: 'Anonymous users', description: 'Anonymous users'
+    end
+  end
+
+  def down
+    act_as_system_user do
+      anonymous_group.update_attributes group_class: nil, name: 'Anonymous group', description: 'Anonymous group'
+    end
+  end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index e1b9702..5d9e3e5 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -2316,4 +2316,6 @@ INSERT INTO schema_migrations (version) VALUES ('20141208174653');
 
 INSERT INTO schema_migrations (version) VALUES ('20141208185217');
 
-INSERT INTO schema_migrations (version) VALUES ('20150122175935');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20150122175935');
+
+INSERT INTO schema_migrations (version) VALUES ('20150203180223');
\ No newline at end of file
diff --git a/services/api/lib/current_api_client.rb b/services/api/lib/current_api_client.rb
index 9f78587..729806f 100644
--- a/services/api/lib/current_api_client.rb
+++ b/services/api/lib/current_api_client.rb
@@ -146,8 +146,9 @@ module CurrentApiClient
         ActiveRecord::Base.transaction do
           $anonymous_group = Group.
           where(uuid: anonymous_group_uuid).first_or_create do |g|
-            g.update_attributes(name: "Anonymous group",
-                                description: "Anonymous group")
+            g.update_attributes(group_class: "role",
+                                name: "Anonymous users",
+                                description: "Anonymous users")
           end
         end
       end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list