Skip to content

Commit 39893c2

Browse files
committedMar 12, 2025
fix: delete mail field on edit
Preserve existing behavior: if a field is not specified, it will not be overwritten. To remove a mail address, just pass an empty string as value Note: a mail address with an aempty string is not allowed by AD
1 parent 54c5aa0 commit 39893c2

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
 

‎imageroot/api-moduled/handlers/add-user/validate-input.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@
5656
"mail": {
5757
"title": "Email address",
5858
"type": "string",
59-
"format": "email"
59+
"oneOf": [
60+
{
61+
"type": "string",
62+
"format": "email"
63+
},
64+
{
65+
"type": "string",
66+
"maxLength": 0
67+
}
68+
]
6069
}
6170
},
6271
"$defs": {}

‎imageroot/api-moduled/handlers/alter-user/post

+6-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ if 'mail' in request:
6565
getdn_cmd = sambatool_cmd + ['user', 'show', user, '--attributes=dn']
6666
proc = subprocess.run(getdn_cmd, check=True, capture_output=True, text=True)
6767
dn = proc.stdout.strip()
68-
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-i', '-H', '/var/lib/samba/private/sam.ldb']
69-
ldbedit_input = f'{dn}\nchangetype: modify\nreplace: mail\nmail: {mail}\n'
70-
subprocess.run(ldbedit_cmd, input=ldbedit_input, stdout=sys.stderr, check=True, text=True)
71-
else:
72-
# remove mail attribute
73-
getdn_cmd = sambatool_cmd + ['user', 'show', user, '--attributes=dn']
74-
proc = subprocess.run(getdn_cmd, check=True, capture_output=True, text=True)
75-
dn = proc.stdout.strip()
76-
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-i', '-H', '/var/lib/samba/private/sam.ldb']
77-
ldbedit_input = f'{dn}\nchangetype: modify\ndelete: mail\n'
68+
if mail != '':
69+
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-i', '-H', '/var/lib/samba/private/sam.ldb']
70+
ldbedit_input = f'{dn}\nchangetype: modify\nreplace: mail\nmail: {mail}\n'
71+
else:
72+
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-H', '/var/lib/samba/private/sam.ldb']
73+
ldbedit_input = f'{dn}\nchangetype: modify\ndelete: mail\n'
7874
subprocess.run(ldbedit_cmd, input=ldbedit_input, stdout=sys.stderr, check=True, text=True)
7975

8076
json.dump({"status": "success", "message": "user_altered"}, fp=sys.stdout)

‎imageroot/api-moduled/handlers/alter-user/validate-input.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@
5656
"mail": {
5757
"title": "Email address",
5858
"type": "string",
59-
"format": "email"
59+
"oneOf": [
60+
{
61+
"type": "string",
62+
"format": "email"
63+
},
64+
{
65+
"type": "string",
66+
"maxLength": 0
67+
}
68+
]
6069
}
6170
},
6271
"$defs": {}

0 commit comments

Comments
 (0)