mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
User management, migration and newsletter
This commit is contained in:
parent
11ecbf04f6
commit
42c437905e
26 changed files with 888 additions and 389 deletions
|
@ -63,7 +63,7 @@ using PlexRequests.Store.Models;
|
|||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
using Quartz;
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
@ -97,7 +97,7 @@ namespace PlexRequests.UI.Modules
|
|||
private IJobRecord JobRecorder { get; }
|
||||
private IAnalytics Analytics { get; }
|
||||
private IRecentlyAdded RecentlyAdded { get; }
|
||||
private ISettingsService<NotificationSettingsV2> NotifySettings { get; }
|
||||
private ISettingsService<NotificationSettingsV2> NotifySettings { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public AdminModule(ISettingsService<PlexRequestSettings> prService,
|
||||
|
@ -210,7 +210,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
Post["/autoupdate"] = x => AutoUpdate();
|
||||
|
||||
Post["/testslacknotification", true] = async (x,ct) => await TestSlackNotification();
|
||||
Post["/testslacknotification", true] = async (x, ct) => await TestSlackNotification();
|
||||
|
||||
Get["/slacknotification"] = _ => SlackNotifications();
|
||||
Post["/slacknotification"] = _ => SaveSlackNotifications();
|
||||
|
@ -975,7 +975,8 @@ namespace PlexRequests.UI.Modules
|
|||
SonarrCacher = s.SonarrCacher,
|
||||
StoreBackup = s.StoreBackup,
|
||||
StoreCleanup = s.StoreCleanup,
|
||||
JobRecorder = jobsDict
|
||||
JobRecorder = jobsDict,
|
||||
RecentlyAddedCron = s.RecentlyAddedCron
|
||||
};
|
||||
return View["SchedulerSettings", model];
|
||||
}
|
||||
|
@ -986,6 +987,21 @@ namespace PlexRequests.UI.Modules
|
|||
Analytics.TrackEventAsync(Category.Admin, Action.Update, "Update ScheduledJobs", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
var settings = this.Bind<ScheduledJobsSettings>();
|
||||
|
||||
if (!string.IsNullOrEmpty(settings.RecentlyAddedCron))
|
||||
{
|
||||
// Validate CRON
|
||||
var isValid = CronExpression.IsValidExpression(settings.RecentlyAddedCron);
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false,
|
||||
Message =
|
||||
$"CRON {settings.RecentlyAddedCron} is not valid. Please ensure you are using a valid CRON."
|
||||
});
|
||||
}
|
||||
}
|
||||
var result = await ScheduledJobSettings.SaveSettingsAsync(settings);
|
||||
|
||||
return Response.AsJson(result
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/local/{id}"] = x => LocalDetails((Guid)x.id);
|
||||
Get["/plex/{id}", true] = async (x, ct) => await PlexDetails(x.id);
|
||||
Get["/claims"] = x => GetClaims();
|
||||
Post["/updateuser"] = x => UpdateUser();
|
||||
}
|
||||
|
||||
private ICustomUserMapper UserMapper { get; }
|
||||
|
@ -57,15 +58,35 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
var userProps = ByteConverterHelper.ReturnObject<UserProperties>(user.UserProperties);
|
||||
|
||||
model.Add(new UserManagementUsersViewModel
|
||||
var m = new UserManagementUsersViewModel
|
||||
{
|
||||
Id = user.UserGuid,
|
||||
Claims = claimsString,
|
||||
Username = user.UserName,
|
||||
Type = UserType.LocalUser,
|
||||
EmailAddress = userProps.EmailAddress,
|
||||
ClaimsArray = claims
|
||||
});
|
||||
ClaimsArray = claims,
|
||||
ClaimsItem = new List<UserManagementUpdateModel.ClaimsModel>()
|
||||
};
|
||||
|
||||
// Add all of the current claims
|
||||
foreach (var c in claims)
|
||||
{
|
||||
m.ClaimsItem.Add(new UserManagementUpdateModel.ClaimsModel { Name = c, Selected = true });
|
||||
}
|
||||
|
||||
var allClaims = UserMapper.GetAllClaims();
|
||||
|
||||
// Get me the current claims that the user does not have
|
||||
var missingClaims = allClaims.Except(claims);
|
||||
|
||||
// Add them into the view
|
||||
foreach (var missingClaim in missingClaims)
|
||||
{
|
||||
m.ClaimsItem.Add(new UserManagementUpdateModel.ClaimsModel { Name = missingClaim, Selected = false });
|
||||
}
|
||||
|
||||
model.Add(m);
|
||||
}
|
||||
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
|
@ -121,6 +142,44 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save user" });
|
||||
}
|
||||
|
||||
private Response UpdateUser()
|
||||
{
|
||||
var body = Request.Body.AsString();
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save user, invalid JSON body" });
|
||||
}
|
||||
|
||||
var model = JsonConvert.DeserializeObject<UserManagementUpdateModel>(body);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(model.Id))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = true,
|
||||
Message = "Couldn't find the user"
|
||||
});
|
||||
}
|
||||
|
||||
var claims = new List<string>();
|
||||
|
||||
foreach (var c in model.Claims)
|
||||
{
|
||||
if (c.Selected)
|
||||
{
|
||||
claims.Add(c.Name);
|
||||
}
|
||||
}
|
||||
|
||||
var userFound = UserMapper.GetUser(new Guid(model.Id));
|
||||
|
||||
userFound.Claims = ByteConverterHelper.ReturnBytes(claims.ToArray());
|
||||
|
||||
var user = UserMapper.EditUser(userFound);
|
||||
|
||||
return Response.AsJson(user);
|
||||
}
|
||||
|
||||
private Response LocalDetails(Guid id)
|
||||
{
|
||||
var localUser = UserMapper.GetUser(id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue