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
get groups from authenticator; improve group mgmt on admin page #3307
Conversation
* Authenticator can supply a group field with group memberships for user Groups will be created if no already existing * Manage groups via admin page * Add and delete groups * assign and revoke groups to/from users
|
Thanks for submitting your first pull request! You are awesome! 🤗 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests still missing
jupyterhub/apihandlers/groups.py
Outdated
| self.db.commit() | ||
| deleted.append(group) | ||
| self.write(json.dumps([self.group_model(group) for group in deleted])) | ||
| self.set_status(201) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the correct return code for bulk delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
204, generally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has to be 200, as 204 does not allow to have a body
| @@ -195,7 +203,7 @@ async def get(self, name): | |||
| @admin_only | |||
| async def post(self, name): | |||
| data = self.get_json_body() | |||
| user = self.find_user(name) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the full User Object?!
jupyterhub/apihandlers/users.py
Outdated
| @@ -244,7 +259,7 @@ async def delete(self, name): | |||
|
|
|||
| @admin_only | |||
| async def patch(self, name): | |||
| user = self.find_user(name) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the full User object here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a downside to consistency? In nearly all cases, the user is in memory already, and this adds only a single dict lookup to return the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I left a little feedback int he Python code, but everything looks nice. I will take the UI updates for a spin a bit later.
jupyterhub/apihandlers/groups.py
Outdated
| self.db.commit() | ||
| deleted.append(group) | ||
| self.write(json.dumps([self.group_model(group) for group in deleted])) | ||
| self.set_status(201) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
204, generally
jupyterhub/apihandlers/users.py
Outdated
| @@ -244,7 +259,7 @@ async def delete(self, name): | |||
|
|
|||
| @admin_only | |||
| async def patch(self, name): | |||
| user = self.find_user(name) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a downside to consistency? In nearly all cases, the user is in memory already, and this adds only a single dict lookup to return the object.
jupyterhub/apihandlers/users.py
Outdated
| else: | ||
| setattr(user, key, value) | ||
| self.db.commit() | ||
| user_ = self.user_model(user) | ||
| user_['auth_state'] = await user.get_auth_state() | ||
| user_['auth_state'] = await self._user_from_orm(user).get_auth_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see by this call to _user_from_orm that the above find_user really is required, so it should probably be put back.
| @@ -734,6 +735,15 @@ async def auth_to_user(self, authenticated, user=None): | |||
| if admin is not None and admin != user.admin: | |||
| user.admin = admin | |||
| self.db.commit() | |||
| # add user to the given groups | |||
| if groups is not None: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
As #3548 is merged, I close this PR. |

Authenticator can supply a group field with group memberships for user
Groups will be created if no already existing
Manage groups via admin page
Self clearing fixtures for user(s) and group(s)