From 3d8fc8f64b7bd331a159ba2eee16618c94000348 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 25 Jun 2019 14:08:01 -0300 Subject: [PATCH] 14874: Capitalizes managed properties keys, updates documentation. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- ...ion-managed-properties.html.textile.liquid | 12 +++---- lib/config/config.default.yml | 8 ++--- services/api/app/models/collection.rb | 32 +++++++++---------- services/api/test/unit/collection_test.rb | 10 +++--- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/doc/admin/collection-managed-properties.html.textile.liquid b/doc/admin/collection-managed-properties.html.textile.liquid index c6943acaee..3952001263 100644 --- a/doc/admin/collection-managed-properties.html.textile.liquid +++ b/doc/admin/collection-managed-properties.html.textile.liquid @@ -24,7 +24,7 @@ For every newly created collection, assign a predefined key/value pair if it isn
 Collections:
   ManagedProperties:
-    foo: {value: bar}
+    foo: {Value: bar}
 
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
 Collections:
   ManagedProperties:
-    responsible_person_uuid: {function: original_owner}
+    responsible_person_uuid: {Function: original_owner}
 
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:
 Collections:
   ManagedProperties:
-    responsible_person_uuid: {function: original_owner, protected: true}
+    responsible_person_uuid: {Function: original_owner, Protected: true}
 
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' %} diff --git a/lib/config/config.default.yml b/lib/config/config.default.yml index 189e0d1fd8..0078da37eb 100644 --- a/lib/config/config.default.yml +++ b/lib/config/config.default.yml @@ -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., diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index 1ffaa6a319..39d56997a0 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -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 diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index 4790501ddd..c2bf94fe73 100644 --- a/services/api/test/unit/collection_test.rb +++ b/services/api/test/unit/collection_test.rb @@ -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 -- 2.30.2