mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 14:10:50 -07:00
commit
3782cf7029
9 changed files with 30 additions and 54 deletions
|
@ -58,7 +58,6 @@ namespace PlexRequests.Core.SettingModels
|
|||
public int MovieWeeklyRequestLimit { get; set; }
|
||||
public int TvWeeklyRequestLimit { get; set; }
|
||||
public int AlbumWeeklyRequestLimit { get; set; }
|
||||
public string NoApprovalUsers { get; set; }
|
||||
public bool CollectAnalyticData { get; set; }
|
||||
public bool IgnoreNotifyForAutoApprovedRequests { get; set; }
|
||||
public bool Wizard { get; set; }
|
||||
|
@ -75,26 +74,5 @@ namespace PlexRequests.Core.SettingModels
|
|||
public string ThemeName { get; set; }
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<string> ApprovalWhiteList
|
||||
{
|
||||
get
|
||||
{
|
||||
var users = new List<string>();
|
||||
if (string.IsNullOrEmpty(NoApprovalUsers))
|
||||
{
|
||||
return users;
|
||||
}
|
||||
|
||||
var splitUsers = NoApprovalUsers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var user in splitUsers)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(user))
|
||||
users.Add(user.Trim());
|
||||
}
|
||||
return users;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
Track(HitType.@event, username, cat, act, label, clientId, value);
|
||||
}
|
||||
|
||||
public async Task TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
|
||||
public async void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
|
||||
{
|
||||
var cat = category.ToString();
|
||||
var act = action.ToString();
|
||||
|
@ -146,7 +146,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
request.Method = RequestMethod;
|
||||
// set the Content-Length header to the correct value
|
||||
request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
|
||||
|
||||
#if !DEBUG
|
||||
// write the request body to the request
|
||||
using (var writer = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
|
@ -165,6 +165,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
{
|
||||
Log.Error(ex, "Analytics tracking failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
private async Task SendRequestAsync(string postDataString)
|
||||
{
|
||||
|
@ -173,6 +174,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
// set the Content-Length header to the correct value
|
||||
request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
|
||||
|
||||
#if !DEBUG
|
||||
// write the request body to the request
|
||||
using (var writer = new StreamWriter(await request.GetRequestStreamAsync()))
|
||||
{
|
||||
|
@ -191,6 +193,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
{
|
||||
Log.Error(ex, "Analytics tracking failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private Dictionary<string, string> BuildRequestData(HitType type, string username, string category, string action, string clientId, string label, int? value, string exceptionDescription, int? fatal)
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
Issues,
|
||||
UserLogin,
|
||||
Services,
|
||||
Navbar
|
||||
Navbar,
|
||||
UserManagement
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
/// <param name="clientId">The client identifier.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns></returns>
|
||||
Task TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null);
|
||||
void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null);
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the page view.
|
||||
|
|
|
@ -302,11 +302,6 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
public bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings, List<string> username)
|
||||
{
|
||||
if (prSettings.ApprovalWhiteList.Intersect(username).Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var user in username)
|
||||
{
|
||||
var admin = Security.HasPermissions(user, Permissions.Administrator);
|
||||
|
|
|
@ -37,8 +37,8 @@ using PlexRequests.Core;
|
|||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Core.StatusChecker;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
|
@ -46,10 +46,11 @@ namespace PlexRequests.UI.Modules.Admin
|
|||
{
|
||||
public class SystemStatusModule : BaseModule
|
||||
{
|
||||
public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService, ICacheProvider cache, ISettingsService<SystemSettings> ss, ISecurityExtensions security) : base("admin", settingsService, security)
|
||||
public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService, ICacheProvider cache, ISettingsService<SystemSettings> ss, ISecurityExtensions security, IAnalytics a) : base("admin", settingsService, security)
|
||||
{
|
||||
Cache = cache;
|
||||
SystemSettings = ss;
|
||||
Analytics = a;
|
||||
|
||||
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
||||
|
||||
|
@ -61,6 +62,7 @@ namespace PlexRequests.UI.Modules.Admin
|
|||
|
||||
private ICacheProvider Cache { get; }
|
||||
private ISettingsService<SystemSettings> SystemSettings { get; }
|
||||
private IAnalytics Analytics { get; }
|
||||
|
||||
private async Task<Negotiator> Status()
|
||||
{
|
||||
|
@ -99,8 +101,10 @@ namespace PlexRequests.UI.Modules.Admin
|
|||
|
||||
private async Task<Response> Save()
|
||||
{
|
||||
|
||||
var settings = this.Bind<SystemSettings>();
|
||||
|
||||
Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, $"Updated Branch {EnumHelper<Branches>.GetDisplayValue(settings.Branch)}", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
await SystemSettings.SaveSettingsAsync(settings);
|
||||
|
||||
// Clear the cache
|
||||
|
@ -111,6 +115,8 @@ namespace PlexRequests.UI.Modules.Admin
|
|||
|
||||
private Response AutoUpdate()
|
||||
{
|
||||
Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, "AutoUpdate", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
|
||||
var url = Request.Form["url"];
|
||||
|
||||
var startInfo = Type.GetType("Mono.Runtime") != null
|
||||
|
|
|
@ -1234,7 +1234,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (IsAdmin)
|
||||
return true;
|
||||
|
||||
if (s.ApprovalWhiteList.Contains(Username))
|
||||
if (ShouldAutoApprove(type,s,Username))
|
||||
return true;
|
||||
|
||||
var requestLimit = GetRequestLimitForType(type, s);
|
||||
|
@ -1376,8 +1376,8 @@ namespace PlexRequests.UI.Modules
|
|||
public bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings, string username)
|
||||
{
|
||||
var admin = Security.HasPermissions(Context.CurrentUser, Permissions.Administrator);
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (admin || prSettings.ApprovalWhiteList.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase))) return true;
|
||||
// if the user is an admin, they go ahead and allow auto-approval
|
||||
if (admin) return true;
|
||||
|
||||
// check by request type if the category requires approval or not
|
||||
switch (requestType)
|
||||
|
|
|
@ -13,12 +13,13 @@ using PlexRequests.Core;
|
|||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
@ -26,7 +27,7 @@ namespace PlexRequests.UI.Modules
|
|||
public class UserManagementModule : BaseModule
|
||||
{
|
||||
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex, IRepository<UserLogins> userLogins, IPlexUserRepository plexRepo
|
||||
, ISecurityExtensions security, IRequestService req) : base("usermanagement", pr, security)
|
||||
, ISecurityExtensions security, IRequestService req, IAnalytics ana) : base("usermanagement", pr, security)
|
||||
{
|
||||
#if !DEBUG
|
||||
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
||||
|
@ -38,11 +39,12 @@ namespace PlexRequests.UI.Modules
|
|||
PlexUsersRepository = plexRepo;
|
||||
PlexRequestSettings = pr;
|
||||
RequestService = req;
|
||||
Analytics = ana;
|
||||
|
||||
Get["/"] = x => Load();
|
||||
|
||||
Get["/users", true] = async (x, ct) => await LoadUsers();
|
||||
Post["/createuser"] = x => CreateUser();
|
||||
Post["/createuser", true] = async (x,ct) => await CreateUser();
|
||||
Get["/local/{id}"] = x => LocalDetails((Guid)x.id);
|
||||
Get["/plex/{id}", true] = async (x, ct) => await PlexDetails(x.id);
|
||||
Get["/permissions"] = x => GetEnum<Permissions>();
|
||||
|
@ -58,6 +60,7 @@ namespace PlexRequests.UI.Modules
|
|||
private IPlexUserRepository PlexUsersRepository { get; }
|
||||
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private IAnalytics Analytics { get; }
|
||||
|
||||
private Negotiator Load()
|
||||
{
|
||||
|
@ -103,8 +106,9 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(model);
|
||||
}
|
||||
|
||||
private Response CreateUser()
|
||||
private async Task<Response> CreateUser()
|
||||
{
|
||||
Analytics.TrackEventAsync(Category.UserManagement, Action.Create, "Created User", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
var body = Request.Body.AsString();
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
|
@ -122,7 +126,7 @@ namespace PlexRequests.UI.Modules
|
|||
});
|
||||
}
|
||||
|
||||
var users = UserMapper.GetUsers();
|
||||
var users = await UserMapper.GetUsersAsync();
|
||||
if (users.Any(x => x.UserName.Equals(model.Username, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
|
@ -158,6 +162,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private async Task<Response> UpdateUser()
|
||||
{
|
||||
Analytics.TrackEventAsync(Category.UserManagement, Action.Update, "Updated User", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
var body = Request.Body.AsString();
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
|
@ -276,6 +281,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response DeleteUser()
|
||||
{
|
||||
Analytics.TrackEventAsync(Category.UserManagement, Action.Delete, "Deleted User", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
var body = Request.Body.AsString();
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
|
|
|
@ -199,19 +199,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<p class="form-group">A comma separated list of users whose requests do not require approval (These users also do not have a request limit).</p>
|
||||
<div class="form-group">
|
||||
<label for="NoApprovalUsers" class="control-label">Approval White listed Users</label>
|
||||
<div>
|
||||
<input type="text" class="form-control-custom form-control " id="NoApprovalUsers" name="NoApprovalUsers" placeholder="e.g. John, Bobby" value="@Model.NoApprovalUsers">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p class="form-group">If the request limits are set to 0 then no request limit is applied.</p>
|
||||
<div class="form-group">
|
||||
<label for="MovieWeeklyRequestLimit" class="control-label">Movie Weekly Request Limit</label>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue