From ed92ab4d95596c7dca7983b706ece5f9a4c5f3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 21 Sep 2022 13:24:48 -0300 Subject: [PATCH] =?UTF-8?q?Otimiza=20gera=C3=A7=C3=A3o=20de=20grupos=20com?= =?UTF-8?q?=20base=20no=20LDAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/servidores/models.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sigi/apps/servidores/models.py b/sigi/apps/servidores/models.py index 07855e4..c7eccfc 100644 --- a/sigi/apps/servidores/models.py +++ b/sigi/apps/servidores/models.py @@ -137,9 +137,12 @@ def ajusta_nome_usuario(sender, instance, *args, **kwargs): def user_staff_and_group(user, ldap_user, **kwargs): dep = ldap_user.attrs.get("department", [""])[0] title = ldap_user.attrs.get("title", [""])[0] - group_names = [dep.split("-")[-1], title] - group_names.extend(title.split("-", 1)) - group_names = [s.strip().upper() for s in group_names] + deps = dep.split("-") + titles = [s.strip().upper() for s in title.split("-", 1)] + group_names = [f"{d}-{t}" for d in deps for t in titles] + group_names.extend(deps) + group_names.extend(titles) + group_names.extend([dep, title.upper()]) user.is_staff = "ILB" in dep user.save() user.groups.clear()