Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projects' add new dropdown #1643

Merged
merged 16 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/concerns/legacy/workflow_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def create_content_blob
private

def legacy_ro_crate_params
params.require(:ro_crate).permit({ workflow: [:data, :data_url, :make_local_copy] },
l_params = params.require(:ro_crate).permit({ workflow: [:data, :data_url, :make_local_copy]},
{ abstract_cwl: [:data, :data_url, :make_local_copy] },
{ diagram: [:data, :data_url, :make_local_copy] })
l_params[:workflow][:project_ids] = params.dig(:workflow, :project_ids) || []
l_params
stuzart marked this conversation as resolved.
Show resolved Hide resolved
end

def legacy_set_workflow
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/publications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ def show
end
end

# GET /publications/new
def new
@publication = Publication.new
@publication.parent_name = params[:parent_name]
respond_to do |format|
format.html # new.html.erb
end
end

# GET /publications/1/edit
def edit; end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/sample_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def show
def new
@tab = 'manual'

@sample_type = SampleType.new
attr = params["sample_type"] ? sample_type_params : {}
@sample_type = SampleType.new(attr)
@sample_type.sample_attributes.build(is_title: true, required: true) # Initial attribute

respond_with(@sample_type)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def index

def new
if params[:sample_type_id]
@sample = Sample.new(sample_type_id: params[:sample_type_id])
@sample = Sample.new(sample_type_id: params[:sample_type_id], project_ids: params[:project_ids])
respond_with(@sample)
else
redirect_to select_sample_types_path(act: :create)
project_ids_param = params[:sample] ? params[:sample][:project_ids] : {}
redirect_to select_sample_types_path(act: :create, project_ids: project_ids_param)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/strains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def new
@strain = parent_strain.clone_with_associations
@strain.parent_id = parent_strain.id
else
@strain = Strain.new
@strain = setup_new_asset
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def default_templates

def new
@tab = 'manual'
@template = Template.new
@template = setup_new_asset
@template.organism = 'any'
respond_with(@template)
end
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def update

# Takes a single RO-Crate zip file
def create_from_ro_crate
@crate_extractor = WorkflowCrateExtractor.new(ro_crate_extractor_params)
@crate_extractor = WorkflowCrateExtractor.new(ro_crate_extractor_params.merge(
params: params.key?(:workflow) ? workflow_params : {}))
@workflow = @crate_extractor.build

respond_to do |format|
Expand Down Expand Up @@ -370,7 +371,8 @@ def workflow_params
def ro_crate_params
params.require(:ro_crate).permit({ main_workflow: [:data, :data_url, :make_local_copy] },
{ abstract_cwl: [:data, :data_url, :make_local_copy] },
{ diagram: [:data, :data_url, :make_local_copy] })
{ diagram: [:data, :data_url, :make_local_copy] }).merge(
params.fetch(:workflow, {}).permit(project_ids: []))
end

def ro_crate_extractor_params
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/multi_step_wizard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def forward_params(key)
if params[key][:publication_ids]
html << hidden_field_tag('data_file[publication_ids][]', params[key][:publication_ids])
end
if params[key][:project_ids]
html << hidden_field_tag("#{key}[project_ids][]", params[key][:project_ids])
end
end
html.html_safe
end
Expand All @@ -56,7 +59,8 @@ def extraction_forward_payload_json(resource, key)
key => {
assay_assets_attributes: resource.assay_assets.collect(&:assay_id).collect { |id| { assay_id: id.to_s } },
event_ids: resource.events.collect(&:id),
publication_ids: resource.publications.collect(&:id)
publication_ids: resource.publications.collect(&:id),
project_ids: resource.projects.collect(&:id)
}
}
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/workflow_repository_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
class WorkflowRepositoryBuilder
include ActiveModel::Model

attr_accessor :main_workflow, :abstract_cwl, :diagram, :workflow_class
attr_accessor :main_workflow, :abstract_cwl, :diagram, :workflow_class, :project_ids

validates :main_workflow, presence: true
validate :resolve_remotes
validate :workflow_data_present

def build
@workflow = Workflow.new(workflow_class: workflow_class, is_git_versioned: true)
@workflow = Workflow.new(workflow_class: workflow_class, is_git_versioned: true, project_ids: project_ids || [])

if valid?
gv = @workflow.git_version
Expand Down
14 changes: 7 additions & 7 deletions app/views/investigations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
<%= form_submit_buttons(@investigation) %>

<script>
fherreazcue marked this conversation as resolved.
Show resolved Hide resolved
$j(document).ready(function () {
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const project_id = params["investigation[project_id]"]
if(project_id)
$j("#projects-selector-select").val(project_id).change();
});
$j(document).ready(function () {
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const project_id = params["investigation[project_id]"]
if(project_id)
$j("#projects-selector-select").val(project_id).change();
});
</script>
6 changes: 3 additions & 3 deletions app/views/projects/_buttons.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<% if can_browse_openbis?(item) %>
<%= button_link_to("Browse openBIS", :openbis_square, openbis_endpoint_path(item.openbis_endpoints.last),{icon_options:{height:'18px'}}) %>
<% end %>
<% if item.try(:has_member?,current_user) %>
<% if item.has_member?(current_user) %>
<%= button_link_to("Dashboard", 'project_dashboard', dashboard_project_stats_path(item)) %>
<% end -%>
<%= button_link_to('Overview', 'graph_nodes', overview_project_path(item)) -%>
<% if item.try(:has_member?,current_user) || admin_logged_in? -%>
<% if item.has_member?(current_user) || admin_logged_in? -%>
<% tooltip_text="This will present you with a short report about the items that have been shared outside of your #{t('project')}" %>
<%= button_link_to("Asset report", 'report', asset_report_project_path(item), 'data-tooltip' => tooltip(tooltip_text)) -%>
<% end -%>
Expand All @@ -31,7 +31,7 @@
</span>
<% end -%>

<% if item.can_edit? -%>
<% if item.can_edit? && item.has_member?(current_user) -%>
<% if displaying_single_page? %>
<%= button_link_to("Design #{t('investigation')}", 'new', new_investigation_path("investigation[project_id]": item.id, single_page: params[:id])) %>
<% else -%>
Expand Down
15 changes: 11 additions & 4 deletions app/views/projects/_project_selector.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,19 @@
});

$j(document).ready(function () {
<% if params[:project_ids] && resource && resource.new_record? %>
// Auto select projects from params if this is a new object
<% params[:project_ids].each do |project_id| %>
Sharing.projectsSelector.add(<%= project_id %>, true);
// Auto select projects from params[:project_ids] or params[resource][:project_ids] if this is a new object
<% if resource && resource.new_record? %>
<% if params[:project_ids] %>
<% params[:project_ids].each do |project_id| %>
Sharing.projectsSelector.add(<%= project_id %>, true);
<% end %>
<% end %>
<% if params[controller_name.singularize] && params[controller_name.singularize][:project_ids] %>
<% params[controller_name.singularize][:project_ids].each do |project_id| %>
Sharing.projectsSelector.add(<%= project_id %>, true);
<% end %>
<% end %>
<% end %>
// Auto select project if there is only one
if (Sharing.projectsSelector.possibilities.length === 1 &&
Sharing.projectsSelector.selected.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/sample_types/select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<script>
var SampleTypeFilters={
optionChanged:function() {
$j.ajax('<%= filter_for_select_sample_types_path %>', {
$j.ajax('<%= filter_for_select_sample_types_path(project_ids: params[:project_ids]) %>', {
data: SampleTypeFilters.queryData(),
success: function (html) {
$j('#selected-sample-types').html(html);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<% if Sample.can_create? %>
<div class="col-sm-2">
<%= link_to "New sample", new_sample_path(:sample_type_id => sample_type.id), class: "btn btn-primary" %>
<%= link_to "New sample", new_sample_path(:sample_type_id => sample_type.id, project_ids: params[:project_ids]), class: "btn btn-primary" %>
</div>
<div class="col-sm-2">
<%= link_to "New batch submission", batch_upload_sample_type_path(sample_type), class: "btn btn-primary" %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/workflows/_legacy_upload_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="tab-content">
<div id="new-ro-crate" role="tabpanel" class="tab-pane active">
<%= form_tag({ action: :create_ro_crate, anchor: 'new-ro-crate' }, multipart: true) do -%>
<%= forward_params(:workflow) %>
<div class="asset_form">
<%= error_messages_for :workflow -%>
<%= error_messages_for :crate_builder, header_message: "Could not build Workflow RO-Crate" -%>
Expand Down Expand Up @@ -80,6 +81,7 @@

<div id="existing-ro-crate" role="tabpanel" class="tab-pane">
<%= form_tag({ action: :create_content_blob, anchor: 'existing-ro-crate' }, multipart: true) do -%>
<%= forward_params(:workflow) %>
<div class="asset_form">
<%= error_messages_for :workflow -%>
<%= error_messages_for :crate_extractor -%>
Expand Down
3 changes: 3 additions & 0 deletions app/views/workflows/_upload_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<div class="tab-content">
<div id="new-ro-crate" role="tabpanel" class="tab-pane active">
<%= form_tag({ action: :create_from_files, anchor: 'new-ro-crate' }, multipart: true) do -%>
<%= forward_params(:workflow) %>
<%= error_messages_for :workflow -%>
<%= error_messages_for :crate_builder, header_message: "Could not build Workflow RO-Crate" -%>

Expand Down Expand Up @@ -90,6 +91,7 @@

<div id="git-repo" role="tabpanel" class="tab-pane">
<%= form_tag({ action: :create_from_git, anchor: 'git-repo' }) do -%>
<%= forward_params(:workflow) %>
<%= error_messages_for :workflow -%>

<%= panel do %>
Expand All @@ -109,6 +111,7 @@

<div id="existing-ro-crate" role="tabpanel" class="tab-pane">
<%= form_tag({ action: :create_from_ro_crate, anchor: 'existing-ro-crate' }, multipart: true) do -%>
<%= forward_params(:workflow) %>
<%= error_messages_for :workflow -%>
<%= error_messages_for :crate_extractor -%>

Expand Down
1 change: 1 addition & 0 deletions app/views/workflows/select_paths.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>New <%= t('workflow') %><%= ' Version' if @workflow.persisted? %></h1>

<%= form_tag(polymorphic_path(@workflow.persisted? ? [:create_version_from_git, @workflow] : [:create_from_git, :workflows])) do %>
<%= hidden_field_tag "workflow[project_ids][]",@workflow.project_ids %>
<%= fields_for('workflow[git_version_attributes]', @workflow.git_version) do |f| %>
<% if false %>
<h2>Version Metadata</h2>
Expand Down
1 change: 1 addition & 0 deletions app/views/workflows/select_ref.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>Select Target</h1>

<%= form_tag(polymorphic_path(@workflow.persisted? ? [:create_version_from_git, @workflow] : [:create_from_git, :workflows])) do %>
<%= hidden_field_tag "workflow[project_ids][]",@workflow.project_ids %>
<%= hidden_field_tag "workflow[git_version_attributes][git_repository_id]", @workflow.git_version.git_repository.id %>
<%= render partial: 'git_repositories/ref_form', locals: { name: "workflow[git_version_attributes][ref]",
git_repository: @workflow.git_version.git_repository } %>
Expand Down
19 changes: 18 additions & 1 deletion lib/seek/add_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ module Seek
# defines what can be added to a particular item, and the params used
class AddButtons
DEFINITIONS = {
'Project' => [[Investigation, 'investigation[project_id]']],
'Project' => [
[Investigation, 'investigation[project_ids][]'],
[Collection, 'collection[project_ids][]'],
[DataFile, 'data_file[project_ids][]'],
[Document, 'document[project_ids][]'],
[Event, 'event[project_ids][]'],
[FileTemplate, 'file_template[project_ids][]'],
[Model, 'model[project_ids][]'],
[Placeholder, 'placeholder[project_ids][]'],
[Presentation, 'presentation[project_ids][]'],
[Publication, 'publication[project_ids][]'],
[Sample, 'sample[project_ids][]'],
[SampleType, 'sample_type[project_ids][]'],
[Sop, 'sop[project_ids][]'],
[Strain, 'strain[project_ids][]'],
[Template, 'template[project_ids][]'],
[Workflow, 'workflow[project_ids][]']
],
'Investigation' => [[Study, 'study[investigation_id]']],
'Study' => [[Assay, 'assay[study_id]']],
'Modelling Analysis' => [[DataFile, 'data_file[assay_assets_attributes[][assay_id]]'],
Expand Down
48 changes: 48 additions & 0 deletions test/functional/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3663,6 +3663,54 @@ def test_admin_can_edit
assert_select 'a.btn[disabled=disabled]', text: 'Request membership', count: 1
end

test 'should not show add new button to admin unless active member' do
admin = FactoryBot.create(:admin)
project = FactoryBot.create(:project)
refute project.has_member?(admin)
login_as(admin)
assert project.can_edit?
get :show, params: { id: project.id }
assert_response :success
assert_select '#buttons' do
assert_select 'div[type=button]', text: /Add new/, count: 0
end
end

test 'should show list of directly linkable assets in add new button to active members' do
person = FactoryBot.create(:person)
project = person.projects.first
login_as(person)
assert project.has_member?(person)
assert project.can_edit?
get :show, params: { id: project.id }
assert_response :success
params = { project_ids: [project.id] }
directly_linked_types = [
Investigation,
Collection,
DataFile,
Document,
Event,
FileTemplate,
Model,
Placeholder,
Presentation,
Publication,
Sample,
SampleType,
Sop,
Strain,
Template,
Workflow,
]
assert_select '#buttons' do
assert_select 'div[type=button]', text: /Add new/
for type in directly_linked_types
assert_select 'a[href=?]', Seek::Util.routes.polymorphic_path(type, action: :new, "#{type.name.underscore}": params)
end
end
end

private

def check_project(project)
Expand Down