NotificationOptions.cs 4.4 KB

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