Skip to content

Commit

Permalink
Define the destriy function for assays
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin De Pelseneer committed Aug 21, 2023
1 parent 404a7c5 commit 712da50
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AssaysController < ApplicationController
api_actions :index, :show, :create, :update, :destroy

def new_object_based_on_existing_one
@existing_assay = Assay.find(params[:id])
@existing_assay = Assay.find(params[:id])
@assay = @existing_assay.clone_with_associations

if @existing_assay.can_view?
Expand Down Expand Up @@ -62,9 +62,7 @@ def new_object_based_on_existing_one
flash[:error]="You do not have the necessary permissions to copy this #{t('assays.assay')}"
redirect_to @existing_assay
end


end
end

def new
@assay=setup_new_asset
Expand Down Expand Up @@ -112,6 +110,29 @@ def create
end
end

def destroy
raise 'This assay is not empty. Unable to delete this assay' unless @assay.state_allows_delete?

raise "You are don't have permission to delete this assay!" unless current_user.can_delete?

# hkvdghvshdbvjh
project_id = @assay.projects&.first&.id

@assay.sample_type.delete if is_single_page_assay?
@assay.delete

if is_single_page_assay?
flash[:notice] = "ISA Assay successfully deleted!"
redirect_to single_page_path(Project.find(project_id))
else
flash[:notice] = "Assay successfully deleted!"
redirect_to new_assay_path(:class => @assay.assay_class)
end
rescue StandardError => e
flash[:error] = "#{e}. Couldn't delete Assay!"
render json: { status: :unprocessable_entity, error: e.message }
end

def update
update_assay_organisms @assay, params
update_assay_human_diseases @assay, params
Expand Down Expand Up @@ -177,4 +198,8 @@ def assay_params
assay_params[:model_ids].select! { |id| Model.find_by_id(id).try(:can_view?) } if assay_params.key?(:model_ids)
end
end

def is_single_page_assay?
params[:return_to].start_with? '/single_pages/'
end
end

0 comments on commit 712da50

Please sign in to comment.