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

only show links to services users have access to #4585

Merged
merged 15 commits into from Nov 13, 2023

Conversation

marcwit
Copy link
Contributor

@marcwit marcwit commented Sep 28, 2023

Proposal to improve the display of services in users hub home page by using filters.

While the visibility of services can currently be enabled or disabled by the display value in the jupyterhub_config.py file, there is no fine-grained control of visibility for individual users/groups or the like.
The proposed code changes are intended to address this by introducing the display_filters attribute in the above mentioned file and corresponding adjustments in base.py.
display_filters is currently a Dict() with the keys usernames, groups and roles to filter by. It should be noted that the eventual service will only be displayed if all filters match the respective user.
To implement the filtering, the function get_accessible_services(self, user) in base.py was extended by corresponding lines that (a) read the roles and group membership of the user and (b) perform the filtering and, if the attributes match, add the service to the accessible_services list as usual.
To read the groups and roles, roles.py and user.py have been extended with the respective function/method get_role_names_for(orm_object) and get_groups(self).

In our use case, we want to filter the display of a service based on a group membership, since it is necessary to show the service for certain users and hide it for others.

@welcome
Copy link

welcome bot commented Sep 28, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@minrk
Copy link
Member

minrk commented Oct 3, 2023

Nice! This makes sense. Before I get into detailed review, I have one question: if we filtered based on the appropriate access:services permission, would that suffice (i.e. only show users services they have access to)? Then you wouldn't have two separate collections - visibility and access, you would just have the one - access (which we already have), and visibility is limited to when the link is going to work.

What do you think?

marcwit and others added 3 commits October 4, 2023 11:04
… into visibility-filters-for-services

# Conflicts:
#	jupyterhub/handlers/base.py
#	jupyterhub/services/service.py
@marcwit marcwit changed the title Visibility filters for services Visibility adjustment for services Oct 4, 2023
@marcwit
Copy link
Contributor Author

marcwit commented Oct 4, 2023

That's a good suggestion. I have adapted it to that effect. It looks cleaner and clearer that way.

Is that all right?

@minrk minrk changed the title Visibility adjustment for services only show links to services users have access to Nov 13, 2023
@minrk minrk force-pushed the visibility-filters-for-services branch from 8679f13 to a1a7f22 Compare November 13, 2023 10:31
@minrk
Copy link
Member

minrk commented Nov 13, 2023

Thanks! I tidied up the check a little bit and added a test, but this looks great!

@minrk minrk merged commit e633199 into jupyterhub:main Nov 13, 2023
19 of 20 checks passed
Copy link

welcome bot commented Nov 13, 2023

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants