2
0

NotificationOptions.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using Jellyfin.Data.Entities;
  5. using Jellyfin.Data.Enums;
  6. using Jellyfin.Extensions;
  7. namespace MediaBrowser.Model.Notifications
  8. {
  9. public class NotificationOptions
  10. {
  11. public NotificationOptions()
  12. {
  13. Options = new[]
  14. {
  15. new NotificationOption(NotificationType.TaskFailed.ToString())
  16. {
  17. Enabled = true,
  18. SendToUserMode = SendToUserType.Admins
  19. },
  20. new NotificationOption(NotificationType.ServerRestartRequired.ToString())
  21. {
  22. Enabled = true,
  23. SendToUserMode = SendToUserType.Admins
  24. },
  25. new NotificationOption(NotificationType.ApplicationUpdateAvailable.ToString())
  26. {
  27. Enabled = true,
  28. SendToUserMode = SendToUserType.Admins
  29. },
  30. new NotificationOption(NotificationType.ApplicationUpdateInstalled.ToString())
  31. {
  32. Enabled = true,
  33. SendToUserMode = SendToUserType.Admins
  34. },
  35. new NotificationOption(NotificationType.PluginUpdateInstalled.ToString())
  36. {
  37. Enabled = true,
  38. SendToUserMode = SendToUserType.Admins
  39. },
  40. new NotificationOption(NotificationType.PluginUninstalled.ToString())
  41. {
  42. Enabled = true,
  43. SendToUserMode = SendToUserType.Admins
  44. },
  45. new NotificationOption(NotificationType.InstallationFailed.ToString())
  46. {
  47. Enabled = true,
  48. SendToUserMode = SendToUserType.Admins
  49. },
  50. new NotificationOption(NotificationType.PluginInstalled.ToString())
  51. {
  52. Enabled = true,
  53. SendToUserMode = SendToUserType.Admins
  54. },
  55. new NotificationOption(NotificationType.PluginError.ToString())
  56. {
  57. Enabled = true,
  58. SendToUserMode = SendToUserType.Admins
  59. },
  60. new NotificationOption(NotificationType.UserLockedOut.ToString())
  61. {
  62. Enabled = true,
  63. SendToUserMode = SendToUserType.Admins
  64. }
  65. };
  66. }
  67. public NotificationOption[] Options { get; set; }
  68. public NotificationOption GetOptions(string type)
  69. {
  70. foreach (NotificationOption i in Options)
  71. {
  72. if (string.Equals(type, i.Type, StringComparison.OrdinalIgnoreCase))
  73. {
  74. return i;
  75. }
  76. }
  77. return null;
  78. }
  79. public bool IsEnabled(string type)
  80. {
  81. NotificationOption opt = GetOptions(type);
  82. return opt != null && opt.Enabled;
  83. }
  84. public bool IsServiceEnabled(string service, string notificationType)
  85. {
  86. NotificationOption opt = GetOptions(notificationType);
  87. return opt == null
  88. || !opt.DisabledServices.Contains(service, StringComparison.OrdinalIgnoreCase);
  89. }
  90. public bool IsEnabledToMonitorUser(string type, Guid userId)
  91. {
  92. NotificationOption opt = GetOptions(type);
  93. return opt != null
  94. && opt.Enabled
  95. && !opt.DisabledMonitorUsers.Contains(userId.ToString("N"), StringComparison.OrdinalIgnoreCase);
  96. }
  97. public bool IsEnabledToSendToUser(string type, string userId, User user)
  98. {
  99. NotificationOption opt = GetOptions(type);
  100. if (opt != null && opt.Enabled)
  101. {
  102. if (opt.SendToUserMode == SendToUserType.All)
  103. {
  104. return true;
  105. }
  106. if (opt.SendToUserMode == SendToUserType.Admins && user.HasPermission(PermissionKind.IsAdministrator))
  107. {
  108. return true;
  109. }
  110. return opt.SendToUsers.Contains(userId, StringComparison.OrdinalIgnoreCase);
  111. }
  112. return false;
  113. }
  114. }
  115. }