From 4915da4cdd9bd7de3f67fa681e06585dbbcfafdb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Mar 2015 01:58:29 -0400 Subject: sync updates --- MediaBrowser.Api/ConnectService.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'MediaBrowser.Api/ConnectService.cs') diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index 4bcd33d9e3..09cbafca6f 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -73,6 +73,12 @@ namespace MediaBrowser.Api public string ConnectUserId { get; set; } } + [Route("/Connect/Supporters", "GET")] + [Authenticated(Roles = "Admin")] + public class GetConnectSupporterSummary : IReturn + { + } + public class ConnectService : BaseApiService { private readonly IConnectManager _connectManager; @@ -84,6 +90,13 @@ namespace MediaBrowser.Api _userManager = userManager; } + public async Task Get(GetConnectSupporterSummary request) + { + var result = await _connectManager.GetConnectSupporterSummary().ConfigureAwait(false); + + return ToOptimizedResult(result); + } + public object Post(CreateConnectLink request) { return _connectManager.LinkUser(request.Id, request.ConnectUsername); -- cgit v1.2.3 From 8b89d0b020c5cf060158007ba55d4dd4d62e0ebf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Mar 2015 11:03:59 -0400 Subject: support remove connect user --- MediaBrowser.Api/ConnectService.cs | 15 +++++++++++ MediaBrowser.Controller/Connect/IConnectManager.cs | 7 +++++ .../Connect/ConnectManager.cs | 30 +++++++++++++++++++++- .../Localization/JavaScript/javascript.json | 2 ++ 4 files changed, 53 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Api/ConnectService.cs') diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index 09cbafca6f..f84b74203f 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -79,6 +79,14 @@ namespace MediaBrowser.Api { } + [Route("/Connect/Supporters", "DELETE")] + [Authenticated(Roles = "Admin")] + public class RemoveConnectSupporter : IReturnVoid + { + [ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")] + public string Id { get; set; } + } + public class ConnectService : BaseApiService { private readonly IConnectManager _connectManager; @@ -97,6 +105,13 @@ namespace MediaBrowser.Api return ToOptimizedResult(result); } + public void Delete(RemoveConnectSupporter request) + { + var task = _connectManager.RemoveConnectSupporter(request.Id); + + Task.WaitAll(task); + } + public object Post(CreateConnectLink request) { return _connectManager.LinkUser(request.Id, request.ConnectUsername); diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index 4003d1bf26..e745f3df31 100644 --- a/MediaBrowser.Controller/Connect/IConnectManager.cs +++ b/MediaBrowser.Controller/Connect/IConnectManager.cs @@ -75,5 +75,12 @@ namespace MediaBrowser.Controller.Connect /// /// Task<ConnectSupporterSummary>. Task GetConnectSupporterSummary(); + + /// + /// Removes the connect supporter. + /// + /// The identifier. + /// Task. + Task RemoveConnectSupporter(string id); } } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index c9b690086a..ac8ce7638e 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -1068,7 +1068,7 @@ namespace MediaBrowser.Server.Implementations.Connect url += "?serverId=" + ConnectServerId; url += "&supporterKey=" + _securityManager.SupporterKey; - + var options = new HttpRequestOptions { Url = url, @@ -1085,6 +1085,34 @@ namespace MediaBrowser.Server.Implementations.Connect } } + public async Task RemoveConnectSupporter(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, "DELETE").ConfigureAwait(false)).Content) + { + } + } + public async Task Authenticate(string username, string passwordMd5) { if (string.IsNullOrWhiteSpace(username)) diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index 9e0260f3c7..d995e485f9 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -38,6 +38,8 @@ "ErrorLaunchingChromecast": "There was an error launching chromecast. Please ensure your device is connected to your wireless network.", "MessageErrorLoadingSupporterInfo": "There was an error loading supporter information. Please try again later.", "MessageLinkYourSupporterKey": "Link your supporter key with up to {0} Media Browser Connect members to enjoy free access to the following apps:", + "HeaderConfirmRemoveUser": "Remove User", + "MessageConfirmRemoveConnectSupporter": "Are you sure you wish to remove the additional supporter benefits from this user?", "ValueTimeLimitSingleHour": "Time limit: 1 hour", "ValueTimeLimitMultiHour": "Time limit: {0} hours", "PluginCategoryGeneral": "General", -- cgit v1.2.3 From d9d295251cb7ff95173e81db55408adc8de17eab Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Mar 2015 11:57:06 -0400 Subject: support adding connect user --- MediaBrowser.Api/ConnectService.cs | 27 ++++++++++++++++++++- .../Connect/ConnectSupporterSummary.cs | 3 +++ MediaBrowser.Controller/Connect/IConnectManager.cs | 7 ++++++ .../Connect/ConnectManager.cs | 28 ++++++++++++++++++++++ .../Localization/Server/server.json | 2 ++ 5 files changed, 66 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Api/ConnectService.cs') diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index f84b74203f..bdd2eeaadd 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -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 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); diff --git a/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs b/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs index 47ff90e705..20eef0521b 100644 --- a/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs +++ b/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs @@ -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 Users { get; set; } + public List EligibleUsers { get; set; } public ConnectSupporterSummary() { Users = new List(); + EligibleUsers = new List(); } } } diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index e745f3df31..7eecf6ebff 100644 --- a/MediaBrowser.Controller/Connect/IConnectManager.cs +++ b/MediaBrowser.Controller/Connect/IConnectManager.cs @@ -82,5 +82,12 @@ namespace MediaBrowser.Controller.Connect /// The identifier. /// Task. Task RemoveConnectSupporter(string id); + + /// + /// Adds the connect supporter. + /// + /// The identifier. + /// Task. + Task AddConnectSupporter(string id); } } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index ac8ce7638e..be0b325487 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -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) diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 2f4470c960..18447ade10 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -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", -- cgit v1.2.3