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

2160 internal user can view access requests #2469

Merged
merged 15 commits into from
Nov 21, 2024

Conversation

Sepehr-Sobhani
Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani commented Nov 14, 2024

ISSUE 2160

NOTE:

  • Updated the dashboard tiles and removed unnecessary ones.
  • Added user operator tables to allow internal users to view access requests.
  • Improved the data in the grid by updating the fixtures.
  • Additionally, modified the Django admin tables for user and user-operator data models to enhance their usability.(non-related)

TEST:
Log in as an internal user. Click the Operator Administrators and Access Requests tile to view the data grid.

@Sepehr-Sobhani Sepehr-Sobhani force-pushed the 2160-internal-user-can-view-access-requests branch 3 times, most recently from 18ab093 to 80ef128 Compare November 19, 2024 23:55
Copy link
Contributor

@BCerki BCerki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

assert response.status_code == 200
response_items_1 = response.json().get('items')
assert response_items_1[0].get('user__first_name') == "Jane"
# Test with a type filter that doesn't exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover comment? This test looks like it's checking the name filter

assert response.status_code == 200
response_data = response.json()
assert len(response_data) == 2
# assert one of the approved admin user operators is in the response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert "one is in the response" as in we're checking one of the two as a sample? Or we actually only expect one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only wanted to test one of them as a sample.

== approved_admin_user_operator_to_check.user.bceid_business_name
)
assert (
approved_admin_user_operator_in_response["operator__legal_name"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we check them one by one like this, it's possible there could be an extra value in there that we don't want and this test isn't catching. We could check that the whole object == expected object, or that the keys match what we expect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test to make sure we get the expected keys.

operator__status=Operator.Statuses.DECLINED
)
# Subquery to check if an approved admin user exists for the operator
approved_admin_operator_exists = UserOperator.objects.filter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cool, nice and readable

@@ -14,6 +15,11 @@ def handle_exception(error: Exception) -> Tuple[Literal[400, 401, 403, 404, 422]
"""
This function handles exceptions for BCEIRS. Returns a 4xx status.
"""
if DEBUG == "True":
# Print the error in the console for easier debugging
print("---------------------------------------------ERROR START-----------------------------------------------")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

)
)

# Add approved admin user for the approved operator (to prevent showing pending user operators for this operator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably more in the loop about this than me, but I thought the plan for reg2 was to show all the user operators in the table regardless of if there's already an admin or who approved them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this with Andrea and Zoey, but I forgot to document it in this ticket. Sorry for that. Here’s the conversation: #2059 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks. Internal users don't get to approve/deny after the first admin, but are they supposed to get to view everyone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they prefer to have a minimal number of requests in this table. From what I understand, seeing a record in the table without being able to change it might be annoying for them. Calling @andrea-williams to take radical decisions lol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm overruling a comment that one SME said (that I believe was just casual and not something they were committing to). IMO it doesn't make sense to show ALL industry admins in that grid when internal users are only expected to action some of them. Internal users can view all users for a specific operator and view the admins from there if they need to.

Boom. Radical Decision made.

Comment on lines +58 to +63
# make sure only irc user can access this
industry_user = baker.make_recipe('utils.industry_operator_user')
with pytest.raises(Exception, match=UNAUTHORIZED_MESSAGE):
UserOperatorServiceV2.list_user_operators_v2(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a long test, could move some parts (e.g. testing for exceptions) into their own tests

assert user_operators_with_admin_access_status.filter(status=UserOperator.Statuses.APPROVED).count() == 5

# Check sorting
filters_3 = filters_2.model_copy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool


it("renders UserOperatorsPage with the note on top of the page", async () => {
getUserOperatorsPageData.mockReturnValueOnce({
data: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a third test that does have data (there's already in-depth testing of the grid in the grid test, so the one here could be super simple and just check number of rows or something to make sure the page does correctly handle a non-empty data array)

def list_user_operators_v2(
request: HttpRequest,
filters: UserOperatorFilterSchema = Query(...),
sort_field: Optional[str] = "created_at",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created_at isn't one of the grid columns, does that matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, created_at serves as the default value for sorting when users do not specify their own sorting preferences.(It's used for the query)

@Sepehr-Sobhani Sepehr-Sobhani force-pushed the 2160-internal-user-can-view-access-requests branch from 9c23643 to 5f1c36c Compare November 21, 2024 21:57
Copy link
Contributor

@BCerki BCerki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤸

@Sepehr-Sobhani Sepehr-Sobhani merged commit 7f9684f into develop Nov 21, 2024
40 checks passed
@Sepehr-Sobhani Sepehr-Sobhani deleted the 2160-internal-user-can-view-access-requests branch November 21, 2024 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants