2
0

NotificationOptions.cs 4.4 KB

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