Skip to content

Commit

Permalink
Add User UUID readonly on user edit field #74
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean28518 committed Apr 27, 2024
1 parent a597c5a commit 21c6387
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lac/idm/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AdministratorUserForm(forms.Form):
admin = forms.BooleanField(label="Administrator", required=False, widget=forms.CheckboxInput)

class AdministratorUserEditForm(forms.Form):
guid = forms.CharField(label="objectGUID", max_length=100, disabled=True, required=False)
password = forms.CharField(label="Neues Passwort setzen", max_length=100, widget=forms.PasswordInput, required=False)
first_name = forms.CharField(label="Vorname", max_length=100, required=False)
last_name = forms.CharField(label="Nachname", max_length=100, required=False)
Expand Down
6 changes: 3 additions & 3 deletions src/lac/idm/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_user_information_of_cn(cn):
user_information["last_name"] = ldap_reply[0][1].get("sn", [b""])[0].decode('utf-8')
user_information["displayName"] = ldap_reply[0][1].get("displayName", [b""])[0].decode('utf-8')
user_information["mail"] = ldap_reply[0][1].get("mail", [b""])[0].decode('utf-8')
user_information["objectGUID"] = ldap_reply[0][1].get("objectGUID", [b""])[0].hex()
user_information["guid"] = ldap_reply[0][1].get("objectGUID", [b""])[0].hex()
user_information["enabled"] = int(ldap_reply[0][1].get("userAccountControl", [b'512'])[0]) & 2 == 0
user_information["dn"] = dn
user_information["cn"] = cn
Expand Down Expand Up @@ -205,15 +205,15 @@ def ldap_get_all_users():
mail = user.get("mail", [b''])[0].decode('utf-8')
cn = user.get("cn", [b''])[0].decode('utf-8')
groups = user.get("memberOf", [])
objectGUID = user.get("objectGUID", [b''])[0].hex()
guid = user.get("objectGUID", [b''])[0].hex()
enabled = int(user.get("userAccountControl", [b'512'])[0]) & 2 == 0
for i in range(len(groups)):
groups[i] = groups[i].decode('utf-8')

if ldap_is_system_user(cn):
continue

users.append({"dn": dn, "displayName": displayName, "mail": mail, "cn": cn, "groups": groups, "objectGUID": objectGUID, "enabled": enabled, "admin": is_user_in_group({"groups": groups}, "Administrators")})
users.append({"dn": dn, "displayName": displayName, "mail": mail, "cn": cn, "groups": groups, "guid": guid, "enabled": enabled, "admin": is_user_in_group({"groups": groups}, "Administrators")})
return users

def ldap_is_system_user(cn):
Expand Down
1 change: 1 addition & 0 deletions src/lac/idm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def edit_user(request, cn):
form = AdministratorUserEditForm()
if form_data != {}:
form = AdministratorUserEditForm(form_data)
form.fields["guid"].initial = form_data.get("guid", "")
return render(request, "idm/admin/edit_user.html", {"form": form, "message": message, "cn": cn})#

@staff_member_required(login_url=settings.LOGIN_URL)
Expand Down
2 changes: 1 addition & 1 deletion src/lac/unix/unix_scripts/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def get_nextcloud_user_directories():
for ldap_user in ldap_users:
for nextcloud_user in nextcloud_users:
# Match only the last 8 characters of the objectGUID with the last 8 characters of the username, because the objectGUID of ldap_users is slightly different from the username of nextcloud_users
if ldap_user["objectGUID"].upper()[-8:-1] == nextcloud_user["name"].replace("-", "")[-8:-1]:
if ldap_user["guid"].upper()[-8:-1] == nextcloud_user["name"].replace("-", "")[-8:-1]:
nextcloud_user["name"] = ldap_user["cn"]

return nextcloud_users
Expand Down

0 comments on commit 21c6387

Please sign in to comment.