Skip to content

Commit

Permalink
Merge branch 'seek-1.16' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Dec 6, 2024
2 parents 8380219 + 6903575 commit cf31448
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 12 deletions.
17 changes: 13 additions & 4 deletions app/models/sample_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ def can_see_hidden_item?(user)
can_view?(user)
end

def self.is_asset?
false
end

# although has a downloadable template, it doesn't have the full downloadable behaviour of an asset with data and it's own accessible permissions
def is_downloadable?
false
end

def self.supports_extended_metadata?
false
end

private

# whether the referring sample is valid and gives permission to view
Expand Down Expand Up @@ -292,9 +305,5 @@ def validate_title_is_not_type_of_seek_sample_multi
end
end

def self.supports_extended_metadata?
false
end

class UnknownAttributeException < RuntimeError; end
end
2 changes: 2 additions & 0 deletions app/views/sample_types/_template.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% return unless @sample_type.can_download? %>
<h2>Template</h2>
<div id="template-details">

<% if @sample_type.template %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/sample_types/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-9 col-sm-8 box_about_actor">
<%= item_description h(@sample_type.description) -%>

<h2>Template</h2>

<%= render :partial => "template" %>

<h2>Attributes</h2>
Expand Down
8 changes: 4 additions & 4 deletions config/help_links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Document: https://docs.seek4science.org/help/user-guide/adding-assets.html
Presentation: https://docs.seek4science.org/help/user-guide/adding-assets.html
Event: https://docs.seek4science.org/help/user-guide/general-attributes.html#events
clipboard_api_mozilla: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
ExtendedMetadataType: https://docs.seek4science.org/tech/extended-metadata
extended_metadata_technical_overview: https://github.com/seek4science/seek-documentation/blob/gh-pages-extended_metadata-type/tech/extended_metadata/extended-metadata-type.md
extended_metadata_type_json_schema: https://github.com/seek4science/seek-documentation/blob/gh-pages-extended_metadata-type/tech/extended_metadata/extended_metadata_type_schema.json
extended_metadata_type_example: https://github.com/seek4science/seek-documentation/blob/gh-pages-extended_metadata-type/tech/extended_metadata/a-complete-example.md
ExtendedMetadataType: https://docs.seek4science.org/tech/extended-metadata/extended-metadata-type.html
extended_metadata_technical_overview: https://docs.seek4science.org/tech/extended-metadata/extended-metadata-type.html
extended_metadata_type_json_schema: https://docs.seek4science.org/tech/extended-metadata/extended-metadata-type-schema.json
extended_metadata_type_example: https://docs.seek4science.org/tech/extended-metadata/a-complete-example.html
23 changes: 20 additions & 3 deletions lib/tasks/seek_upgrades.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace :seek do
update_observation_unit_policies
fix_xlsx_marked_as_zip
add_policies_to_existing_sample_types
fix_previous_sample_type_permissions
]

# these are the tasks that are executes for each upgrade as standard, and rarely change
Expand Down Expand Up @@ -104,13 +105,13 @@ namespace :seek do

# Visible if linked to public samples
if st.samples.any? { |sample| sample.is_published? }
policy.access_type = Policy::VISIBLE
policy.access_type = Policy::ACCESSIBLE
else
policy.access_type = Policy::NO_ACCESS
end
# Visible to each project
st.projects.map do |project|
policy.permissions << Permission.new(contributor_type: Permission::PROJECT, contributor_id: project.id, access_type: Policy::VISIBLE)
policy.permissions << Permission.new(contributor_type: Permission::PROJECT, contributor_id: project.id, access_type: Policy::ACCESSIBLE)
end
# Project admins can manage
project_admins = st.projects.map(&:project_administrators).flatten
Expand All @@ -125,7 +126,23 @@ namespace :seek do
counter += 1
end
end
puts "...Added policies to #{counter} sample types"
puts "... Added policies to #{counter} sample types"
end

task(fix_previous_sample_type_permissions: [:environment]) do
only_once('fix_previous_sample_type_permissions 1.16.0') do
puts '... Updating previous sample type permissions ...'
SampleType.includes(:policy).where.not(policy_id: nil).each do |sample_type|
policy = sample_type.policy
if policy.access_type == Policy::VISIBLE
policy.update_column(:access_type, Policy::ACCESSIBLE)
end
policy.permissions.where(access_type: Policy::VISIBLE).where(contributor_type: Permission::PROJECT).update_all(access_type: Policy::ACCESSIBLE)
putc('.')
end
AuthLookupUpdateQueue.enqueue(SampleType.all)
puts '... Finished updating previous sample type permissions'
end
end

private
Expand Down
25 changes: 25 additions & 0 deletions test/functional/sample_types_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,31 @@ class SampleTypesControllerTest < ActionController::TestCase
assert_equal 'update', ActivityLog.last.action
end

test 'template download link visibility' do
person = FactoryBot.create(:person)
sample_type = SampleType.new title: 'testing download',
uploaded_template: true,
project_ids: person.projects.collect(&:id),
contributor: person,
content_blob: FactoryBot.create(:sample_type_template_content_blob),
policy: FactoryBot.create(:downloadable_public_policy)
sample_type.build_attributes_from_template
disable_authorization_checks { sample_type.save! }
assert sample_type.can_view?
assert sample_type.can_download?
get :show, params: { id: sample_type }
assert_response :success
assert_select 'a[href=?]',download_sample_type_content_blob_path(sample_type,sample_type.template), text:'Download'

sample_type.policy = FactoryBot.create(:publicly_viewable_policy)
disable_authorization_checks { sample_type.save! }
assert sample_type.can_view?
refute sample_type.can_download?
get :show, params: { id: sample_type }
assert_response :success
assert_select 'a[href=?]',download_sample_type_content_blob_path(sample_type,sample_type.template), text:'Download', count:0
end

test 'update changing from a CV attribute' do
sample_type = FactoryBot.create(:apples_controlled_vocab_sample_type, project_ids: @project_ids,
contributor: @person)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/sample_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def setup
end
end

test 'not an asset or downloadable' do
st = FactoryBot.create(:simple_sample_type)
refute st.is_asset?
refute st.is_downloadable?
refute st.is_downloadable_asset?
end

test 'validate title and decription length' do
long_desc = ('a' * 65536).freeze
ok_desc = ('a' * 65535).freeze
Expand Down

0 comments on commit cf31448

Please sign in to comment.