2
0

NotificationOptions.cs 4.4 KB

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