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

Allow unauthenticated users to view group details #3461

Conversation

ivarnakken
Copy link
Member

No description provided.

@ivarnakken ivarnakken added review-needed Pull requests that need review small-fix Pull requests that fix something small labels Jul 13, 2023
@ivarnakken ivarnakken requested a review from a team July 13, 2023 15:32
@ivarnakken ivarnakken self-assigned this Jul 13, 2023
@linear
Copy link

linear bot commented Jul 13, 2023

ABA-509 Viewing groups when not logged in gives 401

Either they should be public, or not visible on the sidebar as pages at all ..

I think a fine solution is to make the groups public, but to not show its members. Webapp would need minimal changes to accommodate this.

image.png

Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

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

I know the perm system is overly conplex. But it might be better to use the safe_perms property (or something like that). I think it's on the handler class. But a quick grep should lead you to it.

@ivarnakken
Copy link
Member Author

ivarnakken commented Jul 13, 2023

I know the perm system is overly conplex. But it might be better to use the safe_perms property (or something like that). I think it's on the handler class. But a quick grep should lead you to it.

@LudvigHz
There is nothing called safe_perms, but are you referring to safe_methods in PermissionHandler? If so, the safe_methods attribute by itself does not grant permissions; it merely defines which actions are considered "safe" or non-modifying. The actual permission checks are performed in methods such as has_perm and has_object_permissions? Or am I missing something?

@ivarnakken ivarnakken force-pushed the ivarnakken/aba-509-viewing-groups-when-not-logged-in-gives-401 branch 2 times, most recently from 5720834 to 2591f11 Compare July 13, 2023 18:56
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (2826e4c) 88.29% compared to head (f88af40) 88.29%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3461   +/-   ##
=======================================
  Coverage   88.29%   88.29%           
=======================================
  Files         662      662           
  Lines       21005    21006    +1     
=======================================
+ Hits        18546    18547    +1     
  Misses       2459     2459           
Impacted Files Coverage Δ
lego/apps/users/permissions.py 93.65% <100.00%> (+0.10%) ⬆️
lego/apps/users/tests/test_abakusgroup_api.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@LudvigHz
Copy link
Member

There is nothing called safe_perms, but are you referring to safe_methods in PermissionHandler? If so, the safe_methods attribute by itself does not grant permissions; it merely defines which actions are considered "safe" or non-modifying. The actual permission checks are performed in methods such as has_perm and has_object_permissions? Or am I missing something?

Yes, that's the one. The default permission handler will check this attribute against the action and allow the method accordingly. So if you set it to view it should allow users to view the objects in the viewset. Although it requires that the group perm handler does not override too much of the behavior already (it really shouldn't)

@ivarnakken ivarnakken force-pushed the ivarnakken/aba-509-viewing-groups-when-not-logged-in-gives-401 branch from 2591f11 to f88af40 Compare July 14, 2023 14:30
@ivarnakken
Copy link
Member Author

ivarnakken commented Jul 14, 2023

Yes, that's the one. The default permission handler will check this attribute against the action and allow the method accordingly. So if you set it to view it should allow users to view the objects in the viewset. Although it requires that the group perm handler does not override too much of the behavior already (it really shouldn't)

ah yes I now see that PermissionHandler has a similar check for this in has_perm

        if require_auth and not authenticated:
            return False
        elif not require_auth and perm in self.safe_methods:         # <----------
            return True
        if not authenticated:
            return False

Adding authentication_map = {VIEW: False, LIST: False} sets require_auth to False on VIEW and LIST methods.

Seems to work fine.

Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

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

Is this all groups now??

I.e. can any person view any group?

@ivarnakken
Copy link
Member Author

Is this all groups now??

I.e. can any person view any group?

Yes, but not its members. I don’t really see anything wrong with letting them be public, but I’m all ears

@ivarnakken ivarnakken merged commit f16bff5 into master Aug 13, 2023
3 checks passed
@ivarnakken ivarnakken deleted the ivarnakken/aba-509-viewing-groups-when-not-logged-in-gives-401 branch August 13, 2023 16:31
@ivarnakken ivarnakken added approved Pull requests that have been approved ready-to-merge Pull requests that have been approved and are ready to be merged and removed review-needed Pull requests that need review labels Aug 13, 2023
@LudvigHz
Copy link
Member

The only concern was that there are some random groups that are administrative only and not really meant to be accessible by the public. But yeah at least it's not the members but still we might want to have some filter on what is public (in terms of group type (committee, interest group))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Pull requests that have been approved ready-to-merge Pull requests that have been approved and are ready to be merged small-fix Pull requests that fix something small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants