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

✨(maildomain_access) add API endpoint to search users #561

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

sdemagny
Copy link
Contributor

closes #508

@sdemagny sdemagny requested a review from qbey November 26, 2024 23:27
@sdemagny sdemagny force-pushed the sdem/search_user_domain branch from 75b44d1 to 23eb00b Compare November 26, 2024 23:28
@sdemagny sdemagny changed the title ✨(maildomain_access) Add API endpoint to search users ✨(maildomain_access) add API endpoint to search users Nov 26, 2024
@sdemagny sdemagny changed the title ✨(maildomain_access) add API endpoint to search users ✨(domain_access) add API endpoint to search users Nov 26, 2024
@sdemagny sdemagny changed the title ✨(domain_access) add API endpoint to search users ✨(maildomain_access) add API endpoint to search users Nov 26, 2024
@sdemagny sdemagny force-pushed the sdem/search_user_domain branch 2 times, most recently from 68ae501 to 10e7537 Compare November 27, 2024 00:21
@sdemagny
Copy link
Contributor Author

Dans les get_abilities il y a manage_access qui me permettrait de limiter l'accès à ce endpoint.
On devrait probablement limiter aussi les utilisateurs trouvés aux organisations ? @qbey
C'est un premier jet un peu basique qui devrait faire un minimum le job. Je me dis que j'affinerai dans un second temps.

Copy link
Member

@qbey qbey left a comment

Choose a reason for hiding this comment

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

Je pense que tu as raison, ça serait bien de limiter aux utilisateurs de la même organisation :)

@action(detail=False, url_path="users", methods=["get"])
def get_available_users(self, request, domain_slug):
"""API endpoint to search user to give them new access.
More filters and permission will be added soon.
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 bit of a nitpick, but I feel that docstrings should be focused on the current state of the code, it's not really their job to say what is "coming soon".

core_models.User.objects.all()
.order_by("-created_at")
# exclude inactive contacts
.filter(is_active=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

This filter is not exercised by the test, I think ?

More filters and permission will be added soon.
"""
queryset = (
core_models.User.objects.all()
Copy link
Contributor

Choose a reason for hiding this comment

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

A note here that this raises a similar problem to issue #35 - if I'm authenticated it lets me see (effectively) all users.

From an API design perspective it's also a bit weird because this is an endpoint where we specify a domain, in order to see all users who do not have access to that domain (L199). It makes L79 quite misleading.

It would perhaps be more coherent to have an "exclude_by_domain_access" parameter on the /users/ endpoint ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(On the /users/ endpoint we already have a parameter - undocumented - to exclude users already on a team… I think for similar reasons; for consistency and for better clarity they should be named something like exclude_xxx)

@sdemagny sdemagny force-pushed the sdem/search_user_domain branch 3 times, most recently from 3ffe70c to c8b5673 Compare December 12, 2024 19:49
@sdemagny sdemagny requested a review from qbey December 12, 2024 19:50
@sdemagny sdemagny force-pushed the sdem/search_user_domain branch 3 times, most recently from 74a54ae to dac3cd3 Compare December 12, 2024 20:01
Comment on lines +196 to +198
abilities = domain.get_abilities(request.user)
if not abilities["manage_accesses"]:
raise exceptions.PermissionDenied()
Copy link
Member

Choose a reason for hiding this comment

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

Should you consider adding a get_available_users to the abilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User needs to list available users to manage access, so adding get_available_users to abilities would be a duplicate.

Comment on lines 81 to 82
if role == enums.MailDomainRoleChoices.VIEWER:
assert response.status_code == status.HTTP_403_FORBIDDEN
else:
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, but this is a bad pattern in tests, there should not be logic like that here :/

Comment on lines 162 to 181
if role == enums.MailDomainRoleChoices.VIEWER:
assert response.status_code == status.HTTP_403_FORBIDDEN
else:
Copy link
Member

Choose a reason for hiding this comment

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

Same here, we don't want logic in tests

@sdemagny sdemagny force-pushed the sdem/search_user_domain branch from dac3cd3 to f2900ef Compare December 13, 2024 12:46
@sdemagny sdemagny requested review from mjeammet and qbey December 13, 2024 13:19
Add new API endpoint to search for new users
to whom we can assign new roles.
@sdemagny sdemagny force-pushed the sdem/search_user_domain branch from f2900ef to 5d84e22 Compare December 13, 2024 15:27
@sdemagny sdemagny merged commit 5d84e22 into main Dec 13, 2024
20 checks passed
@sdemagny sdemagny deleted the sdem/search_user_domain branch December 13, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants