update notify_admin_gui to cache the admin user (#1502)

Co-authored-by: Daniel Hansson <github@hanssonit.se>
This commit is contained in:
szaimen 2020-10-01 17:46:37 +02:00 коммит произвёл GitHub
Родитель 3cecc203f1
Коммит f732671d5b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 22 добавлений и 6 удалений

25
lib.sh
Просмотреть файл

@ -1395,6 +1395,9 @@ esac
#
# occ_command_no_check notification:generate -l "$2" "$admin" "$1"
notify_admin_gui() {
local NC_USERS
local user
local admin
if ! is_app_enabled notifications
then
print_text_in_color "$IRed" "The notifications app isn't enabled - unable to send notifications"
@ -1402,13 +1405,23 @@ then
fi
print_text_in_color "$ICyan" "Posting notification to users that are admins, this might take a while..."
occ_command_no_check user:list | sed 's|^ - ||g' | sed 's|:.*||' | while read -r admin
if [ -z "${NC_ADMIN_USER[*]}" ]
then
NC_USERS=$(occ_command_no_check user:list | sed 's|^ - ||g' | sed 's|:.*||')
mapfile -t NC_USERS <<< "$NC_USERS"
for user in "${NC_USERS[@]}"
do
if occ_command_no_check user:info "$user" | cut -d "-" -f2 | grep -x -q " admin"
then
NC_ADMIN_USER+=("$user")
fi
done
fi
for admin in "${NC_ADMIN_USER[@]}"
do
if occ_command_no_check user:info "$admin" | cut -d "-" -f2 | grep -x -q " admin"
then
print_text_in_color "$IGreen" "Posting '$1' to: $admin"
occ_command_no_check notification:generate -l "$2" "$admin" "$1"
fi
print_text_in_color "$IGreen" "Posting '$1' to: $admin"
occ_command_no_check notification:generate -l "$2" "$admin" "$1"
done
}

Просмотреть файл

@ -398,6 +398,9 @@ then
fi
clear
# We need to unset the cached admin-user since we have changed its name
unset NC_ADMIN_USER
msg_box "Well done, you have now finished most of the setup.
There are still some stuff left to do, but they are automated so sit back and relax! :)"