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

RAS-1289 Update the way claims is determined in the party service: #428

Merged
merged 3 commits into from
Sep 20, 2024
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
4 changes: 2 additions & 2 deletions _infra/helm/secure-message/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 2.1.75
version: 2.1.76

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 2.1.75
appVersion: 2.1.76
2 changes: 1 addition & 1 deletion secure_message/api_mocks/party_service_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_users_details(self, uuids):
user_details = []
return user_details

def does_user_have_claim(self, user_id, business_id):
def does_user_have_claim(self, user_id, business_id, _):
LJBabbage marked this conversation as resolved.
Show resolved Hide resolved
user_details = self._respondent_ids[user_id]
associations = user_details["associations"]
is_enrolled = self._is_user_associated_to_business(associations, business_id)
Expand Down
2 changes: 1 addition & 1 deletion secure_message/resources/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def post(self):
def _has_valid_claim(user, message: Message) -> bool:
"""Validates that the user has a valid claim to interact with the business and survey in the post data
internal users have claims to everything, respondents need to check against party"""
return user.is_internal or party.does_user_have_claim(user.user_uuid, message.business_id)
return user.is_internal or party.does_user_have_claim(user.user_uuid, message.business_id, message.survey_id)

@staticmethod
def _message_save(message: Message):
Expand Down
4 changes: 2 additions & 2 deletions secure_message/services/party_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def get_users_details(self, uuids):
return self._get_user_details_from_party_service(uuids)

@staticmethod
def does_user_have_claim(user_id: str, business_id: str) -> bool:
def does_user_have_claim(user_id: str, business_id: str, survey_id: str) -> bool:
"""Returns true of the user id has a claim on the business_id, survey_id combination
False if not.

Rather than inspect the respondent data it defers to Party Service for the precise logic
to determine what constitutes a valid claim so as to maintain separation of concerns and
avoid future maintenance issues.
"""
params = {"respondent_id": user_id, "business_id": business_id}
params = {"respondent_id": user_id, "business_id": business_id, "survey_id": survey_id}

response = requests.get(
f"{current_app.config['PARTY_URL']}/party-api/v1/respondents/claim",
Expand Down
4 changes: 2 additions & 2 deletions secure_message/services/service_toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def get_user_details(self, uuid):
def get_users_details(self, uuids):
return self._service.get_users_details(uuids)

def does_user_have_claim(self, user_id, business_id):
return self._service.does_user_have_claim(user_id, business_id)
def does_user_have_claim(self, user_id, business_id, survey_id):
return self._service.does_user_have_claim(user_id, business_id, survey_id)


class InternalUser(ServiceMockToggle):
Expand Down
9 changes: 6 additions & 3 deletions tests/app/test_mock_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ def test_get_business_details_returns_none_if_business_id_not_known(self):
def test_get_does_user_have_claim_returns_true_if_known(self):
user_id = "ab123456-ce17-40c2-a8fc-abcdef123456"
business_id = "b3ba864b-7cbc-4f44-84fe-88dc018a1a4c"
survey_id = "ab822606-e9a7-41bc-bbfd-f0cfddcd25b5"
sut = PartyServiceMock()
result = sut.does_user_have_claim(user_id, business_id)
result = sut.does_user_have_claim(user_id, business_id, survey_id)
self.assertTrue(result)

def test_get_does_user_have_claim_returns_false_for_unknown_business_id(self):
user_id = "ab123456-ce17-40c2-a8fc-abcdef123456"
business_id = "somethingunknown"
survey_id = "ab822606-e9a7-41bc-bbfd-f0cfddcd25b5"
sut = PartyServiceMock()
result = sut.does_user_have_claim(user_id, business_id)
result = sut.does_user_have_claim(user_id, business_id, survey_id)
self.assertFalse(result)

def test_get_does_user_have_claim_returns_false_for_not_active_user(self):
user_id = "inactive_user"
business_id = "b3ba864b-7cbc-4f44-84fe-88dc018a1a4c"
survey_id = "ab822606-e9a7-41bc-bbfd-f0cfddcd25b5"
sut = PartyServiceMock()
result = sut.does_user_have_claim(user_id, business_id)
result = sut.does_user_have_claim(user_id, business_id, survey_id)
self.assertFalse(result)


Expand Down
Loading