Skip to content
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
15 changes: 15 additions & 0 deletions app/controllers/boxes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def index
def show
return unless authorize_resource(@box, READ_BOX)
@can_delete = has_access?(@box, DELETE_BOX)
@can_blind = !@box.transferred?

@samples = load_box_samples
end
Expand Down Expand Up @@ -91,6 +92,20 @@ def bulk_destroy
redirect_to boxes_path, notice: "Boxes were successfully deleted."
end

def unblind
return head :forbidden if @box.transferred?
@box.unblind!

redirect_to box_path(@box), notice: "Samples were successfully unblinded."
end

def blind
return head :forbidden if @box.transferred?
@box.blind!

redirect_to box_path(@box), notice: "Samples were successfully blinded."
end

private

def load_box
Expand Down
8 changes: 8 additions & 0 deletions app/models/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ def blind_attribute?(attr_name)
def transferred?
box_transfers.exists?
end

def unblind!
update_columns(blinded: false)
end

def blind!
update_columns(blinded: true)
end
end
14 changes: 12 additions & 2 deletions app/views/boxes/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@
- unless sample.blinded_attribute?(:batch_number)
.sample-row-action= sample.batch_number

- if @can_delete
.row.button-actions
.row.button-actions
- if @can_blind
- if @box.blinded
= link_to unblind_box_path(@box), class: "btn btn-icon", method: "post" do
%i.icon-eye.icon-blue
UNBLIND SAMPLES
-else
= link_to blind_box_path(@box), class: "btn btn-icon", method: "post" do
%i.icon-eye.icon-blue
BLIND SAMPLES

- if @can_delete
.col
= confirm_deletion_button @box, 'box'
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@
end
resources :boxes, except: [:edit, :update] do
member do
post :unblind
post :blind
get 'print'
get 'inventory', constraints: { format: 'csv' }
end
Expand Down
33 changes: 32 additions & 1 deletion spec/controllers/boxes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
@site = Site.make! institution: @institution
@site_box = Box.make! institution: @institution, site: @site

@other_user = Institution.make!.user
@other_institution = Institution.make!
@other_user = @other_institution.user

@confirmed_transfer = TransferPackage.make! :receiver_confirmed, sender_institution: @institution, receiver_institution: @other_institution
@confirmed_box = @confirmed_transfer.box_transfers[0].box

grant @user, @other_user, @institution, READ_INSTITUTION
end

Expand Down Expand Up @@ -103,6 +108,32 @@
end
end

describe "blind" do
it "before transfer: owner institution can blind box" do
post :blind, params: { id: box.id }
expect(response).to have_http_status(:found)
end

it "after transfer: owner institution can't blind box" do
sign_in other_user
post :blind, params: { id: confirmed_box.id, context: other_institution.uuid }
expect(response).to have_http_status(:forbidden)
end
end

describe "unblind" do
it "before transfer: owner institution can unblind box" do
post :unblind, params: { id: box.id }
expect(response).to have_http_status(:found)
end

it "after tranfer: owner institution can't unblind box" do
sign_in other_user
post :blind, params: { id: confirmed_box.id, context: other_institution.uuid }
expect(response).to have_http_status(:forbidden)
end
end

describe "print" do
before do
stub_request(:get, %r{https://fonts\.googleapis\.com/.*}).to_return(body: "")
Expand Down