14874: Capitalizes managed properties keys, updates documentation.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 25 Jun 2019 17:08:01 +0000 (14:08 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 25 Jun 2019 17:08:01 +0000 (14:08 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

doc/admin/collection-managed-properties.html.textile.liquid
lib/config/config.default.yml
services/api/app/models/collection.rb
services/api/test/unit/collection_test.rb

index c6943acaee5e647dd5f8874a09deb124be6dd997..39520012639d9607b4314513378c4f0b45b061e7 100644 (file)
@@ -24,7 +24,7 @@ For every newly created collection, assign a predefined key/value pair if it isn
 <pre>
 Collections:
   ManagedProperties:
-    foo: {value: bar}
+    foo: {Value: bar}
 </pre>
 
 h4. Original owner UUID
@@ -34,17 +34,17 @@ This behavior will assign to a property key the UUID of the user who owns the co
 <pre>
 Collections:
   ManagedProperties:
-    responsible_person_uuid: {function: original_owner}
+    responsible_person_uuid: {Function: original_owner}
 </pre>
 
 h4. Protected properties
 
-If there's a need to prevent a non-admin user from modifying a specific property, even by its owner, the @protected@ attribute can be set to @true@, like so:
+If there's a need to prevent a non-admin user from modifying a specific property, even by its owner, the @Protected@ attribute can be set to @true@, like so:
 
 <pre>
 Collections:
   ManagedProperties:
-    responsible_person_uuid: {function: original_owner, protected: true}
+    responsible_person_uuid: {Function: original_owner, Protected: true}
 </pre>
 
 This property can be applied to any of the defined managed properties. If missing, it's assumed as being @false@ by default.
@@ -53,7 +53,7 @@ h3. Supporting example scripts
 
 When enabling this feature, there may be pre-existing collections that won't have the managed properties just configured. The following script examples may be helpful to sync these older collections.
 
-For the following examples we assume that the @responsible_person_uuid@ property is set as @{function: original_owner, protected: true}@.
+For the following examples we assume that the @responsible_person_uuid@ property is set as @{Function: original_owner, Protected: true}@.
 
 h4. List uuid/names of collections without @responsible_person_uuid@ property
 
@@ -77,7 +77,7 @@ h4. Update the @responsible_person_uuid@ property from X to Y on all collections
 
 This example can be useful to change responsibility from one user to another.
 
-Please note that the following code should run with admin privileges, assuming that the managed property is @protected@.
+Please note that the following code should run with admin privileges, assuming that the managed property is @Protected@.
 
 {% codeblock as python %}
 {% include 'admin_update_collection_property_py' %}
index 189e0d1fd800102bd350df183726f182ebabb14f..0078da37eba25f61d6f807c6152d0db707d1cd94 100644 (file)
@@ -284,14 +284,14 @@ Clusters:
       # one of the following behaviors:
       #
       # * UUID of the user who owns the containing project.
-      #   responsible_person_uuid: {function: original_owner, protected: true}
+      #   responsible_person_uuid: {Function: original_owner, Protected: true}
       #
       # * Default concrete value.
-      #   foo_bar: {value: baz, protected: false}
+      #   foo_bar: {Value: baz, Protected: false}
       #
-      # If protected is true, only an admin user can modify its value.
+      # If Protected is true, only an admin user can modify its value.
       ManagedProperties:
-        SAMPLE: {function: original_owner, protected: true}
+        SAMPLE: {Function: original_owner, Protected: true}
 
     Login:
       # These settings are provided by your OAuth2 provider (e.g.,
index 1ffaa6a319c449a4d2f65980a0848a035b8ffc86..39d56997a09596f64a86a2842a96667b048a6f92 100644 (file)
@@ -22,7 +22,7 @@ class Collection < ArvadosModel
 
   before_validation :default_empty_manifest
   before_validation :default_storage_classes, on: :create
-  before_validation :default_properties, on: :create
+  before_validation :managed_properties, on: :create
   before_validation :check_encoding
   before_validation :check_manifest_validity
   before_validation :check_signatures
@@ -32,7 +32,7 @@ class Collection < ArvadosModel
   validate :ensure_storage_classes_contain_non_empty_strings
   validate :versioning_metadata_updates, on: :update
   validate :past_versions_cannot_be_updated, on: :update
-  validate :protected_default_properties_updates, on: :update
+  validate :protected_managed_properties_updates, on: :update
   after_validation :set_file_count_and_total_size
   before_save :set_file_names
   around_update :manage_versioning, unless: :is_past_version?
@@ -608,19 +608,19 @@ class Collection < ArvadosModel
     self.storage_classes_confirmed ||= []
   end
 
-  # Sets default properties at creation time
-  def default_properties
-    default_props = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
-    if default_props.empty?
+  # Sets managed properties at creation time
+  def managed_properties
+    managed_props = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
+    if managed_props.empty?
       return
     end
-    (default_props.keys - self.properties.keys).each do |key|
-      if default_props[key].has_key?('value')
-        self.properties[key] = default_props[key]['value']
-      elsif default_props[key]['function'].andand == 'original_owner'
+    (managed_props.keys - self.properties.keys).each do |key|
+      if managed_props[key].has_key?('Value')
+        self.properties[key] = managed_props[key]['Value']
+      elsif managed_props[key]['Function'].andand == 'original_owner'
         self.properties[key] = self.user_owner_uuid
       else
-        logger.warn "Unidentified default property definition '#{key}': #{default_props[key].inspect}"
+        logger.warn "Unidentified default property definition '#{key}': #{managed_props[key].inspect}"
       end
     end
   end
@@ -686,13 +686,13 @@ class Collection < ArvadosModel
     end
   end
 
-  def protected_default_properties_updates
-    default_properties = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
-    if default_properties.empty? || !properties_changed? || current_user.is_admin
+  def protected_managed_properties_updates
+    managed_properties = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
+    if managed_properties.empty? || !properties_changed? || current_user.is_admin
       return true
     end
-    protected_props = default_properties.keys.select do |p|
-      Rails.configuration.Collections.ManagedProperties[p]['protected']
+    protected_props = managed_properties.keys.select do |p|
+      Rails.configuration.Collections.ManagedProperties[p]['Protected']
     end
     # Pre-existent protected properties can't be updated
     invalid_updates = properties_was.keys.select{|p| properties_was[p] != properties[p]} & protected_props
index 4790501ddd5aaa875f5c716d88b9ac0464cec607..c2bf94fe73a2d85f45c23ca1dbc7a8dcda25a8c9 100644 (file)
@@ -1013,10 +1013,10 @@ class CollectionTest < ActiveSupport::TestCase
     assert_empty Collection.where(uuid: uuid)
   end
 
-  test "create collections with default properties" do
+  test "create collections with managed properties" do
     Rails.configuration.Collections.ManagedProperties = {
-      'default_prop1' => {'value' => 'prop1_value'},
-      'responsible_person_uuid' => {'function' => 'original_owner'}
+      'default_prop1' => {'Value' => 'prop1_value'},
+      'responsible_person_uuid' => {'Function' => 'original_owner'}
     }
     # Test collection without initial properties
     act_as_user users(:active) do
@@ -1045,9 +1045,9 @@ class CollectionTest < ActiveSupport::TestCase
     end
   end
 
-  test "update collection with protected default properties" do
+  test "update collection with protected managed properties" do
     Rails.configuration.Collections.ManagedProperties = {
-      'default_prop1' => {'value' => 'prop1_value', 'protected' => true},
+      'default_prop1' => {'Value' => 'prop1_value', 'Protected' => true},
     }
     act_as_user users(:active) do
       c = create_collection 'foo', Encoding::US_ASCII