Skip to content

Commit da4d1f4

Browse files
authored
Allow priority to be set for notifications (hestiacp#3873)
* Allow priority to be set for notifications Currently the order is first to last Priority Last to first * See remarks
1 parent a1dc052 commit da4d1f4

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

bin/v-add-user-notification

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ user=$1
1313
topic=$(echo $2 | sed "s/'/%quote%/g")
1414
notice=$(echo $3 | sed "s/'/%quote%/g")
1515
type=$4
16+
priority=$5
1617

1718
# Includes
1819
# shellcheck source=/etc/hestiacp/hestia.conf
@@ -26,9 +27,10 @@ source_conf "$HESTIA/conf/hestia.conf"
2627
# Verifications #
2728
#----------------------------------------------------------#
2829

29-
check_args '2' "$#" 'USER TOPIC NOTICE [TYPE]'
30-
is_format_valid 'user' 'topic' 'notice'
30+
check_args '2' "$#" 'USER TOPIC NOTICE TYPE [PRIORITY]'
31+
is_format_valid 'user' 'topic' 'notice' 'priority'
3132
is_object_valid 'user' 'USER' "$user"
33+
is_common_format_valid "$type"
3234

3335
# Perform verification if read-only mode is enabled
3436
check_hestia_demo_mode
@@ -56,7 +58,7 @@ time=$(echo "$time_n_date" | cut -f 1 -d \ )
5658
date=$(echo "$time_n_date" | cut -f 2 -d \ )
5759

5860
# Concatenating string
59-
str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
61+
str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type' PRIORITY='$priority'"
6062
str="$str ACK='no' TIME='$time' DATE='$date'"
6163

6264
# Adding to config

bin/v-list-user-notifications

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ json_list() {
3030
echo "{"
3131
while read str; do
3232
parse_object_kv_list "$str"
33+
if [ "$PRIORITY" = '' ]; then
34+
PRIORITY='0'
35+
fi
3336
TOPIC=$(echo "$TOPIC" | sed -e "s/%quote%/'/g")
3437
NOTICE=$(echo "$NOTICE" | sed -e "s/%quote%/'/g")
3538
echo -n ' "'$NID'": {
3639
"TOPIC": "'$TOPIC'",
3740
"NOTICE": "'${NOTICE//\"/\'}'",
3841
"TYPE": "'$TYPE'",
3942
"ACK": "'$ACK'",
40-
"TPL": "'$TPL'",
43+
"PRIORITY": "'$PRIORITY'",
4144
"TIME": "'$TIME'",
4245
"DATE": "'$DATE'"
4346
}'

func/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ is_format_valid() {
12101210
object) is_object_name_format_valid "$arg" 'object' ;;
12111211
package) is_object_format_valid "$arg" "$arg_name" ;;
12121212
password) is_password_format_valid "$arg" ;;
1213+
priority) is_int_format_valid $arg ;;
12131214
port) is_int_format_valid "$arg" 'port' ;;
12141215
port_ext) is_fw_port_format_valid "$arg" ;;
12151216
protocol) is_fw_protocol_format_valid "$arg" ;;

web/list/notifications/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
// Data
77
exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
88
$data = json_decode(implode("", $output), true);
9+
10+
function sort_priorty_id($element1, $element2) {
11+
return $element2["PRIORITY"] <=> $element1["PRIORITY"];
12+
}
913
$data = array_reverse($data, true);
14+
usort($data, sort_priorty_id(...));
15+
1016
foreach ($data as $key => $note) {
1117
$note["ID"] = $key;
1218
$data[$key] = $note;

0 commit comments

Comments
 (0)