NotificationOptions.cs 4.4 KB

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