persist agent OU over SSO (#22222)

This commit is contained in:
Frédéric Péters 2018-03-08 17:55:01 +01:00
parent 6ecdbf370a
commit a917556ff5
1 changed files with 15 additions and 0 deletions

View File

@ -15,10 +15,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.conf import settings
from django_rbac.utils import get_ou_model
class AppConfig(django.apps.AppConfig):
name = 'authentic2_gnm'
def a2_hook_auth_oidc_backend_modify_user(self, user, user_info, **kwargs):
ou_map = {ou.slug: ou for ou in get_ou_model().cached()}
# move user to the correct organizational unit
user_ou_slug = settings.CUT_GNM_OU_MAPPING.get(user_info.get('ou'))
if user_ou_slug:
user_ou = ou_map.get(user_ou_slug)
if user_ou and user_ou != user.ou:
user.ou = user_ou
return True
return False
default_app_config = 'authentic2_gnm.AppConfig'