diff --git a/BrainPortal/app/assets/stylesheets/cbrain.css.erb b/BrainPortal/app/assets/stylesheets/cbrain.css.erb index b925a5dd2..adf26514a 100644 --- a/BrainPortal/app/assets/stylesheets/cbrain.css.erb +++ b/BrainPortal/app/assets/stylesheets/cbrain.css.erb @@ -2655,3 +2655,12 @@ img { .no-close .ui-dialog-titlebar-close { display: none; } + +.indeterminate { + color: steelblue !important; +} + +.indeterminate_box_label { + color: steelblue !important; + font-weight: normal !important; +} \ No newline at end of file diff --git a/BrainPortal/app/controllers/data_providers_controller.rb b/BrainPortal/app/controllers/data_providers_controller.rb index 24cd5e3f7..906bda12f 100644 --- a/BrainPortal/app/controllers/data_providers_controller.rb +++ b/BrainPortal/app/controllers/data_providers_controller.rb @@ -178,9 +178,11 @@ def update #:nodoc: # Fields that stay the same if the form provides a blank entry: new_data_provider_attr.delete :cloud_storage_client_token if new_data_provider_attr[:cloud_storage_client_token].blank? + if @provider.update_attributes_with_logging(new_data_provider_attr, current_user, @provider.attributes.keys + []) + mass_flags = 'dp_no_copy_default|rr_no_sync_default' # default policies w.r.t new dp or server + # todo cast params to hash for rails 5.1 as `ActionController::Parameters` no longer inherits from hash + meta_flags_for_restrictions = (params[:meta] || {}).keys.grep(/\Adp_no_copy_\d+\z|\Arr_no_sync_\d+|#{mass_flags}\z/) - if @provider.update_attributes_with_logging(new_data_provider_attr, current_user, @provider.attributes.keys) - meta_flags_for_restrictions = (params[:meta] || {}).keys.grep(/\Adp_no_copy_\d+\z|\Arr_no_sync_\d+\z/) add_meta_data_from_form(@provider, [:must_move, :no_uploads, :no_viewers, :browse_gid] + meta_flags_for_restrictions) flash[:notice] = "Provider successfully updated." respond_to do |format| diff --git a/BrainPortal/app/helpers/show_table_helper.rb b/BrainPortal/app/helpers/show_table_helper.rb index 9fd6ed491..4ff530212 100644 --- a/BrainPortal/app/helpers/show_table_helper.rb +++ b/BrainPortal/app/helpers/show_table_helper.rb @@ -197,12 +197,14 @@ def edit_cell(field, options = {}, &block) # As +boolean_edit_cell+ is a specialization of +edit_cell+, +field+, # +&block+ and +options+ are handled the same way (save for the defaults # outlined above). + # +input_options+ are options just for the checkbox itself (at the moment apply only to the edit mode and block-free use) def boolean_edit_cell(field, cur_value, checked_value = "1", unchecked_value = "0", options = {}, &block) options[:content] ||= @template.disabled_checkbox(cur_value == checked_value) + input_options = options.delete(:input_options) || {} if block_given? edit_cell(field, options, &block) else - edit_cell(field, options) { @template.hidden_field_tag(field, unchecked_value) + @template.check_box_tag(field, checked_value, cur_value == checked_value) } + edit_cell(field, options) { @template.hidden_field_tag(field, unchecked_value) + @template.check_box_tag(field, checked_value, cur_value == checked_value, input_options) } end end diff --git a/BrainPortal/app/models/data_provider.rb b/BrainPortal/app/models/data_provider.rb index 96e0f22e6..bf21a4bea 100644 --- a/BrainPortal/app/models/data_provider.rb +++ b/BrainPortal/app/models/data_provider.rb @@ -1361,11 +1361,13 @@ def self.cleanup_leftover_cache_files(do_it=false, options={}) # Returns true if RemoteResource +rr+ is allowed to access DataProvider +check_dp+ # (which defaults to self). The information for this restriction is maintained - # as a blacklist in the meta data store. + # according to whitelist, blacklist and default value in the meta data store. def rr_allowed_syncing?(rr = RemoteResource.current_resource, check_dp = self) rr ||= RemoteResource.current_resource - meta_key_disabled = "rr_no_sync_#{rr.id}" - check_dp.meta[meta_key_disabled].blank? + meta_key = "rr_no_sync_#{rr.id}" + default = check_dp.meta["rr_no_sync_default"] || 'allowed' # default for default is allow sync + policy = ( self.meta[meta_key].presence || default ) + return policy.length != 8 # shorter or longer than 'disabled' (either 'allowed' or long legacy sentence) end # Works like rr_allowed_syncing? but raise an exception when the @@ -1379,11 +1381,17 @@ def rr_allowed_syncing!(server_does_what = "access the files of", rr = RemoteRes # Returns true if the DataProvider is allowed to copy or move files to the # other DataProvider +other_dp+ . - # The information for this restriction is maintained - # as a blacklist in the meta data store. + # The information for this restriction is maintained by default value + # along with a white- and blacklist, all stored in the meta data store. def dp_allows_copy?(other_dp) - meta_key_disabled = "dp_no_copy_#{other_dp.id}" - self.meta[meta_key_disabled].blank? + meta_key = "dp_no_copy_#{other_dp.id}" + # if there is no explicit flag for particular provider + # fall back on the default policy + default = self.meta["dp_no_copy_default"] + return ( self.meta[meta_key].presence || default ) != "disabled" + # hacky equivalent of + # return true if self.meta[meta_key] == 'copy' # yes if whitelisted + # self.meta[meta_key].blank? && default != "disabled" # otherwise by dafault end # Works like dp_allows_copy? but raises an exception if the diff --git a/BrainPortal/app/views/data_providers/show.html.erb b/BrainPortal/app/views/data_providers/show.html.erb index fd5de1b3d..90b8e4f85 100644 --- a/BrainPortal/app/views/data_providers/show.html.erb +++ b/BrainPortal/app/views/data_providers/show.html.erb @@ -22,12 +22,26 @@ # -%> + <% title 'Data Provider Info' %> <% has_owner_access = (check_role(:admin_user) || @provider.user_id == current_user.id) %> <% is_userkey_dp = @provider.is_a?(UserkeyFlatDirSshDataProvider) %> <% needs_ssh_config = @provider.is_a?(SshDataProvider) || @provider.is_a?(SmartDataProviderInterface) %> +<% + # tribox method creates tristate checkbox for table, to be used with meta data store + # meta_value can have values allowed, disabled and empty (=indetermiate state) + def tribox(t, model, meta_key, meta_value, default_value, cls) + if meta_value.present? + t.boolean_edit_cell("meta[#{meta_key}]", meta_value, "allowed", "disabled", :header => "#{model.name}", :class => 'checkbox_label', :input_options => { class: cls } ) + else + t.boolean_edit_cell("meta[#{meta_key}]", default_value, "allowed", "disabled", :header => "#{model.name}".html_safe, :class => 'checkbox_label indeterminate_box_label', :input_options => { class: "#{cls} indeterminate" } ) + end + end +%> + +