*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit a7ecc311 authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Add command for managing user roles in InvenioRDM

parent 044a03dd
No related branches found
No related tags found
1 merge request!18Add command for managing user roles in InvenioRDM
# Miscellaneous scripts
Scripts which haven't found another home yet.
## `add-user.sh`
Wrapper around some `invenio` commands for managing user roles.
This script should be executed from within the project directory, as it uses `pipenv run`.
### Requirements
* `bash`
* `pipenv`
* `invenio` (with module `Invenio-Utilities-TUW`)
* `fzf`
#!/bin/bash
role="trusted-user"
add="add"
show_all="0"
while getopts "r:haR" arg; do
case "${arg}" in
r)
role="${OPTARG}"
;;
a)
show_all="1"
;;
R)
add="remove"
;;
*)
echo "usage: $0 [options...]"
echo " -r ROLE role to add/remove"
echo " -R remove role instead"
echo " -a list all users (do not filter)"
exit
esac
done
# filter down users to only those who (don't) have the role
users=$(pipenv --quiet run invenio tuw users list -rna 2>/dev/null)
if [[ "${show_all}" -eq 0 ]]; then
if [[ "${add}" = "add" ]]; then
users=$(echo "${users}" | grep -ve "'${role}'")
else
users=$(echo "${users}" | grep -e "'${role}'")
fi
fi
# query for the user
email="$(echo "${users}" | cut -d ' ' -f 2- | fzf --prompt "${add} ${role}>" | cut -d ' ' -f 1)"
if [[ -n "${email}" ]]; then
if [[ "${add}" = "add" ]]; then
echo "adding role ${role} to ${email}"
pipenv --quiet run invenio roles add "${email}" "${role}"
else
echo "removing role ${role} from ${email}"
pipenv --quiet run invenio roles remove "${email}" "${role}"
fi
else
echo >&2 "no user selected, aborting"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment