Exemplo n.º 1
0
        public async Task <IActionResult> ExportNotificationAsync(
            [FromBody] ExportRequest exportRequest)
        {
            if (exportRequest == null)
            {
                throw new ArgumentNullException(nameof(exportRequest));
            }

            var userId = this.HttpContext.User.FindFirstValue(Common.Constants.ClaimTypeUserId);
            var user   = await this.userDataRepository.GetAsync(UserDataTableNames.AuthorDataPartition, userId);

            if (user == null)
            {
                await this.SyncAuthorAsync(exportRequest.TeamId, userId);
            }

            // Ensure the data tables needed by the Azure Function to export the notification exist in Azure storage.
            await Task.WhenAll(
                this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(),
                this.exportDataRepository.EnsureExportDataTableExistsAsync());

            var exportNotification = await this.exportDataRepository.GetAsync(userId, exportRequest.Id);

            if (exportNotification != null)
            {
                return(this.Conflict());
            }

            await this.exportDataRepository.CreateOrUpdateAsync(new ExportDataEntity()
            {
                PartitionKey = userId,
                RowKey       = exportRequest.Id,
                SentDate     = DateTime.UtcNow,
                Status       = ExportStatus.New.ToString(),
            });

            var exportQueueMessageContent = new ExportQueueMessageContent
            {
                NotificationId = exportRequest.Id,
                UserId         = userId,
            };

            await this.exportQueue.SendAsync(exportQueueMessageContent);

            return(this.Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ExportNotificationAsync(string id)
        {
            var userId = this.HttpContext.User.FindFirstValue(Common.Constants.ClaimTypeUserId);
            var user   = await this.userDataRepository.GetAsync(UserDataTableNames.UserDataPartition, userId);

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

            // Ensure the data tables needed by the Azure Function to export the notification exist in Azure storage.
            await Task.WhenAll(
                this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(),
                this.exportDataRepository.EnsureExportDataTableExistsAsync());

            var exportNotification = await this.exportDataRepository.GetAsync(userId, id);

            if (exportNotification != null)
            {
                return(this.Conflict());
            }

            await this.exportDataRepository.CreateOrUpdateAsync(new ExportDataEntity()
            {
                PartitionKey = userId,
                RowKey       = id,
                SentDate     = DateTime.UtcNow,
                Status       = ExportStatus.New.ToString(),
            });

            var exportQueueMessageContent = new ExportQueueMessageContent
            {
                NotificationId = id,
                UserId         = userId,
            };

            await this.exportQueue.SendAsync(exportQueueMessageContent);

            return(this.Ok());
        }
        public async Task <IActionResult> ExportNotificationAsync(
            [FromBody] ExportRequest exportRequest)
        {
            var authorizedCreatorUpns = this.configuration["AuthorizedCreatorUpns"];

            // var authorizedCreatorUpns = "homerun1 @nao365competency.onmicrosoft.com";
            string[] superAdminsArray = authorizedCreatorUpns.Split(",");
            var      superAdmins      = string.Join(",", superAdminsArray).ToLower();

            this.loggedinUser = this.HttpContext.User?.Identity?.Name;
            var sLoggedin = string.Empty + this.loggedinUser;

            this.loggedinUser = sLoggedin.ToLower();

            var userType = superAdmins.Contains(this.loggedinUser) ? "superAdmin" : "admin";
            var userId   = this.HttpContext.User.FindFirstValue(Common.Constants.ClaimTypeUserId);
            var user     = await this.userDataRepository.GetAsync(UserDataTableNames.AuthorDataPartition, userId);

            // Moved this logic to Function App
            // if (user == null)
            // {
            //   await this.SyncAuthorAsync(exportRequest.TeamId, userId);
            // }

            // Ensure the data tables needed by the Azure Function to export the notification exist in Azure storage.
            await Task.WhenAll(
                this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(),
                this.exportDataRepository.EnsureExportDataTableExistsAsync());

            var exportNotification = await this.exportDataRepository.GetAsync(userId, exportRequest.Id);

            if (exportNotification != null)
            {
                return(this.Conflict());
            }
            var exportType = "ExportSingleNotifications";

            if (exportRequest.Id == "dummy")
            {
                exportRequest.Id = Guid.NewGuid().ToString();
                exportType       = "ExportAllNotifications";
            }

            await this.exportDataRepository.CreateOrUpdateAsync(new ExportDataEntity()
            {
                PartitionKey      = userId,
                RowKey            = exportRequest.Id,
                SentDate          = DateTime.UtcNow,
                Status            = ExportStatus.New.ToString(),
                ExportType        = exportType,
                UserType          = userType,
                RequestedTeamId   = exportRequest.TeamId,
                LoggedinUserEmail = this.loggedinUser,
            });

            var exportQueueMessageContent = new ExportQueueMessageContent
            {
                NotificationId = exportRequest.Id,
                UserId         = userId,
            };

            await this.exportQueue.SendAsync(exportQueueMessageContent);

            return(this.Ok());
        }