Skip to content
Open
4 changes: 3 additions & 1 deletion BrainPortal/app/assets/stylesheets/cbrain.css.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2586,11 +2586,13 @@ img {

#data_provider_classes {
z-index: 1111;
max-width: 60em;
width: 60%;
position: absolute;
background-color: white;
border: 0.2em solid #0471B4;
padding: 1em;
word-wrap: break-word;
white-space: normal;
}


Expand Down
69 changes: 56 additions & 13 deletions BrainPortal/app/controllers/data_providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def show #:nodoc:
@provider = DataProvider.find(data_provider_id)
cb_notice "Provider not accessible by current user." unless @provider.can_be_accessed_by?(current_user)

@typelist = get_type_list

respond_to do |format|
format.html # show.html.erb
format.xml {
Expand All @@ -77,19 +79,30 @@ def show #:nodoc:

def new #:nodoc:
provider_group_id = current_assignable_group.id
@provider = DataProvider.new( :user_id => current_user.id,
@provider = DataProvider.new(
:user_id => current_user.id,
:group_id => provider_group_id,
:online => true,
:read_only => false
)

@typelist = get_type_list
@unsaved_meta = {}
@is_personal = false
@typelist = get_type_list

# Edit/create/show are the same view
render :action => :show
end

def create #:nodoc:
@provider = DataProvider.sti_new(data_provider_params)
@provider.user_id ||= current_user.id # disabled field in form DOES NOT send value!
@provider.group_id ||= current_assignable_group.id
@unsaved_meta = params[:meta] || {}

# Fix some attributes
@provider.update_attributes(userkey_provider_params) if @provider.is_a?(UserkeyFlatDirSshDataProvider)
@provider.update_attributes(s3_provider_params) if @provider.is_a?(S3FlatDataProvider)

if @provider.save
add_meta_data_from_form(@provider, [:must_move, :no_uploads, :no_viewers, :browse_gid])
Expand All @@ -103,7 +116,7 @@ def create #:nodoc:
else
@typelist = get_type_list
respond_to do |format|
format.html { render :action => :new }
format.html { render :action => :show }
format.xml { render :xml => @provider.errors, :status => :unprocessable_entity }
format.json { render :json => @provider.errors, :status => :unprocessable_entity }
end
Expand All @@ -117,32 +130,40 @@ def new_personal #:nodoc:
:online => true,
:read_only => false,
)
@groups = current_user.assignable_groups
@unsaved_meta = {}
@is_personal = true
@typelist = get_personal_type_list

# Edit/create/show are the same view
render :action => :show
end

# Can be create by normal user,
# only UserkeyFlatDirSshDataProvider, S3FlatDataProvider, S3MultiLevelDataProvider
def create_personal
@provider = DataProvider.new(base_provider_params).class_update
@provider.update_attributes(userkey_provider_params) if @provider.is_a?(UserkeyFlatDirSshDataProvider)
@provider.update_attributes(s3_provider_params) if @provider.is_a?(S3FlatDataProvider)

authorized_type = [UserkeyFlatDirSshDataProvider, S3FlatDataProvider, S3MultiLevelDataProvider]
@provider.errors.add(:type, "is not allowed") unless authorized_type.include?(@provider.type)
@unsaved_meta = params[:meta] || {}

@provider = DataProvider.new(base_provider_params).class_update
# Fix some attributes
@provider.user_id = current_user.id
@provider.group_id = current_user.own_group.id unless
current_user.assignable_group_ids.include?(@provider.group_id)
@provider.online = true

if ! @provider.save
@provider.update_attributes(userkey_provider_params) if @provider.is_a?(UserkeyFlatDirSshDataProvider)
@provider.update_attributes(s3_provider_params) if @provider.is_a?(S3FlatDataProvider)

authorized_type = ["UserkeyFlatDirSshDataProvider", "S3FlatDataProvider", "S3MultiLevelDataProvider"]
@provider.errors.add(:type, "is not allowed") unless authorized_type.include?(@provider.type)

if ! @provider.errors.empty? || ! @provider.save
@typelist = get_personal_type_list
@groups = current_user.assignable_groups
respond_to do |format|
format.html { render :action => :new_personal}
format.html { render :action => :show }
format.json { render :json => @provider.errors, :status => :unprocessable_entity }
end
return
return
end

@provider.addlog_context(self, "Created by #{current_user.login}")
Expand Down Expand Up @@ -808,8 +829,30 @@ def get_type_list #:nodoc:
grouped_options = data_provider_list.to_a.hashed_partitions { |name| name.constantize.pretty_category_name }
grouped_options.delete(nil) # data providers that can not be on this list return a category name of nil, so we remove them
grouped_options.keys.sort.map { |type| [ type, grouped_options[type].sort ] }

return grouped_options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong. It doesn't do what the original code did, which was to return the value computed by the method chain at line 831. Basically, the list you are returning is no longer sorted.

end

def get_personal_type_list #:nodoc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this method do? Explain please.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment block before the method name

data_provider_list = [ "FlatDirSshDataProvider" ]
data_provider_list = DataProvider.descendants.map(&:name)

grouped_options = data_provider_list.to_a.hashed_partitions { |name| name.constantize.pretty_category_name }
# Keep only Cloud
grouped_options = grouped_options.select { |type, values| ["Cloud"].include?(type) }
# Remove S3DataProvider
grouped_options["Cloud"].reject! { |v| v == S3DataProvider.name } if grouped_options["Cloud"]

# Add UserkeyFlatDirSshDataProvider group
category_of_userkey_dp = UserkeyFlatDirSshDataProvider.pretty_category_name
userkey_group = grouped_options.find { |type, _ | type == category_of_userkey_dp } || []
userkey_group << UserkeyFlatDirSshDataProvider.name
grouped_options[category_of_userkey_dp] = userkey_group

return grouped_options
end


# A name to store the scope for the browsing page;
# a distinct scope is used for each distinct DP
def browse_scope_name(provider) #:nodoc:
Expand Down
8 changes: 8 additions & 0 deletions BrainPortal/app/models/s3_flat_data_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class S3FlatDataProvider < DataProvider
validates :cloud_storage_client_identifier, length: { in: 16..128 }
validates :cloud_storage_client_token, length: { in: 20..100 }

# Attributes of:
# - SshDataProvider attributes (not appllicable to S3)
# - Containerized attributes (not applicable to S3)
# should be absent for this DP class.
validates :remote_user, :remote_host, :remote_port, :remote_dir,
:containerized_path,
absence: true

validates :cloud_storage_client_bucket_name, format: {
with: /\A[A-Za-z0-9][A-Za-z0-9\-.]{1,61}[A-Za-z0-9]\z/, # this is good enough; DP will just crash on bad names
message: "invalid S3 bucket name, for rules see https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html"
Expand Down
11 changes: 11 additions & 0 deletions BrainPortal/app/models/ssh_data_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class SshDataProvider < DataProvider

include SshDataProviderBase

# Attributes of:
# - S3 attributes (not appllicable to Ssh)
# - Containerized attributes (not applicable to Ssh)
# should be absent for this DP class.
validates :cloud_storage_client_identifier, :cloud_storage_client_token,
:cloud_storage_client_bucket_name, :cloud_storage_client_path_start,
:cloud_storage_endpoint, :cloud_storage_region,
:containerized_path,
absence: true


Revision_info=CbrainFileRevision[__FILE__] #:nodoc:

# This returns the category of the data provider
Expand Down
Loading