Skip to content

Commit

Permalink
Merge branch 'unify-asset-selection-views' of github.com:seek4science…
Browse files Browse the repository at this point in the history
…/seek into fairdom_test

Pulling latest changes from the unify-asset-selection-views branch
  • Loading branch information
Kevin De Pelseneer committed Sep 1, 2023
2 parents a0b0429 + f4211fc commit eea9a56
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 41 deletions.
25 changes: 19 additions & 6 deletions app/helpers/policy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def project_policy_json(project)
hash.to_json.html_safe
end

def permission_title(permission, member_prefix: false, icon: false)
def permission_title(permission, member_prefix: false, icon: false, link: false)
if permission.is_a?(Permission)
type = permission.contributor_type
contributor = permission.contributor
Expand All @@ -168,18 +168,31 @@ def permission_title(permission, member_prefix: false, icon: false)
contributor = permission
end

if type == 'Person'
option = { target: :_blank }
case type
when 'Person'
text = "#{contributor.first_name} #{contributor.last_name}"
elsif type == 'WorkGroup'
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.project.title} @ #{contributor.institution.title}"
text = link_to(h(text), contributor, option).html_safe if link
when 'WorkGroup'
institution = contributor.institution
project = contributor.project
if link
text = "#{member_prefix ? 'Members of ' : ''}#{link_to(h(project.title), project, option)} @ #{link_to(h(institution.title), institution, option)}".html_safe
else
text = "#{member_prefix ? 'Members of ' : ''}#{project.title} @ #{institution.title}"
end
else
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.title}"
if link
text = "#{member_prefix ? 'Members of ' : ''}#{link_to(h(contributor.title), contributor, option)}".html_safe
else
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.title}"
end
end

if icon
content_tag(:span, class: 'type-icon-wrapper') do
image_tag(asset_path(icon_filename_for_key(type.underscore)), class: 'type-icon')
end.html_safe + " #{text}"
end.html_safe + " #{text}".html_safe
else
text
end
Expand Down
19 changes: 0 additions & 19 deletions app/helpers/sharing_permissions_helper.rb

This file was deleted.

5 changes: 4 additions & 1 deletion app/views/assets/_batch_asset_selection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@
</div>
<div id="investigation_list">
<% @investigations.each do |inv| %>
<% collection = inv.assays.map(&:study).map(&:investigation).flatten.uniq %>
<% collection = inv.studies.map(&:investigation).flatten.uniq if collection.empty? %>
<% collection = [inv] if collection.empty?%>
<%= render partial: 'assets/isa_tree_preview',
locals: { publishing: publishing },
collection: inv.assays.map(&:study).map(&:investigation).flatten.uniq %>
collection: collection %>
<% end %>
</div>
<br/>
Expand Down
2 changes: 1 addition & 1 deletion app/views/assets/_permission_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% item.policy.permissions.map do |permission| %>
<% sharing_permission_changed = @batch_sharing_permission_changed && (@items_for_sharing.include? item) ? PolicyHelper::permission_changed_item_class(permission, @policy_params) : "" %>
<div id="<%= item_id %>-Permission-<%= permission.contributor_type %>}-<%= permission.contributor.id %>" class="permission-node <%= sharing_permission_changed %>">
<strong><%= get_permission_type permission -%>:</strong>
<strong><%= permission_title(permission, member_prefix: false, icon: false, link: true) -%>:</strong>
<%= Policy.get_access_type_wording(permission.access_type, downloadable) %>
</div>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

<div class="alert alert-info">
<ul>
<li>You can view the details of current permissions for each item by clicking the item's policy icon.</li>
<li>You can view the details of current permissions for each item by clicking the item's policy icon (
<%= image('world', title: 'Was published', class: 'visibility_icon') %>
<%= image('partial_world', title: 'Visible to everyone, but not accessible', class: 'visibility_icon') %>
<%= image('manage', title: 'Custom policy', class: 'visibility_icon') %>
<%= image('lock', title: 'Private', class: 'visibility_icon') %>
).</li>
<li>You can view the managers for each item by clicking the
<span class="glyphicon glyphicon-user" aria-hidden="true" style="position:relative; top:2px;"></span>
icon.</li>
<li>After your confirmation, the newly modified permissions will be highlighted with <span class="sharing_permission_changed"></span> .</li>
</ul>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/people/_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% if mine?(@person) -%>
<% tooltip_text_sharing = "You can change the sharing policy and permissions for your assets in batch. A preview of selected assets will be given before you choose new permissions for them." %>
<% tooltip_text_publishing = "Publish your owned assets in one click. A preview will be given before publishing" %>
<% tooltip_text_sharing = "You can change the sharing policy and permissions for your items in batch. A preview of selected items will be given before you choose new permissions for them." %>
<% tooltip_text_publishing = "Publish your owned items in one click. A preview will be given before publishing" %>
<%= button_link_to "Batch permission changes", "publish", batch_sharing_permission_preview_person_path(@person), 'data-tooltip' => tooltip(tooltip_text_sharing) -%>
<%= button_link_to "Publish your assets", "publish", batch_publishing_preview_person_path(@person), 'data-tooltip' => tooltip(tooltip_text_publishing) -%>
<%= button_link_to "Publish your items", "publish", batch_publishing_preview_person_path(@person), 'data-tooltip' => tooltip(tooltip_text_publishing) -%>
<% if @person.is_in_any_gatekept_projects? %>
<%= button_link_to "Assets awaiting approval", "waiting", waiting_approval_assets_person_path(@person),
'data-tooltip' => tooltip("The assets you have requested to publish, but are awaiting the #{t('asset_gatekeeper').downcase} approval") -%>
Expand Down
9 changes: 7 additions & 2 deletions lib/seek/publishing/publishing_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def set_asset
def set_assets
# get the assets that current_user can manage
@assets = {}
publishable_types = Seek::Util.authorized_types.select { |authorized_type| authorized_type.first.try(:is_in_isa_publishable?) }
publishable_types.each do |klass|
Seek::Util.authorized_types.each do |klass|
can_manage_assets = klass.authorized_for 'manage', current_user
unless can_manage_assets.empty?
@assets[klass.name] = can_manage_assets
Expand All @@ -146,8 +145,12 @@ def set_assets

def set_investigations
@investigations = []
@assets['Investigation']&.each do |inv|
@investigations.push(inv)
end
@assets_not_in_isa = []
@assets.each do |type, klass|
next if %w[Investigation Study Assay].include? type
klass.each do |asset|
if asset.investigations.empty?
@assets_not_in_isa.push(asset)
Expand All @@ -157,6 +160,8 @@ def set_investigations
@investigations.push(inv)
end
end
rescue NoMethodError
@assets_not_in_isa.push(asset)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/functional/publishing/batch_publishing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup
test 'should have the -Publish your assets- only on your own profile' do
get :show, params: { id: User.current_user.person }
assert_response :success
assert_select 'a[href=?]', batch_publishing_preview_person_path, text: /Publish your assets/
assert_select 'a[href=?]', batch_publishing_preview_person_path, text: /Publish your items/

get :batch_publishing_preview, params: { id: User.current_user.person.id }
assert_response :success
Expand Down Expand Up @@ -44,14 +44,14 @@ def setup
assert a.can_publish?, 'The asset must not be publishable for this test to succeed'
assert a.gatekeeper_required?, "This asset must require gatekeeper's approval for this test to succeed"
end

total_asset_count = (publish_immediately_assets + gatekeeper_required_assets).count

get :batch_publishing_preview, params: { id: User.current_user.person.id }
assert_response :success

assert_select 'div#sorted_by_type,#sorted_by_isa', count: 2 do |sorted_by|
sorted_by.each do |sorted_by_block|
assert_select sorted_by_block, '.type_and_title', count: total_asset_count do
assert_select sorted_by_block, '.type_and_title', count: total_asset_count + 1 do # event will also be shown
publish_immediately_assets.each do |a|
assert_select 'a[href=?]', eval("#{a.class.name.underscore}_path(#{a.id})"), text: /#{a.title}/
end
Expand All @@ -61,7 +61,7 @@ def setup
assert_select '.type_and_title img[src*=?][title=?]', 'lock.png', 'Private', count: total_asset_count
end

assert_select sorted_by_block, '.parent-btn-checkbox', count: total_asset_count do
assert_select sorted_by_block, '.parent-btn-checkbox', count: total_asset_count + 1 do # event will also be shown
publish_immediately_assets.each do |a|
assert_select "input[type='checkbox'][id=?]", "publish_#{a.class.name}_#{a.id}"
end
Expand Down
8 changes: 4 additions & 4 deletions test/functional/sharing/batch_sharing_change_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def setup
assert_select 'a[href=?]', "/people/#{person.id}", text: /#{person.name}/, count: 1
end
assert_select 'div#sorted_by_type', count: 1 do
# Should only see assets: df, doc, ft, model, pres, sop, wf
assert_select '.type_and_title', count: 7
# Should see all items with policies
assert_select '.type_and_title', count: 21
end
assert_select 'div#sorted_by_isa', count: 1 do
# Should see assets + inv, study, assay
assert_select '.type_and_title', count: 10
# Should see all items with policies
assert_select '.type_and_title', count: 21
end

end
Expand Down

0 comments on commit eea9a56

Please sign in to comment.