2014-07-01 04:06:28 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-04-27 03:42:05 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Configuration
|
|
|
|
|
{
|
|
|
|
|
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
|
2014-04-27 03:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NotificationOption GetOptions(string type)
|
|
|
|
|
{
|
2014-05-09 04:38:12 +00:00
|
|
|
|
foreach (NotificationOption i in Options)
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(type, i.Type)) return i;
|
2014-05-09 04:38:12 +00:00
|
|
|
|
}
|
|
|
|
|
return null;
|
2014-04-27 03:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled(string type)
|
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
NotificationOption opt = GetOptions(type);
|
2014-04-27 03:42:05 +00:00
|
|
|
|
|
|
|
|
|
return opt != null && opt.Enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsServiceEnabled(string service, string notificationType)
|
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 17:54:43 +00:00
|
|
|
|
public bool IsEnabledToSendToUser(string type, string userId, UserConfiguration userConfig)
|
2014-04-27 03:42:05 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opt.SendToUserMode == SendToUserType.Admins && userConfig.IsAdministrator)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|