Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle mail field #80

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-samb
fi

echo "Downloading user manager ${user_manager_version} UI..."
curl -f -O -L https://github.com/NethServer/ns8-user-manager/releases/download/${user_manager_version}/ns8-user-manager-${user_manager_version}.tar.gz
user_manager_version=mail_notify #FIXME
#curl -f -L -O https://github.com/NethServer/ns8-user-manager/releases/download/${user_manager_version}/ns8-user-manager-${user_manager_version}.tar.gz
curl -f -L -o ns8-user-manager-${user_manager_version}.tar.gz https://github.com/NethServer/ns8-user-manager/archive/refs/heads/mail_notify.tar.gz
#curl -f -O -L https://github.com/NethServer/ns8-user-manager/releases/download/${user_manager_version}/ns8-user-manager-${user_manager_version}.tar.gz

echo "Build static UI files with node..."
buildah run \
Expand Down
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
4 changes: 2 additions & 2 deletions imageroot/api-moduled/handlers/list-users/post
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ request = json.load(sys.stdin)

domain = Ldapproxy().get_domain(os.environ['REALM'].lower())

users = Ldapclient.factory(**domain).list_users()
users = Ldapclient.factory(**domain).list_users(extra_info=True)

users = sorted(users, key=lambda rec: rec['user'])

json.dump({"status": "success", "message": "users_listed", "users": users}, fp=sys.stdout)
json.dump({"status": "success", "message": "users_listed", "users": users}, fp=sys.stdout)
Loading