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:
@@ -27,6 +27,7 @@ default = {
|
||||
'allowed': [],
|
||||
'banned': [],
|
||||
'admin': [],
|
||||
'groups': {}
|
||||
},
|
||||
'limits': {
|
||||
'memory': None,
|
||||
@@ -93,6 +94,7 @@ def apply_config(config_overrides, c):
|
||||
|
||||
update_auth(c, tljh_config)
|
||||
update_userlists(c, tljh_config)
|
||||
update_usergroups(c, tljh_config)
|
||||
update_limits(c, tljh_config)
|
||||
update_user_environment(c, tljh_config)
|
||||
update_user_account_config(c, tljh_config)
|
||||
@@ -168,6 +170,14 @@ def update_userlists(c, config):
|
||||
c.Authenticator.admin_users = set(users['admin'])
|
||||
|
||||
|
||||
def update_usergroups(c, config):
|
||||
"""
|
||||
Set user groups
|
||||
"""
|
||||
users = config['users']
|
||||
c.UserCreatingSpawner.user_groups = users['groups']
|
||||
|
||||
|
||||
def update_limits(c, config):
|
||||
"""
|
||||
Set user server limits
|
||||
|
||||
@@ -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