mirror of
https://github.com/bitwarden/server.git
synced 2025-05-29 15:24:51 -05:00
leave a note on new tickets
This commit is contained in:
parent
726ce2510f
commit
abe624b739
@ -12,6 +12,7 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Bit.Core;
|
||||||
|
|
||||||
namespace Bit.Billing.Controllers
|
namespace Bit.Billing.Controllers
|
||||||
{
|
{
|
||||||
@ -23,6 +24,7 @@ namespace Bit.Billing.Controllers
|
|||||||
private readonly IOrganizationRepository _organizationRepository;
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly ILogger<AppleController> _logger;
|
private readonly ILogger<AppleController> _logger;
|
||||||
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly HttpClient _httpClient = new HttpClient();
|
private readonly HttpClient _httpClient = new HttpClient();
|
||||||
private readonly string _freshdeskAuthkey;
|
private readonly string _freshdeskAuthkey;
|
||||||
|
|
||||||
@ -31,13 +33,15 @@ namespace Bit.Billing.Controllers
|
|||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
IOptions<BillingSettings> billingSettings,
|
IOptions<BillingSettings> billingSettings,
|
||||||
ILogger<AppleController> logger)
|
ILogger<AppleController> logger,
|
||||||
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_billingSettings = billingSettings?.Value;
|
_billingSettings = billingSettings?.Value;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_globalSettings = globalSettings;
|
||||||
_freshdeskAuthkey = Convert.ToBase64String(
|
_freshdeskAuthkey = Convert.ToBase64String(
|
||||||
Encoding.UTF8.GetBytes($"{_billingSettings.FreshdeskApiKey}:X"));
|
Encoding.UTF8.GetBytes($"{_billingSettings.FreshdeskApiKey}:X"));
|
||||||
}
|
}
|
||||||
@ -79,9 +83,11 @@ namespace Bit.Billing.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var updateBody = new Dictionary<string, object>();
|
var updateBody = new Dictionary<string, object>();
|
||||||
|
var note = string.Empty;
|
||||||
var user = await _userRepository.GetByEmailAsync(ticketContactEmail);
|
var user = await _userRepository.GetByEmailAsync(ticketContactEmail);
|
||||||
if(user != null)
|
if(user != null)
|
||||||
{
|
{
|
||||||
|
note += $"User: {_globalSettings.BaseServiceUri.Admin}/users/edit/{user.Id}";
|
||||||
var tags = new List<string>();
|
var tags = new List<string>();
|
||||||
if(user.Premium)
|
if(user.Premium)
|
||||||
{
|
{
|
||||||
@ -90,6 +96,8 @@ namespace Bit.Billing.Controllers
|
|||||||
var orgs = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
var orgs = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
||||||
foreach(var org in orgs)
|
foreach(var org in orgs)
|
||||||
{
|
{
|
||||||
|
note += $"\n\nOrg, {org.Name}: " +
|
||||||
|
$"{_globalSettings.BaseServiceUri.Admin}/organizations/edit/{org.Id}";
|
||||||
var planName = GetAttribute<DisplayAttribute>(org.PlanType).Name.Split(" ").FirstOrDefault();
|
var planName = GetAttribute<DisplayAttribute>(org.PlanType).Name.Split(" ").FirstOrDefault();
|
||||||
if(!string.IsNullOrWhiteSpace(planName))
|
if(!string.IsNullOrWhiteSpace(planName))
|
||||||
{
|
{
|
||||||
@ -106,12 +114,23 @@ namespace Bit.Billing.Controllers
|
|||||||
{
|
{
|
||||||
updateBody.Add("tags", tags);
|
updateBody.Add("tags", tags);
|
||||||
}
|
}
|
||||||
|
var updateRequest = new HttpRequestMessage(HttpMethod.Put,
|
||||||
var request = new HttpRequestMessage(HttpMethod.Put,
|
|
||||||
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}", ticketId));
|
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}", ticketId));
|
||||||
request.Content = new StringContent(JsonConvert.SerializeObject(updateBody),
|
updateRequest.Content = new StringContent(JsonConvert.SerializeObject(updateBody),
|
||||||
Encoding.UTF8, "application/json");
|
Encoding.UTF8, "application/json");
|
||||||
await CallFreshdeskApiAsync(request);
|
await CallFreshdeskApiAsync(updateRequest);
|
||||||
|
|
||||||
|
|
||||||
|
var noteBody = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "body", note },
|
||||||
|
{ "private", true }
|
||||||
|
};
|
||||||
|
var noteRequest = new HttpRequestMessage(HttpMethod.Post,
|
||||||
|
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}/notes", ticketId));
|
||||||
|
noteRequest.Content = new StringContent(JsonConvert.SerializeObject(noteBody),
|
||||||
|
Encoding.UTF8, "application/json");
|
||||||
|
await CallFreshdeskApiAsync(noteRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new OkResult();
|
return new OkResult();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user