File sso_pipeline_opensuse.py of Package netbox
"""
Custom SSO pipeline hook for better integration with idm.infra.opensuse.org -
synchronizes the name and groups of a user on every login (if enabled through
'netbox.sso_pipeline_opensuse.set_opensuse' in SOCIAL_AUTH_PIPELINE).
Copyright (C) 2024 Georg Pfuetzenreuter <mail+opensuse@georg-pfuetzenreuter.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
def set_opensuse(response, user, **kwargs):
groups = response.get('groups', [])
user.username = response['preferred_username']
user.is_staff = 'netbox-admins@infra.opensuse.org' in groups
user.is_superuser = 'netbox-superusers@infra.opensuse.org' in groups
user.save()