mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
commit
b7e3be0a46
14 changed files with 183 additions and 69 deletions
|
@ -238,9 +238,13 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
|
||||
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}
|
||||
// Update old invalid posters
|
||||
var allRequests = RequestService.GetAll().ToList();
|
||||
|
||||
foreach (var req in allRequests)
|
||||
var allRequests = RequestService.GetAll();
|
||||
if (allRequests == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var requestedModels = allRequests as RequestedModel[] ?? allRequests.ToArray();
|
||||
foreach (var req in requestedModels)
|
||||
{
|
||||
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))
|
||||
{
|
||||
|
@ -248,7 +252,7 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
req.PosterPath = newImg;
|
||||
}
|
||||
}
|
||||
RequestService.BatchUpdate(allRequests);
|
||||
RequestService.BatchUpdate(requestedModels);
|
||||
}
|
||||
|
||||
private void UpdateAdmin()
|
||||
|
|
|
@ -146,8 +146,17 @@ namespace PlexRequests.Core.StatusChecker
|
|||
eapAtrifactRequest.AddHeader("Authorization", $"Bearer {api}");
|
||||
eapAtrifactRequest.AddHeader("Content-Type", "application/json");
|
||||
|
||||
var artifactResult = request.ExecuteJson<List<AppveyorArtifactResult>>(eapAtrifactRequest, new Uri(AppveyorApiUrl)).FirstOrDefault();
|
||||
var artifactResults = request.ExecuteJson<List<AppveyorArtifactResult>>(eapAtrifactRequest, new Uri(AppveyorApiUrl));
|
||||
|
||||
var artifactResult = artifactResults.FirstOrDefault();
|
||||
|
||||
if (artifactResult == null)
|
||||
{
|
||||
return new StatusModel
|
||||
{
|
||||
UpdateAvailable = false
|
||||
};
|
||||
}
|
||||
var downloadLink = $"{AppveyorApiUrl}/buildjobs/{jobId}/artifacts/{artifactResult.fileName}";
|
||||
|
||||
var branchDisplay = EnumHelper<Branches>.GetDisplayValue(branch);
|
||||
|
|
|
@ -167,6 +167,8 @@ namespace PlexRequests.Helpers.Analytics
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
private async Task SendRequestAsync(string postDataString)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(AnalyticsUri);
|
||||
|
@ -195,6 +197,7 @@ namespace PlexRequests.Helpers.Analytics
|
|||
}
|
||||
#endif
|
||||
}
|
||||
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
|
||||
private Dictionary<string, string> BuildRequestData(HitType type, string username, string category, string action, string clientId, string label, int? value, string exceptionDescription, int? fatal)
|
||||
{
|
||||
|
|
|
@ -70,6 +70,9 @@ namespace PlexRequests.Helpers.Permissions
|
|||
UsersCanViewOnlyOwnRequests = 1024,
|
||||
|
||||
[Display(Name = "Users can only view their own issues")]
|
||||
UsersCanViewOnlyOwnIssues = 2048
|
||||
UsersCanViewOnlyOwnIssues = 2048,
|
||||
|
||||
[Display(Name = "Bypass the request limit")]
|
||||
BypassRequestLimit = 4096
|
||||
}
|
||||
}
|
|
@ -105,6 +105,7 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
public void Test()
|
||||
{
|
||||
Log.Debug("Starting Test Newsletter");
|
||||
var settings = NewsletterSettings.GetSettings();
|
||||
Start(settings, true);
|
||||
}
|
||||
|
@ -113,19 +114,32 @@ namespace PlexRequests.Services.Jobs
|
|||
{
|
||||
var sb = new StringBuilder();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
Log.Debug("Got Plex Settings");
|
||||
|
||||
var libs = Api.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
Log.Debug("Getting Plex Library Sections");
|
||||
|
||||
var tvSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
|
||||
Log.Debug("Filtered sections for TV");
|
||||
var movieSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Movie.ToString(), StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
Log.Debug("Filtered sections for Movies");
|
||||
|
||||
|
||||
var recentlyAddedTv = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, tvSection.Key);
|
||||
Log.Debug("Got RecentlyAdded TV Shows");
|
||||
var recentlyAddedMovies = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, movieSection.Key);
|
||||
Log.Debug("Got RecentlyAdded Movies");
|
||||
|
||||
Log.Debug("Started Generating Movie HTML");
|
||||
GenerateMovieHtml(recentlyAddedMovies, plexSettings, sb);
|
||||
Log.Debug("Finished Generating Movie HTML");
|
||||
Log.Debug("Started Generating TV HTML");
|
||||
GenerateTvHtml(recentlyAddedTv, plexSettings, sb);
|
||||
Log.Debug("Finished Generating TV HTML");
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
Log.Debug("Loaded the template");
|
||||
|
||||
Send(newletterSettings, html, plexSettings, testEmail);
|
||||
}
|
||||
|
@ -188,11 +202,17 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
private void GenerateTvHtml(RecentlyAddedModel tv, PlexSettings plexSettings, StringBuilder sb)
|
||||
{
|
||||
var orderedTv = tv?._children;
|
||||
if (orderedTv == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
orderedTv = orderedTv.OrderByDescending(x => x?.addedAt.UnixTimeStampToDateTime()).ToList();
|
||||
// TV
|
||||
sb.Append("<h1>New Episodes:</h1><br/><br/>");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var t in tv._children.OrderByDescending(x => x.addedAt.UnixTimeStampToDateTime()))
|
||||
foreach (var t in orderedTv)
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
|
@ -247,6 +267,7 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false)
|
||||
{
|
||||
Log.Debug("Entering Send");
|
||||
var settings = EmailSettings.GetSettings();
|
||||
|
||||
if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
|
||||
|
@ -255,11 +276,13 @@ namespace PlexRequests.Services.Jobs
|
|||
}
|
||||
|
||||
var body = new BodyBuilder { HtmlBody = html, TextBody = "This email is only available on devices that support HTML." };
|
||||
|
||||
var message = new MimeMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = "New Content on Plex!",
|
||||
};
|
||||
Log.Debug("Created Plain/HTML MIME body");
|
||||
|
||||
if (!testEmail)
|
||||
{
|
||||
|
@ -284,6 +307,7 @@ namespace PlexRequests.Services.Jobs
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin
|
||||
|
||||
message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
|
||||
|
@ -302,7 +326,9 @@ namespace PlexRequests.Services.Jobs
|
|||
client.Authenticate(settings.EmailUsername, settings.EmailPassword);
|
||||
}
|
||||
Log.Info("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated);
|
||||
Log.Debug("Sending");
|
||||
client.Send(message);
|
||||
Log.Debug("Sent");
|
||||
client.Disconnect(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,11 +41,9 @@ namespace PlexRequests.Store.Repository
|
|||
public PlexUserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache)
|
||||
{
|
||||
DbConfig = config;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration DbConfig { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private IDbConnection Db => DbConfig.DbConnection();
|
||||
|
||||
public PlexUsers GetUser(string userGuid)
|
||||
|
@ -69,7 +67,9 @@ namespace PlexRequests.Store.Repository
|
|||
return await Db.QueryFirstOrDefaultAsync<PlexUsers>(sql, new {UserGuid = userguid});
|
||||
}
|
||||
|
||||
#region abstract implimentation
|
||||
#region abstract implementation
|
||||
|
||||
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
|
||||
[Obsolete]
|
||||
public override PlexUsers Get(string id)
|
||||
{
|
||||
|
@ -94,6 +94,7 @@ namespace PlexRequests.Store.Repository
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,9 @@ namespace PlexRequests.Store.Repository
|
|||
public UserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache)
|
||||
{
|
||||
DbConfig = config;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration DbConfig { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private IDbConnection Db => DbConfig.DbConnection();
|
||||
|
||||
public UsersModel GetUser(string userGuid)
|
||||
|
@ -68,7 +66,9 @@ namespace PlexRequests.Store.Repository
|
|||
return await Db.QueryFirstOrDefaultAsync<UsersModel>(sql, new {UserGuid = userguid});
|
||||
}
|
||||
|
||||
#region abstract implimentation
|
||||
#region abstract implementation
|
||||
|
||||
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
|
||||
[Obsolete]
|
||||
public override UsersModel Get(string id)
|
||||
{
|
||||
|
@ -93,6 +93,7 @@ namespace PlexRequests.Store.Repository
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ namespace PlexRequests.UI.Modules
|
|||
Post["/clearlogs", true] = async (x, ct) => await ClearLogs();
|
||||
|
||||
Get["/notificationsettings", true] = async (x, ct) => await NotificationSettings();
|
||||
Post["/notificationsettings", true] = async (x, ct) => await SaveNotificationSettings();
|
||||
Post["/notificationsettings"] = x => SaveNotificationSettings();
|
||||
|
||||
Post["/recentlyAddedTest"] = x => RecentlyAddedTest();
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Analytics.TrackEventAsync(Category.Admin, Action.Save, "CollectAnalyticData turned off", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
}
|
||||
var result = PrService.SaveSettings(model);
|
||||
var result = await PrService.SaveSettingsAsync(model);
|
||||
|
||||
Analytics.TrackEventAsync(Category.Admin, Action.Save, "PlexRequestSettings", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
return Response.AsJson(result
|
||||
|
@ -520,7 +520,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
NotificationService.Subscribe(new EmailMessageNotification(EmailService));
|
||||
settings.Enabled = true;
|
||||
NotificationService.Publish(notificationModel, settings);
|
||||
await NotificationService.Publish(notificationModel, settings);
|
||||
Log.Info("Sent email notification test");
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -620,7 +620,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
NotificationService.Subscribe(new PushbulletNotification(PushbulletApi, PushbulletService));
|
||||
settings.Enabled = true;
|
||||
NotificationService.Publish(notificationModel, settings);
|
||||
await NotificationService.Publish(notificationModel, settings);
|
||||
Log.Info("Sent pushbullet notification test");
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -686,7 +686,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService));
|
||||
settings.Enabled = true;
|
||||
NotificationService.Publish(notificationModel, settings);
|
||||
await NotificationService.Publish(notificationModel, settings);
|
||||
Log.Info("Sent pushover notification test");
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -742,7 +742,10 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Negotiator Logs()
|
||||
{
|
||||
return View["Logs"];
|
||||
var model = false;
|
||||
if (Request.Query["developer"] != null)
|
||||
model = true;
|
||||
return View["Logs", model];
|
||||
}
|
||||
|
||||
private Response LoadLogs()
|
||||
|
@ -1040,7 +1043,7 @@ namespace PlexRequests.UI.Modules
|
|||
return View["NotificationSettings", s];
|
||||
}
|
||||
|
||||
private async Task<Negotiator> SaveNotificationSettings()
|
||||
private Negotiator SaveNotificationSettings()
|
||||
{
|
||||
var model = this.Bind<NotificationSettingsV2>();
|
||||
return View["NotificationSettings", model];
|
||||
|
@ -1050,12 +1053,13 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
try
|
||||
{
|
||||
Log.Debug("Clicked TEST");
|
||||
RecentlyAdded.Test();
|
||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Log.Error(e);
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,12 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Analytics = a;
|
||||
|
||||
Get["/", true] = async(x,c) => await SetCulture();
|
||||
Get["/"] = x => SetCulture();
|
||||
}
|
||||
|
||||
private IAnalytics Analytics { get; }
|
||||
|
||||
public async Task<RedirectResponse> SetCulture()
|
||||
private RedirectResponse SetCulture()
|
||||
{
|
||||
var culture = (string)Request.Query["l"];
|
||||
var returnUrl = (string)Request.Query["u"];
|
||||
|
|
|
@ -1234,7 +1234,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (IsAdmin)
|
||||
return true;
|
||||
|
||||
if (ShouldAutoApprove(type,s,Username))
|
||||
if (Security.HasPermissions(User, Permissions.BypassRequestLimit))
|
||||
return true;
|
||||
|
||||
var requestLimit = GetRequestLimitForType(type, s);
|
||||
|
|
|
@ -41,6 +41,7 @@ using PlexRequests.Core.SettingModels;
|
|||
using PlexRequests.Core.Users;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
|
@ -139,6 +140,7 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
|
||||
var authenticated = false;
|
||||
var isOwner = false;
|
||||
|
||||
var settings = await AuthService.GetSettingsAsync();
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
|
@ -173,6 +175,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
isOwner = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -194,6 +197,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
isOwner = true;
|
||||
userId = GetOwnerId(plexSettings.PlexAuthToken, username);
|
||||
}
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
|
@ -228,15 +232,26 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
var defaultSettings = UserManagementSettings.GetSettings();
|
||||
loginGuid = Guid.NewGuid();
|
||||
|
||||
var defaultPermissions = (Permissions)UserManagementHelper.GetPermissions(defaultSettings);
|
||||
if (isOwner)
|
||||
{
|
||||
// If we are the owner, add the admin permission.
|
||||
if (!defaultPermissions.HasFlag(Permissions.Administrator))
|
||||
{
|
||||
defaultPermissions += (int)Permissions.Administrator;
|
||||
}
|
||||
}
|
||||
|
||||
// Looks like we still don't have an entry, so this user does not exist
|
||||
await PlexUserRepository.InsertAsync(new PlexUsers
|
||||
{
|
||||
PlexUserId = GetUserIdIsInPlexFriends(username, plexSettings.PlexAuthToken) ?? string.Empty,
|
||||
PlexUserId = userId,
|
||||
UserAlias = string.Empty,
|
||||
Permissions = UserManagementHelper.GetPermissions(defaultSettings),
|
||||
Permissions = (int)defaultPermissions,
|
||||
Features = UserManagementHelper.GetPermissions(defaultSettings),
|
||||
Username = username,
|
||||
EmailAddress = string.Empty, // We don't have it, we will get it on the next scheduled job run
|
||||
Username = username,
|
||||
EmailAddress = string.Empty, // We don't have it, we will get it on the next scheduled job run (in 30 mins)
|
||||
LoginId = loginGuid.ToString()
|
||||
});
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/"] = x => Load();
|
||||
|
||||
Get["/users", true] = async (x, ct) => await LoadUsers();
|
||||
Post["/createuser", true] = async (x,ct) => await 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>();
|
||||
|
@ -91,6 +91,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
var dbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == u.Id);
|
||||
var userDb = userLogins.FirstOrDefault(x => x.UserId == u.Id);
|
||||
|
||||
// We don't have the user in the database yet
|
||||
if (dbUser == null)
|
||||
{
|
||||
|
@ -102,6 +103,15 @@ namespace PlexRequests.UI.Modules
|
|||
model.Add(MapPlexUser(u, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
|
||||
}
|
||||
}
|
||||
|
||||
// Also get the server admin
|
||||
var account = PlexApi.GetAccount(plexSettings.PlexAuthToken);
|
||||
if (account != null)
|
||||
{
|
||||
var dbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == account.Id);
|
||||
var userDb = userLogins.FirstOrDefault(x => x.UserId == account.Id);
|
||||
model.Add(MapPlexAdmin(account, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
|
||||
}
|
||||
}
|
||||
return Response.AsJson(model);
|
||||
}
|
||||
|
@ -193,7 +203,6 @@ namespace PlexRequests.UI.Modules
|
|||
localUser.Permissions = permissionsValue;
|
||||
localUser.Features = featuresValue;
|
||||
|
||||
|
||||
var currentProps = ByteConverterHelper.ReturnObject<UserProperties>(localUser.UserProperties);
|
||||
|
||||
// Let's check if the alias has changed, if so we need to change all the requests associated with this
|
||||
|
@ -232,6 +241,24 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(retUser);
|
||||
}
|
||||
|
||||
// So it could actually be the admin
|
||||
var account = PlexApi.GetAccount(plexSettings.PlexAuthToken);
|
||||
if (plexDbUser != null && account != null)
|
||||
{
|
||||
// We have a user in the DB for this Plex Account
|
||||
plexDbUser.Permissions = permissionsValue;
|
||||
plexDbUser.Features = featuresValue;
|
||||
|
||||
await UpdateRequests(plexDbUser.Username, plexDbUser.UserAlias, model.Alias);
|
||||
|
||||
plexDbUser.UserAlias = model.Alias;
|
||||
|
||||
await PlexUsersRepository.UpdateAsync(plexDbUser);
|
||||
|
||||
var retUser = MapPlexAdmin(account, plexDbUser, userLogin?.LastLoggedIn ?? DateTime.MinValue);
|
||||
return Response.AsJson(retUser);
|
||||
}
|
||||
|
||||
// We have a Plex Account but he's not in the DB
|
||||
if (plexUser != null)
|
||||
{
|
||||
|
@ -256,12 +283,11 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private async Task UpdateRequests(string username, string oldAlias, string newAlias)
|
||||
{
|
||||
var newUsername = string.IsNullOrEmpty(newAlias) ? username : newAlias; // User the username if we are clearing the alias
|
||||
var olderUsername = string.IsNullOrEmpty(oldAlias) ? username : oldAlias;
|
||||
// Let's check if the alias has changed, if so we need to change all the requests associated with this
|
||||
if (!oldAlias.Equals(newAlias, StringComparison.CurrentCultureIgnoreCase))
|
||||
if (!olderUsername.Equals(newUsername, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
var newUsername = string.IsNullOrEmpty(newAlias) ? username : newAlias; // User the username if we are clearing the alias
|
||||
var olderUsername = string.IsNullOrEmpty(oldAlias) ? username : oldAlias;
|
||||
|
||||
var requests = await RequestService.GetAllAsync();
|
||||
// Update all requests
|
||||
var requestsWithThisUser = requests.Where(x => x.RequestedUsers.Contains(olderUsername)).ToList();
|
||||
|
@ -371,35 +397,9 @@ namespace PlexRequests.UI.Modules
|
|||
LastLoggedIn = lastLoggedIn,
|
||||
};
|
||||
|
||||
// Add permissions
|
||||
foreach (var p in Enum.GetValues(typeof(Permissions)))
|
||||
{
|
||||
var perm = (Permissions)p;
|
||||
var displayValue = EnumHelper<Permissions>.GetDisplayValue(perm);
|
||||
var pm = new CheckBox
|
||||
{
|
||||
Name = displayValue,
|
||||
Selected = permissions.HasFlag(perm),
|
||||
Value = (int)perm
|
||||
};
|
||||
|
||||
m.Permissions.Add(pm);
|
||||
}
|
||||
|
||||
// Add features
|
||||
foreach (var p in Enum.GetValues(typeof(Features)))
|
||||
{
|
||||
var perm = (Features)p;
|
||||
var displayValue = EnumHelper<Features>.GetDisplayValue(perm);
|
||||
var pm = new CheckBox
|
||||
{
|
||||
Name = displayValue,
|
||||
Selected = features.HasFlag(perm),
|
||||
Value = (int)perm
|
||||
};
|
||||
|
||||
m.Features.Add(pm);
|
||||
}
|
||||
m.Permissions.AddRange(GetPermissions(permissions));
|
||||
m.Features.AddRange(GetFeatures(features));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
@ -429,6 +429,42 @@ namespace PlexRequests.UI.Modules
|
|||
},
|
||||
};
|
||||
|
||||
m.Permissions.AddRange(GetPermissions(permissions));
|
||||
m.Features.AddRange(GetFeatures(features));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private UserManagementUsersViewModel MapPlexAdmin(PlexAccount plexInfo, PlexUsers dbUser, DateTime lastLoggedIn)
|
||||
{
|
||||
if (dbUser == null)
|
||||
{
|
||||
dbUser = new PlexUsers();
|
||||
}
|
||||
var features = (Features)dbUser?.Features;
|
||||
var permissions = (Permissions)dbUser?.Permissions;
|
||||
|
||||
var m = new UserManagementUsersViewModel
|
||||
{
|
||||
Id = plexInfo.Id,
|
||||
PermissionsFormattedString = permissions == 0 ? "None" : permissions.ToString(),
|
||||
FeaturesFormattedString = features.ToString(),
|
||||
Username = plexInfo.Username,
|
||||
Type = UserType.PlexUser,
|
||||
EmailAddress = plexInfo.Email,
|
||||
Alias = dbUser?.UserAlias ?? string.Empty,
|
||||
LastLoggedIn = lastLoggedIn,
|
||||
};
|
||||
|
||||
m.Permissions.AddRange(GetPermissions(permissions));
|
||||
m.Features.AddRange(GetFeatures(features));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private List<CheckBox> GetPermissions(Permissions permissions)
|
||||
{
|
||||
var retVal = new List<CheckBox>();
|
||||
// Add permissions
|
||||
foreach (var p in Enum.GetValues(typeof(Permissions)))
|
||||
{
|
||||
|
@ -441,9 +477,15 @@ namespace PlexRequests.UI.Modules
|
|||
Value = (int)perm
|
||||
};
|
||||
|
||||
m.Permissions.Add(pm);
|
||||
retVal.Add(pm);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private List<CheckBox> GetFeatures(Features features)
|
||||
{
|
||||
var retVal = new List<CheckBox>();
|
||||
// Add features
|
||||
foreach (var p in Enum.GetValues(typeof(Features)))
|
||||
{
|
||||
|
@ -456,10 +498,9 @@ namespace PlexRequests.UI.Modules
|
|||
Value = (int)perm
|
||||
};
|
||||
|
||||
m.Features.Add(pm);
|
||||
retVal.Add(pm);
|
||||
}
|
||||
|
||||
return m;
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,14 @@
|
|||
@{
|
||||
var baseUrl = Html.GetBaseUrl();
|
||||
var formAction = "/admin/authentication";
|
||||
|
||||
var usermanagement = "/usermanagement";
|
||||
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
|
||||
{
|
||||
formAction = "/" + baseUrl.ToHtmlString() + formAction;
|
||||
usermanagement = "/" + baseUrl.ToHtmlString() + usermanagement;
|
||||
}
|
||||
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
<form class="form-horizontal" method="POST" action="@formAction" id="mainForm">
|
||||
|
@ -50,7 +54,7 @@
|
|||
|
||||
|
||||
<br />
|
||||
<a href="/@Html.GetBaseUrl()/usermanagement/" class="btn btn-info-outline">User Management</a>
|
||||
<a href="@usermanagement" class="btn btn-info-outline">User Management</a>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
<label for="logLevel" class="control-label">Log Level</label>
|
||||
<div id="logLevel">
|
||||
<select class="form-control" id="selected">
|
||||
<option id="Trace" value="0">Trace</option>
|
||||
@if (Model)
|
||||
{
|
||||
<option id="Trace" value="0">Trace</option>
|
||||
}
|
||||
<option id="Debug" value="1">Debug</option>
|
||||
<option id="Info" value="2">Info</option>
|
||||
<option id="Warn" value="3">Warn</option>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue