mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Allow adding users to specific groups
This commit is contained in:
@@ -13,12 +13,16 @@ from tljh.normalize import generate_system_username
|
||||
from tljh.yaml import yaml
|
||||
from jupyterhub_traefik_proxy import TraefikTomlProxy
|
||||
|
||||
from traitlets import Any
|
||||
|
||||
class UserCreatingSpawner(SystemdSpawner):
|
||||
"""
|
||||
SystemdSpawner with user creation on spawn.
|
||||
|
||||
FIXME: Remove this somehow?
|
||||
"""
|
||||
user_groups = Any(config=True)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Perform system user activities before starting server
|
||||
@@ -34,6 +38,10 @@ class UserCreatingSpawner(SystemdSpawner):
|
||||
user.ensure_user_group(system_username, 'jupyterhub-admins')
|
||||
else:
|
||||
user.remove_user_group(system_username, 'jupyterhub-admins')
|
||||
if self.user_groups:
|
||||
for group, users in self.user_groups.items():
|
||||
if self.user.name in users:
|
||||
user.ensure_user_group(system_username, group)
|
||||
return super().start()
|
||||
|
||||
c.JupyterHub.spawner_class = UserCreatingSpawner
|
||||
|
||||
Reference in New Issue
Block a user