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

Add home userassignment #86

Merged
merged 31 commits into from
Jan 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f87c369
Add HomeUserRelation
brylie Jan 4, 2024
e288e86
Add home.members
brylie Jan 4, 2024
1908e8b
Register HomeUserRelation
brylie Jan 4, 2024
cd00d43
Add User.homes and get_full_name
brylie Jan 4, 2024
3561629
Fix User.homes
brylie Jan 4, 2024
0ea1e61
Add homes with and without groups
brylie Jan 4, 2024
e7f92a4
Add i18n
brylie Jan 4, 2024
65ba472
Add condition for superuser
brylie Jan 4, 2024
bfbf0ff
Add HomeGroupFactory
brylie Jan 4, 2024
5f7b034
Initial HomeGroupListViewTest
brylie Jan 4, 2024
859cb53
Update test cases for new setUp data
brylie Jan 4, 2024
b8b2cee
Return early for unauthenticated user
brylie Jan 4, 2024
0cc2418
Initial 403 template
brylie Jan 5, 2024
8609e37
Add allowed hosts
brylie Jan 5, 2024
7d767ac
Add authentication on home view
brylie Jan 5, 2024
a2ef475
Add HomeDetailViewTests
brylie Jan 5, 2024
ae67028
Pass user into form; refactor form code
brylie Jan 5, 2024
ae7dc67
Filter home choices by user status
brylie Jan 5, 2024
8f62456
Fix failing tests
brylie Jan 5, 2024
c7e0ad2
Add User.can_add_activity
brylie Jan 5, 2024
1895782
Hide Add Activity button for users who can't add activity
brylie Jan 5, 2024
7141517
Display 403 error for users who can't add activity
brylie Jan 5, 2024
b14604f
Add Privacy and Data Protection Guidelines
brylie Jan 5, 2024
37c0872
Add UserFactory
brylie Jan 5, 2024
0e75760
Add auth tests
brylie Jan 5, 2024
7532731
Add ResidentDataPreparationTest
brylie Jan 5, 2024
18959ec
Add residencies related name
brylie Jan 5, 2024
049c121
Add User.can_manage_residents with test
brylie Jan 5, 2024
dab55a3
Add Resident current residency and home helpers
brylie Jan 5, 2024
2b82313
Fix Home.current_residents
brylie Jan 5, 2024
2bae701
Only allow users to submit activities for related residents
brylie Jan 5, 2024
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
Prev Previous commit
Only allow users to submit activities for related residents
brylie committed Jan 5, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 2bae701d1d7508f80beca97f35ad5dc3f6ffb7dc
3 changes: 3 additions & 0 deletions activities/views.py
Original file line number Diff line number Diff line change
@@ -59,6 +59,9 @@ def post(self, request, *args, **kwargs):
# generate group activity ID based on current epoch time
group_activity_id = uuid.uuid4()

if not request.user.can_manage_residents(resident_ids):
return self.handle_no_permission()

for resident_id in resident_ids:
try:
resident = Resident.objects.get(id=resident_id)
37 changes: 33 additions & 4 deletions metrics/tests.py
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def test_resident_activity_form_view_create_multiple_resident_activity(self):

activity_residents = [self.resident1.id, self.resident2.id]
# Prepare data for POST request
self.data = {
data = {
"residents": activity_residents,
"activity_date": date.today(),
"activity_type": ResidentActivity.ActivityTypeChoices.OUTDOOR,
@@ -112,7 +112,7 @@ def test_resident_activity_form_view_create_multiple_resident_activity(self):
# Make POST request
response = self.client.post(
self.url,
self.data,
data,
)

# The response should indicate a successful form submission
@@ -151,7 +151,7 @@ def test_activity_rollback_on_residency_exception(self):
resident_activity_count_pre = ResidentActivity.objects.all().count()

# Prepare data for POST request with a resident that does not have a residency
self.data = {
data = {
"residents": [non_resident.id],
"activity_type": ResidentActivity.ActivityTypeChoices.OUTDOOR,
"activity_date": date.today(),
@@ -165,7 +165,7 @@ def test_activity_rollback_on_residency_exception(self):
# Make POST request
response = self.client.post(
self.url,
self.data,
data,
)

# The response should indicate a failure to process the form
@@ -191,6 +191,35 @@ def test_activity_rollback_on_residency_exception(self):
# Ensure counts have not changed, indicating a rollback
self.assertEqual(resident_activity_count_pre, resident_activity_count_post)

def test_general_user_get_403_on_post(self):
"""Test that a general user gets a 403 response.

I.e., the user should not be associated with any residents and
so should not be authorized to submit the form.
"""
# log in general user
self.client.force_login(self.general_user)

data = {
"residents": [self.resident1.id],
"activity_type": ResidentActivity.ActivityTypeChoices.OUTDOOR,
"activity_date": date.today(),
"activity_minutes": 30,
"caregiver_role": ResidentActivity.CaregiverRoleChoices.NURSE,
}

# Make POST request
response = self.client.post(
self.url,
data,
)

# The response should indicate a failure to process the form
self.assertEqual(
response.status_code,
HTTPStatus.FORBIDDEN,
)


class ResidentDataPreparationTest(TestCase):
def setUp(self):