-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the ability to restrict access to patients to the model layer
- Loading branch information
Showing
7 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class AuthorizedUser < ActiveRecord::Base | ||
belongs_to :patient | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
class Patient < ActiveRecord::Base | ||
has_many :documents | ||
has_many :authorized_users | ||
|
||
scope :accessible_to, ->(email) {joins(:authorized_users).where(authorized_users: {email: email})} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateAuthorizedUsers < ActiveRecord::Migration | ||
def change | ||
create_table :authorized_users do |t| | ||
t.string :email | ||
t.references :patient | ||
|
||
t.timestamps | ||
end | ||
add_index :authorized_users, :patient_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
email: [email protected] | ||
patient: one | ||
|
||
two: | ||
email: [email protected] | ||
patient: two | ||
|
||
three: | ||
email: [email protected] | ||
patient: two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class AuthorizedUserTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
require 'test_helper' | ||
|
||
class PatientTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
test 'users can only see patients they have access to' do | ||
assert_equal 2, Patient.accessible_to('[email protected]').count | ||
assert_equal 1, Patient.accessible_to('[email protected]').count | ||
assert_equal 0, Patient.accessible_to('[email protected]').count | ||
end | ||
end |