Procházet zdrojové kódy

Allow priority to be set for notifications (#3873)

* Allow priority to be set for notifications

Currently the order is first to last

Priority
Last to first

* See remarks
Jaap Marcus před 2 roky
rodič
revize
da4d1f427c

+ 5 - 3
bin/v-add-user-notification

@@ -13,6 +13,7 @@ user=$1
 topic=$(echo $2 | sed "s/'/%quote%/g")
 notice=$(echo $3 | sed "s/'/%quote%/g")
 type=$4
+priority=$5
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -26,9 +27,10 @@ source_conf "$HESTIA/conf/hestia.conf"
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-check_args '2' "$#" 'USER TOPIC NOTICE [TYPE]'
-is_format_valid 'user' 'topic' 'notice'
+check_args '2' "$#" 'USER TOPIC NOTICE TYPE [PRIORITY]'
+is_format_valid 'user' 'topic' 'notice' 'priority'
 is_object_valid 'user' 'USER' "$user"
+is_common_format_valid "$type"
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
@@ -56,7 +58,7 @@ time=$(echo "$time_n_date" | cut -f 1 -d \ )
 date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating string
-str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
+str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type' PRIORITY='$priority'"
 str="$str ACK='no' TIME='$time' DATE='$date'"
 
 # Adding to config

+ 4 - 1
bin/v-list-user-notifications

@@ -30,6 +30,9 @@ json_list() {
 	echo "{"
 	while read str; do
 		parse_object_kv_list "$str"
+		if [ "$PRIORITY" = '' ]; then
+			PRIORITY='0'
+		fi
 		TOPIC=$(echo "$TOPIC" | sed -e "s/%quote%/'/g")
 		NOTICE=$(echo "$NOTICE" | sed -e "s/%quote%/'/g")
 		echo -n '    "'$NID'": {
@@ -37,7 +40,7 @@ json_list() {
         "NOTICE": "'${NOTICE//\"/\'}'",
         "TYPE": "'$TYPE'",
         "ACK": "'$ACK'",
-        "TPL": "'$TPL'",
+        "PRIORITY": "'$PRIORITY'",
         "TIME": "'$TIME'",
         "DATE": "'$DATE'"
     }'

+ 1 - 0
func/main.sh

@@ -1210,6 +1210,7 @@ is_format_valid() {
 				object) is_object_name_format_valid "$arg" 'object' ;;
 				package) is_object_format_valid "$arg" "$arg_name" ;;
 				password) is_password_format_valid "$arg" ;;
+				priority) is_int_format_valid $arg ;;
 				port) is_int_format_valid "$arg" 'port' ;;
 				port_ext) is_fw_port_format_valid "$arg" ;;
 				protocol) is_fw_protocol_format_valid "$arg" ;;

+ 6 - 0
web/list/notifications/index.php

@@ -6,7 +6,13 @@ if ($_REQUEST["ajax"] == 1 && $_REQUEST["token"] == $_SESSION["token"]) {
 	// Data
 	exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
 	$data = json_decode(implode("", $output), true);
+
+	function sort_priorty_id($element1, $element2) {
+		return $element2["PRIORITY"] <=> $element1["PRIORITY"];
+	}
 	$data = array_reverse($data, true);
+	usort($data, sort_priorty_id(...));
+
 	foreach ($data as $key => $note) {
 		$note["ID"] = $key;
 		$data[$key] = $note;