125 lines
3.1 KiB
Plaintext
125 lines
3.1 KiB
Plaintext
# ---
|
|
# Delete User
|
|
# ---
|
|
|
|
# see: https://docs.mattermost.com/manage/command-line-tools.html#mattermost-user-delete
|
|
|
|
|
|
# There are two levels in user deactivation/deletion:
|
|
#
|
|
# The first one is user deactivation which is what you performed. After deactivating a user,
|
|
# that user becomes archived and you can still search him/her and read their messages in
|
|
# channels.
|
|
#
|
|
# The second is user deletion. You can do this via a CLI command. Note that when you permanently
|
|
# delete a user, all their posts and past activities will get permanently deleted.
|
|
|
|
|
|
# Permanently delete a user and all related information, including posts from the database.
|
|
#
|
|
# Requirement:
|
|
# Set "EnableAPIUserDeletion" to "true" in file /opt/mattermost/config/config.json and restart mattermost
|
|
#
|
|
# /opt/mattermost/bin/mmctl user delete <users>
|
|
#
|
|
# Note:
|
|
# Does not delete content from the file storage. You can manually delete all file uploads
|
|
# for a given user as uploads contain the CreatorId field. User profile pictures are stored
|
|
# in data/users/<userid>/profile.png.
|
|
|
|
|
|
# Set "EnableAPIUserDeletion" to "true" in file /opt/mattermost/config/config.json
|
|
#
|
|
perl -i -n -p -e "s/^(\s*\"EnableAPIUserDeletion\":).*$/\1 true,/" /opt/mattermost/config/config.json
|
|
|
|
# Restart Mattermost
|
|
#
|
|
systemctl restart mattermost
|
|
|
|
usr_to_delete="
|
|
a.marinou-strohm
|
|
angelika
|
|
bennie
|
|
clarissa
|
|
david
|
|
fabian
|
|
georg
|
|
hanna
|
|
hannahnieswand
|
|
leonie
|
|
leoniestetter
|
|
lilian
|
|
lisa
|
|
lsachenbacher
|
|
ludwig
|
|
klaudia
|
|
mads
|
|
owain
|
|
stina
|
|
tim_vallee
|
|
viktar
|
|
"
|
|
|
|
clear
|
|
|
|
# Log in to an instance and store credentials.
|
|
#
|
|
# instance url: https://mm-irights.oopen.de
|
|
# server name: local-server
|
|
# username: admin-irights
|
|
# password: M6aHdhGh_I%9
|
|
|
|
# save password to a file
|
|
#
|
|
cat << EOF > .mm-admin-irights.auth
|
|
M6aHdhGh_I%9
|
|
EOF
|
|
|
|
mmctl auth login https://mm-irights.oopen.de --name local-server --username admin-irights --password-file .mm-admin-irights.auth
|
|
|
|
echo ""
|
|
for _user in $usr_to_delete ; do
|
|
echo ""
|
|
echo $_user
|
|
|
|
if $(mmctl user list 2> /dev/null | grep -q $_user) ; then
|
|
echo -n " Delete user '$_user' [yes/no]: "
|
|
read OK
|
|
OK="${OK,,}"
|
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
echo -n " Wrong answer - repeat [yes/no]: "
|
|
read OK
|
|
OK="${OK,,}"
|
|
done
|
|
|
|
if [[ $OK = "yes" ]] ; then
|
|
|
|
# Delete user
|
|
#
|
|
/opt/mattermost/bin/mmctl user delete $_user --confirm > /dev/null 2>&1
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo -e " [ \033[31m\033[1mError\033[m ] Deleting user '$_user' failed!"
|
|
else
|
|
echo -e " [ \033[32m\033[1mInfo\033[m ] User '$_user' was deleted."
|
|
fi
|
|
else
|
|
echo -e " [ \033[33m\033[1mWarning\033[m ] User '$_user' was omitted"
|
|
fi
|
|
else
|
|
echo -e " [ \033[31m\033[1mError\033[m ] User '$_user' not found!"
|
|
fi
|
|
done
|
|
|
|
rm .mm-admin-irights.auth
|
|
|
|
|
|
# Set "EnableAPIUserDeletion" to "false" in file /opt/mattermost/config/config.json
|
|
#
|
|
perl -i -n -p -e "s/^(\s*\"EnableAPIUserDeletion\":).*$/\1 false,/" /opt/mattermost/config/config.json
|
|
|
|
# Restart Mattermost
|
|
#
|
|
systemctl restart mattermost
|
|
|