Skip to content

Commit

Permalink
feat: handle mail field
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Mar 6, 2025
1 parent 78869a9 commit 45c44bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
11 changes: 11 additions & 0 deletions imageroot/api-moduled/handlers/add-user/post
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ groups = request.get('groups', [])
password = request.get('password', '')
display_name = request.get('display_name', '')
locked = request.get('locked', False)
mail = request.get('mail', '')

sambatool_cmd = ['podman', 'exec', '-i', 'samba-dc', 'samba-tool']
adduser_cmd = sambatool_cmd + ['user', 'create', user]
Expand All @@ -55,4 +56,14 @@ if display_name:
'pdbedit', '-u', user, f'--fullname={display_name}']
subprocess.run(setname_cmd, stdout=sys.stderr, check=True, text=True)

if mail:
# retrieve the user's DN, example:
# dn: CN=Administrator,CN=Users,DC=ad,DC=leader,DC=cluster0,DC=gs,DC=nethserver,DC=net
getdn_cmd = sambatool_cmd + ['user', 'show', user, '--attributes=dn']
proc = subprocess.run(getdn_cmd, check=True, capture_output=True, text=True)
dn = proc.stdout.strip()
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-i', '-H', '/var/lib/samba/private/sam.ldb']
ldbedit_input = f'{dn}\nchangetype: modify\nreplace: mail\nmail: {mail}\n'
subprocess.run(ldbedit_cmd, input=ldbedit_input, stdout=sys.stderr, check=True, text=True)

json.dump({"status": "success", "message": "user_created"}, fp=sys.stdout)
8 changes: 7 additions & 1 deletion imageroot/api-moduled/handlers/add-user/validate-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"locked": false,
"groups": [
"developers"
]
],
"mail": "[email protected]"
}
],
"required": [
Expand Down Expand Up @@ -51,6 +52,11 @@
"type": "string",
"minLength": 1
}
},
"mail": {
"title": "Email address",
"type": "string",
"format": "email"
}
},
"$defs": {}
Expand Down
11 changes: 11 additions & 0 deletions imageroot/api-moduled/handlers/alter-user/post
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ if 'display_name' in request:
'pdbedit', '-u', user, f'--fullname={display_name}']
subprocess.run(setname_cmd, stdout=sys.stderr, check=True, text=True)

if 'mail' in request:
mail = request['mail']
# retrieve the user's DN, example:
# dn: CN=Administrator,CN=Users,DC=ad,DC=leader,DC=cluster0,DC=gs,DC=nethserver,DC=net
getdn_cmd = sambatool_cmd + ['user', 'show', user, '--attributes=dn']
proc = subprocess.run(getdn_cmd, check=True, capture_output=True, text=True)
dn = proc.stdout.strip()
ldbedit_cmd = ['podman', 'exec', '-i', 'samba-dc', 'ldbmodify', '-i', '-H', '/var/lib/samba/private/sam.ldb']
ldbedit_input = f'{dn}\nchangetype: modify\nreplace: mail\nmail: {mail}\n'
subprocess.run(ldbedit_cmd, input=ldbedit_input, stdout=sys.stderr, check=True, text=True)

json.dump({"status": "success", "message": "user_altered"}, fp=sys.stdout)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"locked": false,
"groups": [
"developers","managers"
]
],
"mail": "[email protected]"
}
],
"required": [
Expand Down Expand Up @@ -51,6 +52,11 @@
"uniqueItems": true,
"minLength": 1
}
},
"mail": {
"title": "Email address",
"type": "string",
"format": "email"
}
},
"$defs": {}
Expand Down

0 comments on commit 45c44bc

Please sign in to comment.