support adding connect user
This commit is contained in:
parent
8b89d0b020
commit
d9d295251c
|
@ -1,8 +1,10 @@
|
|||
using MediaBrowser.Common.Extensions;
|
||||
using System;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Connect;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Connect;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using ServiceStack;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -87,6 +89,14 @@ namespace MediaBrowser.Api
|
|||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Connect/Supporters", "POST")]
|
||||
[Authenticated(Roles = "Admin")]
|
||||
public class AddConnectSupporter : IReturnVoid
|
||||
{
|
||||
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class ConnectService : BaseApiService
|
||||
{
|
||||
private readonly IConnectManager _connectManager;
|
||||
|
@ -101,6 +111,14 @@ namespace MediaBrowser.Api
|
|||
public async Task<object> Get(GetConnectSupporterSummary request)
|
||||
{
|
||||
var result = await _connectManager.GetConnectSupporterSummary().ConfigureAwait(false);
|
||||
var existingConnectUserIds = result.Users.Select(i => i.Id).ToList();
|
||||
|
||||
result.EligibleUsers = _userManager.Users
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i.ConnectUserId))
|
||||
.Where(i => !existingConnectUserIds.Contains(i.ConnectUserId, StringComparer.OrdinalIgnoreCase))
|
||||
.OrderBy(i => i.Name)
|
||||
.Select(i => _userManager.GetUserDto(i))
|
||||
.ToList();
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
@ -112,6 +130,13 @@ namespace MediaBrowser.Api
|
|||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
public void Post(AddConnectSupporter request)
|
||||
{
|
||||
var task = _connectManager.AddConnectSupporter(request.Id);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
public object Post(CreateConnectLink request)
|
||||
{
|
||||
return _connectManager.LinkUser(request.Id, request.ConnectUsername);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using MediaBrowser.Model.Connect;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Dto;
|
||||
|
||||
namespace MediaBrowser.Controller.Connect
|
||||
{
|
||||
|
@ -7,10 +8,12 @@ namespace MediaBrowser.Controller.Connect
|
|||
{
|
||||
public int MaxUsers { get; set; }
|
||||
public List<ConnectUser> Users { get; set; }
|
||||
public List<UserDto> EligibleUsers { get; set; }
|
||||
|
||||
public ConnectSupporterSummary()
|
||||
{
|
||||
Users = new List<ConnectUser>();
|
||||
EligibleUsers = new List<UserDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,5 +82,12 @@ namespace MediaBrowser.Controller.Connect
|
|||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task RemoveConnectSupporter(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the connect supporter.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task AddConnectSupporter(string id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1085,6 +1085,34 @@ namespace MediaBrowser.Server.Implementations.Connect
|
|||
}
|
||||
}
|
||||
|
||||
public async Task AddConnectSupporter(string id)
|
||||
{
|
||||
if (!_securityManager.IsMBSupporter)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var url = GetConnectUrl("keyAssociation");
|
||||
|
||||
url += "?serverId=" + ConnectServerId;
|
||||
url += "&supporterKey=" + _securityManager.SupporterKey;
|
||||
url += "&userId=" + id;
|
||||
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
CancellationToken = CancellationToken.None
|
||||
};
|
||||
|
||||
SetServerAccessToken(options);
|
||||
SetApplicationHeader(options);
|
||||
|
||||
// No need to examine the response
|
||||
using (var stream = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveConnectSupporter(string id)
|
||||
{
|
||||
if (!_securityManager.IsMBSupporter)
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
"ButtonOrganize": "Organize",
|
||||
"LinkedToMediaBrowserConnect": "Linked to Media Browser Connect",
|
||||
"HeaderSupporterBenefits": "Supporter Benefits",
|
||||
"HeaderAddUser": "Add User",
|
||||
"LabelAddConnectSupporterHelp": "To add a user who isn't listed, you'll need to first link their accounts to Media Browser Connect from their user profile page.",
|
||||
"LabelPinCode": "Pin code:",
|
||||
"ButtonOk": "Ok",
|
||||
"ButtonCancel": "Cancel",
|
||||
|
|
Loading…
Reference in New Issue
Block a user