public async Task SendNotification_ForValidData_ReturnsStatusCodeOk()
        {
            // Arrange
            var controller        = this.GetControllerInstance();
            var draftNotification = new DraftNotification()
            {
                Id = "id"
            };
            var    sentNotificationId = "notificationId";
            string appId                  = null;
            var    teamsAppId             = "appId";
            var    statusCodeOk           = 200;
            var    notificationDataEntity = new NotificationDataEntity();

            this.notificationDataRepository.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(notificationDataEntity);
            this.notificationDataRepository.Setup(x => x.MoveDraftToSentPartitionAsync(It.IsAny <NotificationDataEntity>())).ReturnsAsync(sentNotificationId);
            this.sentNotificationDataRepository.Setup(x => x.EnsureSentNotificationDataTableExistsAsync()).Returns(Task.CompletedTask);
            this.appSettingsService.Setup(x => x.GetUserAppIdAsync()).ReturnsAsync(appId);
            this.appSettingsService.Setup(x => x.SetUserAppIdAsync(It.IsAny <string>())).Returns(Task.CompletedTask);
            this.appCatalogService.Setup(x => x.GetTeamsAppIdAsync(It.IsAny <string>())).ReturnsAsync(teamsAppId);
            this.prepareToSendQueue.Setup(x => x.SendAsync(It.IsAny <PrepareToSendQueueMessageContent>())).Returns(Task.CompletedTask);
            this.dataQueue.Setup(x => x.SendDelayedAsync(It.IsAny <DataQueueMessageContent>(), It.IsAny <double>())).Returns(Task.CompletedTask);

            // Act
            var result = await controller.CreateSentNotificationAsync(draftNotification);

            var statusCode = ((StatusCodeResult)result).StatusCode;

            // Assert
            Assert.Equal(statusCode, statusCodeOk);
        }
Beispiel #2
0
        public async Task <ActionResult <string> > CreateDraftNotificationAsync([FromBody] DraftNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            if (!notification.Validate(this.localizer, out string errorMessage))
            {
                return(this.BadRequest(errorMessage));
            }

            var containsHiddenMembership = await this.groupsService.ContainsHiddenMembershipAsync(notification.Groups);

            if (containsHiddenMembership)
            {
                return(this.Forbid());
            }

            await this.UploadToBlobStorage(notification);

            notification.TrackingUrl = this.HttpContext.Request.Scheme + "://" + this.HttpContext.Request.Host + "/api/sentNotifications/tracking";

            var notificationId = await this.notificationDataRepository.CreateDraftNotificationAsync(
                notification,
                this.HttpContext.User?.Identity?.Name);

            return(this.Ok(notificationId));
        }
        public async Task Get_SetUserAppIdServiceCall_ShouldInvokedOnce()
        {
            // Arrange
            var controller        = this.GetControllerInstance();
            var draftNotification = new DraftNotification()
            {
                Id = "id"
            };
            var    sentNotificationId = "notificationId";
            string appId                  = null;
            var    teamsAppId             = "appId";
            var    notificationDataEntity = new NotificationDataEntity();

            this.notificationDataRepository.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(notificationDataEntity);
            this.notificationDataRepository.Setup(x => x.MoveDraftToSentPartitionAsync(It.IsAny <NotificationDataEntity>())).ReturnsAsync(sentNotificationId);
            this.sentNotificationDataRepository.Setup(x => x.EnsureSentNotificationDataTableExistsAsync()).Returns(Task.CompletedTask);
            this.appSettingsService.Setup(x => x.GetUserAppIdAsync()).ReturnsAsync(appId);
            this.appSettingsService.Setup(x => x.SetUserAppIdAsync(It.IsAny <string>())).Returns(Task.CompletedTask);
            this.appCatalogService.Setup(x => x.GetTeamsAppIdAsync(It.IsAny <string>())).ReturnsAsync(teamsAppId);

            // Act
            await controller.CreateSentNotificationAsync(draftNotification);

            // Assert
            this.appSettingsService.Verify(x => x.SetUserAppIdAsync(It.IsAny <string>()), Times.Once());
        }
        public async Task UpdateDraftNotificationAsync([FromBody] DraftNotification notification)
        {
            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey    = PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                RowKey          = notification.Id,
                Id              = notification.Id,
                Title           = notification.Title,
                ImageLink       = notification.ImageLink,
                Summary         = notification.Summary,
                Author          = notification.Author,
                ButtonTitle     = notification.ButtonTitle,
                ButtonLink      = notification.ButtonLink,
                ButtonTitle2    = notification.ButtonTitle2,
                ButtonLink2     = notification.ButtonLink2,
                CreatedBy       = this.HttpContext.User?.Identity?.Name,
                CreatedDate     = DateTime.UtcNow,
                IsDraft         = true,
                Teams           = notification.Teams,
                Rosters         = notification.Rosters,
                ADGroups        = notification.ADGroups,
                AllUsers        = notification.AllUsers,
                IsScheduled     = notification.IsScheduled,
                ScheduleDate    = notification.ScheduleDate,
                IsRecurrence    = notification.IsRecurrence,
                Repeats         = notification.Repeats,
                RepeatFor       = Convert.ToInt32(notification.RepeatFor),
                RepeatFrequency = notification.RepeatFrequency,
                WeekSelection   = notification.WeekSelection,
                RepeatStartDate = notification.RepeatStartDate,
                RepeatEndDate   = notification.RepeatEndDate,
            };

            await this.notificationDataRepository.CreateOrUpdateAsync(notificationEntity);
        }
        public async Task <ActionResult <DraftNotification> > GetDraftNotificationByIdAsync(string id)
        {
            var notificationEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.DraftNotificationsPartition,
                id);

            if (notificationEntity == null)
            {
                return(this.NotFound());
            }

            var result = new DraftNotification
            {
                Id              = notificationEntity.Id,
                Title           = notificationEntity.Title,
                ImageLink       = notificationEntity.ImageLink,
                Summary         = notificationEntity.Summary,
                Author          = notificationEntity.Author,
                ButtonTitle     = notificationEntity.ButtonTitle,
                ButtonLink      = notificationEntity.ButtonLink,
                CreatedDateTime = notificationEntity.CreatedDate,
                Teams           = notificationEntity.Teams,
                Rosters         = notificationEntity.Rosters,
                Groups          = notificationEntity.Groups,
                AllUsers        = notificationEntity.AllUsers,
            };

            return(this.Ok(result));
        }
        /// <summary>
        /// Create a new draft notification.
        /// </summary>
        /// <param name="notificationRepository">The notification repository.</param>
        /// <param name="notification">Draft Notification model class instance passed in from Web API.</param>
        /// <param name="userName">Name of the user who is running the application.</param>
        /// <returns>The newly created notification's id.</returns>
        public static async Task <string> CreateDraftNotificationAsync(
            this INotificationDataRepository notificationRepository,
            DraftNotification notification,
            string userName)
        {
            var newId = notificationRepository.TableRowKeyGenerator.CreateNewKeyOrderingOldestToMostRecent();

            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey = NotificationDataTableNames.DraftNotificationsPartition,
                RowKey       = newId,
                Id           = newId,
                Title        = notification.Title,
                ImageLink    = notification.ImageLink,
                Summary      = notification.Summary,
                Author       = notification.Author,
                ButtonTitle  = notification.ButtonTitle,
                ButtonLink   = notification.ButtonLink,
                CreatedBy    = userName,
                CreatedDate  = DateTime.UtcNow,
                IsDraft      = true,
                Teams        = notification.Teams,
                Rosters      = notification.Rosters,
                Groups       = notification.Groups,
                AllUsers     = notification.AllUsers,
            };

            await notificationRepository.CreateOrUpdateAsync(notificationEntity);

            return(newId);
        }
        public async Task <IActionResult> CreateSentNotificationAsync(
            [FromBody] DraftNotification draftNotification)
        {
            if (draftNotification == null)
            {
                throw new ArgumentNullException(nameof(draftNotification));
            }

            // TODO: double-check it
            // draftNotification.Buttons = this.GetButtonTrackingUrl(draftNotification);

            var draftNotificationDataEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.DraftNotificationsPartition,
                draftNotification.Id);

            if (draftNotificationDataEntity == null)
            {
                return(this.NotFound($"Draft notification, Id: {draftNotification.Id}, could not be found."));
            }

            var newSentNotificationId =
                await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftNotificationDataEntity);

            // Ensure the data table needed by the Azure Functions to send the notifications exist in Azure storage.
            await this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync();

            // Update user app id if proactive installation is enabled.
            await this.UpdateUserAppIdAsync();

            var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent
            {
                NotificationId = newSentNotificationId,
            };

            await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent);

            // Send a "force complete" message to the data queue with a delay to ensure that
            // the notification will be marked as complete no matter the counts
            var forceCompleteDataQueueMessageContent = new DataQueueMessageContent
            {
                NotificationId       = newSentNotificationId,
                ForceMessageComplete = true,
            };

            await this.dataQueue.SendDelayedAsync(
                forceCompleteDataQueueMessageContent,
                this.forceCompleteMessageDelayInSeconds);

            return(this.Ok());
        }
        public async Task <IActionResult> CreateSentNotificationAsync([FromBody] DraftNotification draftNotification)
        {
            var draftNotificationEntity = await this.notificationDataRepository.GetAsync(
                PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                draftNotification.Id);

            if (draftNotificationEntity == null)
            {
                return(this.NotFound());
            }

            await this.notificationDelivery.SendAsync(draftNotificationEntity);

            return(this.Ok());
        }
        public async Task <ActionResult <DraftNotification> > GetDraftNotificationByIdAsync(string id)
        {
            var notificationEntity = await this.notificationDataRepository.GetAsync(
                PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                id);

            if (notificationEntity == null)
            {
                return(this.NotFound());
            }

            // AD Groups is empty for old records.
            if (notificationEntity.ADGroups == null)
            {
                notificationEntity.ADGroups = new string[0];
            }

            var result = new DraftNotification
            {
                Id              = notificationEntity.Id,
                Title           = notificationEntity.Title,
                ImageLink       = notificationEntity.ImageLink,
                Summary         = notificationEntity.Summary,
                Author          = notificationEntity.Author,
                ButtonTitle     = notificationEntity.ButtonTitle,
                ButtonLink      = notificationEntity.ButtonLink,
                CreatedDateTime = notificationEntity.CreatedDate,
                Teams           = notificationEntity.Teams,
                Rosters         = notificationEntity.Rosters,
                ADGroups        = notificationEntity.ADGroups,
                AllUsers        = notificationEntity.AllUsers,
                ButtonTitle2    = notificationEntity.ButtonTitle2,
                ButtonLink2     = notificationEntity.ButtonLink2,
                IsScheduled     = notificationEntity.IsScheduled,
                ScheduleDate    = notificationEntity.ScheduleDate,
                IsRecurrence    = notificationEntity.IsRecurrence,
                Repeats         = notificationEntity.Repeats,
                RepeatFor       = Convert.ToInt32(notificationEntity.RepeatFor),
                RepeatFrequency = notificationEntity.RepeatFrequency,
                WeekSelection   = notificationEntity.WeekSelection,
                RepeatStartDate = notificationEntity.RepeatStartDate,
                RepeatEndDate   = notificationEntity.RepeatEndDate,
            };

            return(this.Ok(result));
        }
        public async Task CreateDraft_GrouplistHasHiddenMembership_ReturnsForbidResult()
        {
            // Arrange
            var controller = this.GetDraftNotificationsController();

            this.groupsService.Setup(x => x.ContainsHiddenMembershipAsync(It.IsAny <IEnumerable <string> >())).ReturnsAsync(true);
            var notification = new DraftNotification()
            {
                Groups = new List <string>()
            };

            // Act
            var result = await controller.CreateDraftNotificationAsync(notification);

            // Assert
            Assert.IsType <ForbidResult>(result.Result);
        }
Beispiel #11
0
        public async Task <ActionResult <string> > CreateDraftNotificationAsync([FromBody] DraftNotification notification)
        {
            if (!notification.Validate(this.localizer, out string errorMessage))
            {
                return(this.BadRequest(errorMessage));
            }

            // var containsHiddenMembership = await this.groupsService.ContainsHiddenMembershipAsync(notification.Groups);
            //   if (containsHiddenMembership)
            //  {
            //     return this.Forbid();
            //  }
            var notificationId = await this.notificationDataRepository.CreateDraftNotificationAsync(
                notification,
                this.HttpContext.User?.Identity?.Name);

            return(this.Ok(notificationId));
        }
        public async Task UpdateDraft_RoastersSizeLessThan20_ReturnsNotificationId()
        {
            // Arrange
            var controller   = this.GetDraftNotificationsController();
            var notification = new DraftNotification()
            {
                Rosters = this.GetItemsList(10), Groups = new List <string>()
            };

            this.groupsService.Setup(x => x.ContainsHiddenMembershipAsync(It.IsAny <IEnumerable <string> >())).ReturnsAsync(false);
            this.notificationDataRepository.Setup(x => x.CreateOrUpdateAsync(It.IsAny <NotificationDataEntity>())).Returns(Task.CompletedTask);

            // Act
            var result = await controller.UpdateDraftNotificationAsync(notification);

            // Assert
            Assert.IsType <OkResult>(result);
        }
        public async Task Post_ValidData_ReturnsOkObjectResult()
        {
            // Arrange
            var controller = this.GetDraftNotificationsController();

            this.groupsService.Setup(x => x.ContainsHiddenMembershipAsync(It.IsAny <IEnumerable <string> >())).ReturnsAsync(false);
            var notification = new DraftNotification()
            {
                Groups = new List <string>()
            };

            this.notificationDataRepository.Setup(x => x.CreateOrUpdateAsync(It.IsAny <NotificationDataEntity>())).Returns(Task.CompletedTask);

            // Act
            var result = await controller.CreateDraftNotificationAsync(notification);

            // Assert
            Assert.IsType <OkObjectResult>(result.Result);
        }
Beispiel #14
0
        public async Task <IActionResult> UpdateDraftNotificationAsync([FromBody] DraftNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var containsHiddenMembership = await this.groupsService.ContainsHiddenMembershipAsync(notification.Groups);

            if (containsHiddenMembership)
            {
                return(this.Forbid());
            }

            if (!notification.Validate(this.localizer, out string errorMessage))
            {
                return(this.BadRequest(errorMessage));
            }

            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey = NotificationDataTableNames.DraftNotificationsPartition,
                RowKey       = notification.Id,
                Id           = notification.Id,
                Title        = notification.Title,
                ImageLink    = notification.ImageLink,
                Summary      = notification.Summary,
                Author       = notification.Author,
                ButtonTitle  = notification.ButtonTitle,
                ButtonLink   = notification.ButtonLink,
                CreatedBy    = this.HttpContext.User?.Identity?.Name,
                CreatedDate  = DateTime.UtcNow,
                IsDraft      = true,
                Teams        = notification.Teams,
                Rosters      = notification.Rosters,
                Groups       = notification.Groups,
                AllUsers     = notification.AllUsers,
            };

            await this.notificationDataRepository.CreateOrUpdateAsync(notificationEntity);

            return(this.Ok());
        }
Beispiel #15
0
        /// <summary>
        /// Create a new draft notification.
        /// </summary>
        /// <param name="notificationRepository">The notification repository.</param>
        /// <param name="notification">Draft Notification model class instance passed in from Web API.</param>
        /// <param name="userName">Name of the user who is running the application.</param>
        /// <returns>The newly created notification's id.</returns>
        public static async Task <string> CreateDraftNotificationAsync(
            this NotificationDataRepository notificationRepository,
            DraftNotification notification,
            string userName)
        {
            var newId = notificationRepository.TableRowKeyGenerator.CreateNewKeyOrderingOldestToMostRecent();

            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey    = PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                RowKey          = newId,
                Id              = newId,
                Title           = notification.Title,
                ImageLink       = notification.ImageLink,
                Summary         = notification.Summary,
                Author          = notification.Author,
                ButtonTitle     = notification.ButtonTitle,
                ButtonLink      = notification.ButtonLink,
                ButtonTitle2    = notification.ButtonTitle2,
                ButtonLink2     = notification.ButtonLink2,
                CreatedBy       = userName,
                CreatedDate     = DateTime.UtcNow,
                IsDraft         = true,
                Teams           = notification.Teams,
                Rosters         = notification.Rosters,
                ADGroups        = notification.ADGroups,
                AllUsers        = notification.AllUsers,
                IsScheduled     = notification.IsScheduled,
                ScheduleDate    = notification.ScheduleDate,
                IsRecurrence    = notification.IsRecurrence,
                Repeats         = notification.Repeats,
                RepeatFor       = Convert.ToInt32(notification.RepeatFor),
                RepeatFrequency = notification.RepeatFrequency,
                WeekSelection   = notification.WeekSelection,
                RepeatStartDate = notification.RepeatStartDate,
                RepeatEndDate   = notification.RepeatEndDate,
            };

            await notificationRepository.CreateOrUpdateAsync(notificationEntity);

            return(newId);
        }
        public async Task UpdateDraft_GroupSizeMorethan20_ReturnsBadRequestResult()
        {
            // Arrange
            var controller = this.GetDraftNotificationsController();
            DraftNotification notification = new DraftNotification()
            {
                Groups = this.GetItemsList(21)
            };

            string warning         = "NumberOfGroupsExceededLimitWarningFormat";
            var    localizedString = new LocalizedString(warning, warning);

            this.localizer.Setup(_ => _[warning]).Returns(localizedString);

            // Act
            var result = await controller.UpdateDraftNotificationAsync(notification);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task SendNotification_NullParameter_ThrowsArgumentNullExceptioin12()
        {
            // Arrange
            var controller        = this.GetControllerInstance();
            var draftNotification = new DraftNotification()
            {
                Id = "id"
            };

            this.notificationDataRepository.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(default(NotificationDataEntity)));

            // Act
            var result = await controller.CreateSentNotificationAsync(draftNotification);

            var errorMessage = ((ObjectResult)result).Value;

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(errorMessage, $"Draft notification, Id: {draftNotification.Id}, could not be found.");
        }
        public async Task <IActionResult> CreateSentNotificationAsync(
            [FromBody] DraftNotification draftNotification)
        {
            var draftNotificationDataEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.DraftNotificationsPartition,
                draftNotification.Id);

            if (draftNotificationDataEntity == null)
            {
                return(this.NotFound($"Draft notification, Id: {draftNotification.Id}, could not be found."));
            }

            var newSentNotificationId =
                await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftNotificationDataEntity);

            // Ensure the data tables needed by the Azure Functions to send the notifications exist in Azure storage.
            await Task.WhenAll(
                this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(),
                this.sendBatchesDataRepository.EnsureSendBatchesDataTableExistsAsync());

            var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent
            {
                NotificationId = newSentNotificationId,
            };

            await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent);

            // Send a "force complete" message to the data queue with a delay to ensure that
            // the notification will be marked as complete no matter the counts
            var forceCompleteDataQueueMessageContent = new DataQueueMessageContent
            {
                NotificationId       = newSentNotificationId,
                ForceMessageComplete = true,
            };

            await this.dataQueue.SendDelayedAsync(
                forceCompleteDataQueueMessageContent,
                this.forceCompleteMessageDelayInSeconds);

            return(this.Ok());
        }
        public async Task UpdateDraft_TeamSizeMoreThan20_ReturnsBadRequestResult()
        {
            // Arrange
            var controller   = this.GetDraftNotificationsController();
            var notification = new DraftNotification()
            {
                Teams = this.GetItemsList(21), Groups = new List <string>()
            };

            this.groupsService.Setup(x => x.ContainsHiddenMembershipAsync(It.IsAny <IEnumerable <string> >())).ReturnsAsync(false);
            string warning         = "NumberOfTeamsExceededLimitWarningFormat";
            var    localizedString = new LocalizedString(warning, warning);

            this.localizer.Setup(_ => _[warning]).Returns(localizedString);

            // Act
            var result = await controller.UpdateDraftNotificationAsync(notification);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task CreateDraft_GroupSizeLessThan20_ReturnsNotificationId()
        {
            // Arrange
            var controller   = this.GetDraftNotificationsController();
            var notification = new DraftNotification()
            {
                Groups = new List <string>()
                {
                    "item1", "item2"
                }
            };

            this.groupsService.Setup(x => x.ContainsHiddenMembershipAsync(It.IsAny <IEnumerable <string> >())).ReturnsAsync(false);
            this.notificationDataRepository.Setup(x => x.CreateOrUpdateAsync(It.IsAny <NotificationDataEntity>())).Returns(Task.CompletedTask);

            // Act
            var result = await controller.CreateDraftNotificationAsync(notification);

            // Assert
            Assert.Equal(((ObjectResult)result.Result).Value, this.notificationId);
        }
        public async Task UpdateAppId_ProactiveInstallationDisabled_SetUserAppIdShouldNeverInvoked()
        {
            // Arrange
            var controller        = this.GetControllerInstance(false);
            var draftNotification = new DraftNotification()
            {
                Id = "id"
            };
            var sentNotificationId     = "notificationId";
            var notificationDataEntity = new NotificationDataEntity();

            this.notificationDataRepository.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(notificationDataEntity);
            this.notificationDataRepository.Setup(x => x.MoveDraftToSentPartitionAsync(It.IsAny <NotificationDataEntity>())).ReturnsAsync(sentNotificationId);
            this.sentNotificationDataRepository.Setup(x => x.EnsureSentNotificationDataTableExistsAsync()).Returns(Task.CompletedTask);
            this.appSettingsService.Setup(x => x.SetUserAppIdAsync(It.IsAny <string>())).Returns(Task.CompletedTask);

            // Act
            await controller.CreateSentNotificationAsync(draftNotification);

            // Assert
            this.appSettingsService.Verify(x => x.SetUserAppIdAsync(It.IsAny <string>()), Times.Never());
        }
        public async Task UpdateDraftNotificationAsync([FromBody] DraftNotification notification)
        {
            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey = PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                RowKey       = notification.Id,
                Id           = notification.Id,
                Title        = notification.Title,
                ImageLink    = notification.ImageLink,
                Summary      = notification.Summary,
                Author       = notification.Author,
                ButtonTitle  = notification.ButtonTitle,
                ButtonLink   = notification.ButtonLink,
                CreatedBy    = this.HttpContext.User?.Identity?.Name,
                CreatedDate  = DateTime.UtcNow,
                IsDraft      = true,
                Teams        = notification.Teams,
                Rosters      = notification.Rosters,
                AllUsers     = notification.AllUsers,
            };

            await this.notificationDataRepository.CreateOrUpdateAsync(notificationEntity);
        }
Beispiel #23
0
        public async Task <string> Create([FromBody] DraftNotification notification)
        {
            if (string.IsNullOrWhiteSpace(notification.Title))
            {
                return(null);
            }

            var draftNotificationId = await this.notificationDataRepository.CreateDraftNotificationAsync(
                notification,
                this.HttpContext.User?.Identity?.Name);

            var draftNotificationEntity = await this.notificationDataRepository.GetAsync(
                PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                draftNotificationId);

            if (draftNotificationEntity == null)
            {
                return(null);
            }

            await this.notificationDelivery.SendAsync(draftNotificationEntity);

            return(draftNotificationId);
        }
Beispiel #24
0
 private async Task UploadToBlobStorage(DraftNotification notification)
 {
     if (this.userAppOptions.ImageUploadBlobStorage && !string.IsNullOrWhiteSpace(notification.ImageLink))
     {
         var offset     = notification.ImageLink.IndexOf(',') + 1;
         var imageBytes = Convert.FromBase64String(notification.ImageLink[offset..^ 0]);
 public async Task <string> CreateDraftNotificationAsync([FromBody] DraftNotification notification)
 {
     return(await this.notificationDataRepository.CreateDraftNotificationAsync(
                notification,
                this.HttpContext.User?.Identity?.Name));
 }
Beispiel #26
0
        public async Task <IActionResult> UpdateSentNotificationAsync([FromBody] DraftNotification notification)
        {
            var containsHiddenMembership = await this.groupsService.ContainsHiddenMembershipAsync(notification.Groups);

            if (containsHiddenMembership)
            {
                return(this.Forbid());
            }

            if (!notification.Validate(this.localizer, out string errorMessage))
            {
                return(this.BadRequest(errorMessage));
            }

            var senttNotificationDataEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.SentNotificationsPartition,
                notification.Id);

            var updateSentNotificationDataEntity = new NotificationDataEntity
            {
                PartitionKey       = NotificationDataTableNames.SentNotificationsPartition,
                RowKey             = notification.Id,
                Id                 = notification.Id,
                Channel            = notification.Channel,
                TemplateID         = notification.TemplateID,
                Title              = notification.Title,
                ImageLink          = notification.ImageLink,
                Summary            = notification.Summary,
                Author             = notification.Author,
                ButtonTitle        = notification.ButtonTitle,
                ButtonLink         = notification.ButtonLink,
                CreatedBy          = this.HttpContext.User?.Identity?.Name,
                CreatedDate        = DateTime.UtcNow,
                SentDate           = DateTime.UtcNow,
                Edited             = DateTime.UtcNow,
                IsDraft            = false,
                Teams              = notification.Teams,
                Rosters            = notification.Rosters,
                Groups             = notification.Groups,
                AllUsers           = notification.AllUsers,
                MessageVersion     = senttNotificationDataEntity.MessageVersion,
                Succeeded          = senttNotificationDataEntity.Succeeded,
                Failed             = 0,
                Throttled          = 0,
                TotalMessageCount  = senttNotificationDataEntity.TotalMessageCount,
                SendingStartedDate = DateTime.UtcNow,
                Status             = NotificationStatus.Sent.ToString(),
            };
            var id = updateSentNotificationDataEntity.Id;
            var sentNotificationId = await this.notificationDataRepository.UpdateSentNotificationAsync(updateSentNotificationDataEntity, id);

            await this.sentNotificationUpdateDataRepository.EnsureSentNotificationDataTableExistsAsync();

            var sendQueueMessageContent = new SendQueueMessageContent
            {
                NotificationId = sentNotificationId,
                ActivtiyId     = null,
                RecipientData  = null,
                NotificationUpdatePreviewEntity = new NotificationUpdatePreviewEntity
                {
                    ActionType             = "EditNotification",
                    NotificationDataEntity = updateSentNotificationDataEntity,
                    ConversationReferance  = null,
                    MessageActivity        = null,
                    ServiceUrl             = null,
                    AppID = null,
                },
            };

            await this.sendQueue.SendAsync(sendQueueMessageContent);

            return(this.Ok());
        }