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