Ejemplo n.º 1
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                if (QueryValidationHelper.IsReservedGuid(UserId))
                {
                    throw new InvalidOperationException("Invalid user ID");
                }
                var user = await callContext.DbContext.Users.SingleAsync(u => u.Id == UserId);

                var cardVersion = await callContext.DbContext.CardPreviousVersions.Include(v => v.UsersWithView).SingleAsync(v => v.Id == VersionId);

                if (!CardVisibilityHelper.CardIsVisibleToUser(UserId, cardVersion.UsersWithView.Select(uwv => uwv.AllowedUserId)))
                {
                    throw new InvalidOperationException("Original not visible to user");
                }
            }
Ejemplo n.º 2
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                //We allow viewing the history of a card as soon as the user can access the current version of the card. Of course the differ will refuse to give details to a user not allowed

                QueryValidationHelper.CheckNotReservedGuid(UserId);
                QueryValidationHelper.CheckNotReservedGuid(CardId);

                var user = await callContext.DbContext.Users.SingleAsync(u => u.Id == UserId);

                var card = await callContext.DbContext.Cards.Include(v => v.UsersWithView).SingleAsync(v => v.Id == CardId);

                if (!CardVisibilityHelper.CardIsVisibleToUser(UserId, card.UsersWithView))
                {
                    throw new InvalidOperationException("Current not visible to user");
                }
            }
Ejemplo n.º 3
0
        public async Task <ImmutableArray <CardVersion> > RunAsync(Guid userId)
        {
            var chrono       = Stopwatch.StartNew();
            var cardVersions = await callContext.DbContext.Cards
                               .Include(card => card.VersionCreator)
                               .Include(card => card.UsersWithView)
                               .Join(callContext.DbContext.CardNotifications.Where(cardNotif => cardNotif.UserId == userId), card => card.Id, cardNotif => cardNotif.CardId, (card, cardNotif) => new { card, cardNotif })
                               .Where(cardAndNotif => cardAndNotif.card.VersionUtcDate > cardAndNotif.cardNotif.LastNotificationUtcDate)
                               .ToListAsync();

            performanceIndicators.Add($"{GetType().Name} took {chrono.Elapsed} to list user's registered cards with new versions");

            chrono.Restart();
            var result = cardVersions.Select(cardToReport =>
                                             new CardVersion(
                                                 cardToReport.card.Id,
                                                 cardToReport.card.FrontSide,
                                                 cardToReport.card.VersionCreator.UserName,
                                                 cardToReport.card.VersionUtcDate,
                                                 cardToReport.card.VersionDescription,
                                                 CardVisibilityHelper.CardIsVisibleToUser(userId, cardToReport.card.UsersWithView),
                                                 GetCardVersionOn(cardToReport.card.Id, cardToReport.cardNotif.LastNotificationUtcDate)
                                                 )
                                             ).ToImmutableArray();

            performanceIndicators.Add($"{GetType().Name} took {chrono.Elapsed} to create the result list with getting card version on last notif");

            chrono.Restart();
            foreach (var cardVersion in cardVersions)
            {
                cardVersion.cardNotif.LastNotificationUtcDate = runningUtcDate;
            }
            await callContext.DbContext.SaveChangesAsync();

            performanceIndicators.Add($"{GetType().Name} took {chrono.Elapsed} to update user's registered cards last notif date");
            callContext.TelemetryClient.TrackEvent("UserCardVersionsNotifier", ("ResultCount", result.Length.ToString()));
            return(result);
        }