jellyfin-server/MediaBrowser.Model/Notifications/NotificationOptions.cs

133 lines
4.4 KiB
C#
Raw Normal View History

2014-07-02 18:34:08 +00:00
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Extensions;
2015-04-01 04:23:34 +00:00
using MediaBrowser.Model.Users;
2014-04-27 03:42:05 +00:00
2014-07-02 18:34:08 +00:00
namespace MediaBrowser.Model.Notifications
2014-04-27 03:42:05 +00:00
{
public class NotificationOptions
{
public NotificationOption[] Options { get; set; }
public NotificationOptions()
{
Options = new[]
{
new NotificationOption
{
Type = NotificationType.TaskFailed.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.ServerRestartRequired.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.ApplicationUpdateAvailable.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.ApplicationUpdateInstalled.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.PluginUpdateInstalled.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.PluginUninstalled.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.InstallationFailed.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
},
new NotificationOption
{
Type = NotificationType.PluginInstalled.ToString(),
2014-04-27 17:54:43 +00:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-29 03:56:20 +00:00
},
new NotificationOption
{
Type = NotificationType.PluginError.ToString(),
Enabled = true,
SendToUserMode = SendToUserType.Admins
2015-03-03 18:48:47 +00:00
},
new NotificationOption
{
Type = NotificationType.UserLockedOut.ToString(),
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 03:42:05 +00:00
}
};
}
public NotificationOption GetOptions(string type)
{
foreach (NotificationOption i in Options)
{
if (StringHelper.EqualsIgnoreCase(type, i.Type)) return i;
}
return null;
2014-04-27 03:42:05 +00:00
}
public bool IsEnabled(string type)
{
NotificationOption opt = GetOptions(type);
2014-04-27 03:42:05 +00:00
return opt != null && opt.Enabled;
}
public bool IsServiceEnabled(string service, string notificationType)
{
NotificationOption opt = GetOptions(notificationType);
2014-04-27 03:42:05 +00:00
return opt == null ||
2014-07-01 04:06:28 +00:00
!ListHelper.ContainsIgnoreCase(opt.DisabledServices, service);
2014-04-27 03:42:05 +00:00
}
public bool IsEnabledToMonitorUser(string type, string userId)
{
NotificationOption opt = GetOptions(type);
2014-04-27 03:42:05 +00:00
return opt != null && opt.Enabled &&
2014-07-01 04:06:28 +00:00
!ListHelper.ContainsIgnoreCase(opt.DisabledMonitorUsers, userId);
2014-04-27 03:42:05 +00:00
}
2015-04-01 04:23:34 +00:00
public bool IsEnabledToSendToUser(string type, string userId, UserPolicy userPolicy)
2014-04-27 03:42:05 +00:00
{
NotificationOption opt = GetOptions(type);
2014-04-27 03:42:05 +00:00
2014-04-27 17:54:43 +00:00
if (opt != null && opt.Enabled)
{
if (opt.SendToUserMode == SendToUserType.All)
{
return true;
}
2015-04-01 04:23:34 +00:00
if (opt.SendToUserMode == SendToUserType.Admins && userPolicy.IsAdministrator)
2014-04-27 17:54:43 +00:00
{
return true;
}
2014-07-01 04:06:28 +00:00
return ListHelper.ContainsIgnoreCase(opt.SendToUsers, userId);
2014-04-27 17:54:43 +00:00
}
return false;
2014-04-27 03:42:05 +00:00
}
}
}