Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Convention Identifier #11

Merged
merged 9 commits into from
Nov 7, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Eurofurence.App.Domain.Model.Sync
{
public class AggregatedDeltaResponse
{
public string ConventionIdentifier { get; set; }

public DateTime? Since { get; set; }
public DateTime CurrentDateTimeUtc { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"global": {
"conventionNumber": 23,
"conventionIdentifier": "EF25",
"regSysAuthenticationEnabled": 0
},
"logLevel": 1,
Expand All @@ -20,12 +21,7 @@
"targetTopic": "Debug"
},
"firebase": {
"authorizationKey": "",
"targetTopic": {
"all": "",
"android": "",
"ios": ""
}
"authorizationKey": ""
},
"aws": {
"accessKey": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IPrivateMessageService

Task<Guid> SendPrivateMessageAsync(SendPrivateMessageRequest request, string senderUid = "System");

Task<int> FlushPrivateMessageQueueNotifications(int messageCount = 10);

Task<PrivateMessageStatus> GetPrivateMessageStatusAsync(Guid messageId);

Task<IEnumerable<PrivateMessageRecord>> GetPrivateMessagesForSenderAsync(string senderUid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Eurofurence.App.Server.Services.Abstractions
{
public class ConventionSettings
{
public int ConventionNumber { get; set; }
public string ConventionIdentifier { get; set; }
public bool IsRegSysAuthenticationEnabled { get; set; }
public string ApiBaseUrl { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ namespace Eurofurence.App.Server.Services.Abstractions.PushNotifications
public class FirebaseConfiguration
{
public string AuthorizationKey { get; set; }
public string TargetTopicAll { get; set; }
public string TargetTopicAndroid { get; set; }
public string TargetTopicIos { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task ImportActivityLogAsync(TextReader logReader)
var newRecord = new ItemActivityRecord()
{
Id = Guid.NewGuid(),
OwnerUid = $"RegSys:{_conventionSettings.ConventionNumber}:{csvRecord.RegNo}",
OwnerUid = $"RegSys:{_conventionSettings.ConventionIdentifier}:{csvRecord.RegNo}",
ASIDNO = csvRecord.ASIDNO,
ArtistName = csvRecord.ArtistName,
ArtPieceTitle = csvRecord.ArtPieceTitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -14,6 +15,7 @@ public class PrivateMessageService : EntityServiceBase<PrivateMessageRecord>,
IPrivateMessageService
{
private readonly IPushEventMediator _pushEventMediator;
private readonly ConcurrentQueue<QueuedNotificationParameters> _notificationQueue = new ConcurrentQueue<QueuedNotificationParameters>();

public PrivateMessageService(
IEntityRepository<PrivateMessageRecord> entityRepository,
Expand Down Expand Up @@ -53,6 +55,15 @@ public async Task<IEnumerable<PrivateMessageRecord>> GetPrivateMessagesForRecipi
return message.ReadDateTimeUtc;
}


private struct QueuedNotificationParameters
{
public string RecipientUid;
public string ToastTitle;
public string ToastMessage;
public Guid RelatedId;
}

public async Task<Guid> SendPrivateMessageAsync(SendPrivateMessageRequest request, string senderUid = "System")
{
var entity = new PrivateMessageRecord
Expand All @@ -67,8 +78,14 @@ public async Task<Guid> SendPrivateMessageAsync(SendPrivateMessageRequest reques
entity.NewId();

await InsertOneAsync(entity);
await _pushEventMediator.PushPrivateMessageNotificationAsync(
request.RecipientUid, request.ToastTitle, request.ToastMessage, entity.Id);

_notificationQueue.Enqueue(new QueuedNotificationParameters()
{
RecipientUid = request.RecipientUid,
ToastTitle = request.ToastTitle,
ToastMessage = request.ToastMessage,
RelatedId = entity.Id
});

return entity.Id;
}
Expand Down Expand Up @@ -98,5 +115,31 @@ public async Task<IEnumerable<PrivateMessageRecord>> GetPrivateMessagesForSender
{
return await FindAllAsync(a => a.SenderUid == senderUid);
}

public async Task<int> FlushPrivateMessageQueueNotifications(int messageCount = 10)
{
var flushedMessageCount = 0;

for(int i = 0; i < messageCount; i++)
{
if (_notificationQueue.TryDequeue(out QueuedNotificationParameters parameters))
{
await _pushEventMediator.PushPrivateMessageNotificationAsync(
parameters.RecipientUid,
parameters.ToastTitle,
parameters.ToastMessage,
parameters.RelatedId
);

flushedMessageCount++;
}
else
{
break;
}
}

return flushedMessageCount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<PushNotificationChannelStatisticsService>().As<IPushNotificationChannelStatisticsService>();
builder.RegisterType<FirebaseChannelManager>().As<IFirebaseChannelManager>();
builder.RegisterType<LinkFragmentValidator>().As<ILinkFragmentValidator>();
builder.RegisterType<PrivateMessageService>().As<IPrivateMessageService>();
builder.RegisterType<PrivateMessageService>()
.As<IPrivateMessageService>()
.SingleInstance();

builder.RegisterType<RegSysAlternativePinAuthenticationProvider>()
.As<IRegSysAlternativePinAuthenticationProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<Guid> UpsertFursuitBadgeAsync(FursuitBadgeRegistration registr
}

record.ExternalReference = registration.BadgeNo.ToString();
record.OwnerUid = $"RegSys:{_conventionSettings.ConventionNumber}:{registration.RegNo}";
record.OwnerUid = $"RegSys:{_conventionSettings.ConventionIdentifier}:{registration.RegNo}";
record.Gender = registration.Gender;
record.Name = registration.Name;
record.Species = registration.Species;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Eurofurence.App.Domain.Model.Abstractions;
using Eurofurence.App.Domain.Model.Announcements;
using Eurofurence.App.Domain.Model.PushNotifications;
using Eurofurence.App.Server.Services.Abstractions;
using Eurofurence.App.Server.Services.Abstractions.PushNotifications;
using Newtonsoft.Json;

Expand All @@ -18,14 +19,18 @@ public class FirebaseChannelManager : IFirebaseChannelManager
{
private readonly FirebaseConfiguration _configuration;
private readonly IEntityRepository<PushNotificationChannelRecord> _pushNotificationRepository;
private readonly ConventionSettings _conventionSettings;

public FirebaseChannelManager(
FirebaseConfiguration configuration,
IEntityRepository<PushNotificationChannelRecord> pushNotificationRepository)
IEntityRepository<PushNotificationChannelRecord> pushNotificationRepository,
ConventionSettings conventionSettings
)

{
_configuration = configuration;
_pushNotificationRepository = pushNotificationRepository;
_conventionSettings = conventionSettings;
}

private Task<IEnumerable<PushNotificationChannelRecord>> GetRecipientChannelAsync(string recipientUid)
Expand All @@ -46,7 +51,7 @@ public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)
Text = announcement.Content.RemoveMarkdown(),
RelatedId = announcement.Id
},
to = $"/topics/{_configuration.TargetTopicAndroid}"
to = $"/topics/{_conventionSettings.ConventionIdentifier}-android"
}),
SendPushNotificationAsync(new
{
Expand All @@ -62,7 +67,7 @@ public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)
},
content_available = true,
priority = "high",
to = $"/topics/{_configuration.TargetTopicIos}"
to = $"/topics/{_conventionSettings.ConventionIdentifier}-ios"
})
);
}
Expand Down Expand Up @@ -116,7 +121,7 @@ public Task PushSyncRequestAsync()
{
Event = "Sync",
},
to = $"/topics/{_configuration.TargetTopicAndroid}"
to = $"/topics/{_conventionSettings.ConventionIdentifier}-android"
}),
SendPushNotificationAsync(new
{
Expand All @@ -126,7 +131,7 @@ public Task PushSyncRequestAsync()
},
content_available = true,
priority = "high",
to = $"/topics/{_configuration.TargetTopicIos}"
to = $"/topics/{_conventionSettings.ConventionIdentifier}-ios"
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task<AuthenticationResponse> AuthorizeViaRegSys(RegSysAuthenticatio
return null;
}

var uid = $"RegSys:{_conventionSettings.ConventionNumber}:{authenticationResult.RegNo}";
var uid = $"RegSys:{_conventionSettings.ConventionIdentifier}:{authenticationResult.RegNo}";

var identityRecord = await _regSysIdentityRepository.FindOneAsync(a => a.Uid == uid);
if (identityRecord == null)
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task<AuthenticationResponse> AuthorizeViaRegSys(RegSysAuthenticatio
new Claim(ClaimTypes.Name, uid),
new Claim(ClaimTypes.GivenName, authenticationResult.Username),
new Claim(ClaimTypes.PrimarySid, authenticationResult.RegNo.ToString()),
new Claim(ClaimTypes.GroupSid, _conventionSettings.ConventionNumber.ToString()),
new Claim(ClaimTypes.GroupSid, _conventionSettings.ConventionIdentifier.ToString()),
new Claim(ClaimTypes.System, "RegSys")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public async Task CommandSendMessage()
return;
}

var recipientUid = $"RegSys:{_conventionSettings.ConventionNumber}:{regNo}";
var recipientUid = $"RegSys:{_conventionSettings.ConventionIdentifier}:{regNo}";
var messageId = await _privateMessageService.SendPrivateMessageAsync(new SendPrivateMessageRequest()
{
AuthorName = $"{from}",
Expand Down Expand Up @@ -341,7 +341,7 @@ public async Task CommandCollectionGameUnban()
}

var result = await _collectingGameService.UnbanPlayerAsync(
$"RegSys:{_conventionSettings.ConventionNumber}:{regNo}");
$"RegSys:{_conventionSettings.ConventionIdentifier}:{regNo}");

if (result.IsSuccessful)
{
Expand Down Expand Up @@ -660,7 +660,7 @@ private async Task CommandCollectionGameRegisterFursuit()
return;
}

if (badge.OwnerUid != $"RegSys:{_conventionSettings.ConventionNumber}:{regNo}")
if (badge.OwnerUid != $"RegSys:{_conventionSettings.ConventionIdentifier}:{regNo}")
{
await ReplyAsync($"*Error*: Fursuit badge with no *{fursuitBadgeNo}* exists, but does *not* belong to reg no *{regNo}*. Aborting.");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Server.Services/Telegram/BotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private async Task<InlineQueryResult[]> QueryEvents(string query)
messageBuilder.Append($"\n\n_{desc}_");
}

messageBuilder.Append($"\n\n[Read more...](https://www.eurofurence.org/EF{_conventionSettings.ConventionNumber}/schedule/events/{e.SourceEventId}.en.html)");
messageBuilder.Append($"\n\n[Read more...](https://www.eurofurence.org/{_conventionSettings.ConventionIdentifier}/schedule/events/{e.SourceEventId}.en.html)");

return new InlineQueryResultArticle()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class AnnouncementsController : Controller
[Route("Api/[controller]")]
public class AnnouncementsController : BaseController
{
private readonly IAnnouncementService _announcementService;
private readonly IPushEventMediator _eventMediator;
Expand Down
10 changes: 3 additions & 7 deletions src/Eurofurence.App.Server.Web/Controllers/ArtShowController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Eurofurence.App.Server.Services.Abstractions.ArtShow;
using Eurofurence.App.Server.Services.Abstractions.Fursuits;
using Eurofurence.App.Server.Services.Abstractions.Security;
using Eurofurence.App.Server.Web.Extensions;
using Eurofurence.App.Server.Web.Swagger;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class ArtShowController : Controller
[Route("Api/[controller]")]
public class ArtShowController : BaseController
{
private readonly IItemActivityService _itemActivityService;
private readonly IApiPrincipal _apiPrincipal;
Expand Down
10 changes: 10 additions & 0 deletions src/Eurofurence.App.Server.Web/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Eurofurence.App.Server.Web.Extensions;
using Microsoft.AspNetCore.Mvc;

namespace Eurofurence.App.Server.Web.Controllers
{
[CidRouteBase]
public class BaseController : Controller
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Eurofurence.App.Domain.Model.Communication;
using Eurofurence.App.Server.Services.Abstractions.Communication;
Expand All @@ -11,8 +10,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class CommunicationController : Controller
[Route("Api/[controller]")]
public class CommunicationController : BaseController
{
private readonly IApiPrincipal _apiPrincipal;
private readonly IPrivateMessageService _privateMessageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class DealersController : Controller
[Route("Api/[controller]")]
public class DealersController : BaseController
{
private readonly IDealerService _dealerService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class EventConferenceDaysController : Controller
[Route("Api/[controller]")]
public class EventConferenceDaysController : BaseController
{
private readonly IEventConferenceDayService _eventConferenceDayService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class EventConferenceRoomsController : Controller
[Route("Api/[controller]")]
public class EventConferenceRoomsController : BaseController
{
private readonly IEventConferenceRoomService _eventConferenceRoomService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/v2/[controller]")]
public class EventConferenceTracksController : Controller
[Route("Api/[controller]")]
public class EventConferenceTracksController : BaseController
{
private readonly IEventConferenceTrackService _eventConferenceTrackService;

Expand Down
Loading