v-delete-user-notification 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # info: delete user notification
  3. # options: USER NOTIFICATION
  4. # labels: panel
  5. #
  6. # example: v-delete-user-notification admin 1
  7. #
  8. # The function deletes user notification.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. nid=$2
  15. # Includes
  16. source $HESTIA/func/main.sh
  17. source $HESTIA/conf/hestia.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER NOTIFICATION'
  22. is_format_valid 'user' 'nid'
  23. is_object_valid 'user' 'USER' "$user"
  24. # Perform verification if read-only mode is enabled
  25. check_hestia_demo_mode
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. # Deleting notification
  30. sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
  31. # Checking last notification
  32. if [ -e "$USER_DATA/notifications.conf" ]; then
  33. if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
  34. notice='no'
  35. fi
  36. if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
  37. notice='no'
  38. fi
  39. else
  40. notice='no'
  41. fi
  42. #----------------------------------------------------------#
  43. # Hestia #
  44. #----------------------------------------------------------#
  45. # Updating notification counter
  46. if [ "$notice" = 'no' ]; then
  47. if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
  48. sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
  49. else
  50. update_user_value "$user" '$NOTIFICATIONS' "no"
  51. fi
  52. fi
  53. # Logging
  54. log_event "$OK" "$ARGUMENTS"
  55. exit