NotificationOptions.cs 4.3 KB

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