Skip to content

Commit

Permalink
Only Allow Principal Investigators Access to Protocol Form
Browse files Browse the repository at this point in the history
This restricts the ability of users who aren't principal investigators
such that they cannot access the form to create a new study protocol. A
principal investigator must be the type of user to create this
information.
  • Loading branch information
kevin-j-m committed Mar 10, 2019
1 parent afb2dec commit 58597ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/controllers/study_protocols_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class StudyProtocolsController < ApplicationController
def new
@study_protocol = StudyProtocol.new(study: study)
if current_user.principal_investigator?
@study_protocol = StudyProtocol.new(study: study)
else
flash[:alert] = "Only Principal Investigators may create study protocols"
redirect_back(fallback_location: root_path)
end
end

def create
Expand Down
16 changes: 15 additions & 1 deletion spec/system/create_study_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe "Creating a study protocol", type: :system do
scenario "Successfully adding a protocol" do
user = create :user
user = create :user, :principal_investigator
sign_in user

study = create :study
Expand All @@ -16,4 +16,18 @@
expect(page).to have_content "Ask how they are feeling."
end
end

scenario "Co-investigators cannot create a study protocol" do
user = create :user, :co_investigator
sign_in user

study = create :study
visit new_study_study_protocol_path(study)

within(".alert-danger") do
expect(page).to have_content "Only Principal Investigators may create study protocols"
end

expect(page).to have_current_path root_path
end
end

0 comments on commit 58597ff

Please sign in to comment.