mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 13:53:19 -07:00
Initial impliementation of #739
This commit is contained in:
parent
88c0651b1e
commit
973688393f
18 changed files with 624 additions and 21 deletions
|
@ -29,7 +29,10 @@ namespace Ombi.Core
|
|||
/// Gets the username this could be the alias! We should always use this method when getting the username
|
||||
/// </summary>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <returns><c>null</c> if we cannot find a user</returns>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <returns>
|
||||
/// <c>null</c> if we cannot find a user
|
||||
/// </returns>
|
||||
string GetUsername(string username, ISession session);
|
||||
}
|
||||
}
|
|
@ -122,6 +122,7 @@
|
|||
<Compile Include="Queue\TransientFaultQueue.cs" />
|
||||
<Compile Include="SecurityExtensions.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\DiscordNotificationSettings.cs" />
|
||||
<Compile Include="SettingModels\WatcherSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||
|
|
|
@ -94,34 +94,23 @@ namespace Ombi.Core
|
|||
/// Gets the username this could be the alias! We should always use this method when getting the username
|
||||
/// </summary>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <returns><c>null</c> if we cannot find a user</returns>
|
||||
/// <param name="session"></param>
|
||||
/// <returns>
|
||||
/// <c>null</c> if we cannot find a user
|
||||
/// </returns>
|
||||
public string GetUsername(string username, ISession session)
|
||||
{
|
||||
var plexUser = PlexUsers.GetUserByUsername(username);
|
||||
if (plexUser != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(plexUser.UserAlias))
|
||||
{
|
||||
return plexUser.UserAlias;
|
||||
}
|
||||
else
|
||||
{
|
||||
return plexUser.Username;
|
||||
}
|
||||
return !string.IsNullOrEmpty(plexUser.UserAlias) ? plexUser.UserAlias : plexUser.Username;
|
||||
}
|
||||
|
||||
var dbUser = UserRepository.GetUserByUsername(username);
|
||||
if (dbUser != null)
|
||||
{
|
||||
var userProps = ByteConverterHelper.ReturnObject<UserProperties>(dbUser.UserProperties);
|
||||
if (!string.IsNullOrEmpty(userProps.UserAlias))
|
||||
{
|
||||
return userProps.UserAlias;
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbUser.UserName;
|
||||
}
|
||||
return !string.IsNullOrEmpty(userProps.UserAlias) ? userProps.UserAlias : dbUser.UserName;
|
||||
}
|
||||
|
||||
// could be a local user
|
||||
|
|
31
Ombi.Core/SettingModels/DiscordNotificationSettings.cs
Normal file
31
Ombi.Core/SettingModels/DiscordNotificationSettings.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Ombi.Core.SettingModels
|
||||
{
|
||||
public sealed class DiscordNotificationSettings : NotificationSettings
|
||||
{
|
||||
public string WebhookUrl { get; set; }
|
||||
public string Username { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string WebookId => SplitWebUrl(4);
|
||||
|
||||
[JsonIgnore]
|
||||
public string Token => SplitWebUrl(5);
|
||||
|
||||
private string SplitWebUrl(int index)
|
||||
{
|
||||
if (!WebhookUrl.StartsWith("http", StringComparison.InvariantCulture))
|
||||
{
|
||||
WebhookUrl = "https://" + WebhookUrl;
|
||||
}
|
||||
var split = WebhookUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
return split.Length < index
|
||||
? string.Empty
|
||||
: split[index];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue