Beispiel #1
0
        public async Task <BulkInviteSubmission> SendBulkInvitations(BulkInviteSubmission bulkRequest)
        {
            if (!User.Identity.IsInRole(Roles.CompanyAdministrator))
            {
                //enforcing rule: only Company Administrator can invite Members
                bulkRequest.MemberType = MemberType.Guest;
            }

            bulkRequest.InvitationMessage = HtmlSanitizer.SanitizeHtml(bulkRequest.InvitationMessage);
            bulkRequest.SubmissionDate    = DateTime.UtcNow;

            //this call adds the batch to the DB and creates a pending item for each guest
            bulkRequest = await BulkInviteSubmission.AddItem(bulkRequest, User.Identity.Name);

            string userOid = User.Identity.GetClaim(Settings.ObjectIdentifier);

            //queue the request for processing
            var queue = new BatchQueueItem
            {
                BulkInviteSubmissionId = bulkRequest.Id,
                InvitingUserId         = userOid,
                ProfileUrl             = Utils.GetProfileUrl(Request.RequestUri),
                UserSourceHostName     = Utils.GetFQDN(Request)
            };

            StorageRepo.AddQueueItem(queue, "invitations");

            return(bulkRequest);
        }
Beispiel #2
0
        public async Task <BulkInviteResults> BulkInvitations(string BulkInviteSubmissionId)
        {
            var res = new BulkInviteResults(BulkInviteSubmissionId);

            try
            {
                var batch = await BulkInviteSubmission.GetItem(BulkInviteSubmissionId);

                if (batch == null)
                {
                    return(new BulkInviteResults
                    {
                        ErrorMessage = "Batch not found."
                    });
                }
                if (batch.StopProcessing)
                {
                    return(new BulkInviteResults
                    {
                        ErrorMessage = "Batch was flagged to discontinue processing."
                    });
                }
                res = await ProcessBulkInvitations(batch);

                return(res);
            }
            catch (Exception ex)
            {
                var msg = "Error processing bulk invitation";
                res.ErrorMessage = Logging.WriteToAppLog(msg, System.Diagnostics.EventLogEntryType.Error, ex);
                await BulkInviteResults.AddItem(res);

                return(res);
            }
        }
Beispiel #3
0
        public async Task <HttpResponseMessage> DeleteQueuedRequest(dynamic data)
        {
            var id = data.id.ToString();
            await BulkInviteSubmission.DeleteBatch(id);

            return(new HttpResponseMessage(HttpStatusCode.Accepted));
        }
Beispiel #4
0
 public async Task <BatchDTO> GetBatchItem(string id)
 {
     return(new BatchDTO
     {
         Submission = await BulkInviteSubmission.GetItem(id),
         BatchResults = await BulkInviteResults.GetItems(id)
     });
 }
Beispiel #5
0
        public async Task <IEnumerable <BulkInviteSubmission> > GetBatchHistory(int daysHistory = 20)
        {
            IEnumerable <BulkInviteSubmission> res = null;

            try
            {
                res = (await BulkInviteSubmission.GetItemHistory(daysHistory)).OrderByDescending(c => c.SubmissionDate);
            }
            catch (Exception)
            {
                //see if this domain needs the group object updated
                res = await BulkInviteSubmission.RefreshAllPreAuthGroupData(daysHistory);
            }

            return(res);
        }
Beispiel #6
0
        public async Task <StatusDTO> GetBulkItemStatus()
        {
            var submissionId = Request.GetQueryNameValuePairs().Single(s => s.Key == "submissionId").Value;
            var email        = Request.GetQueryNameValuePairs().Single(s => s.Key == "email").Value;

            var request = await BulkInviteSubmission.GetGuestItemDetail(submissionId, email);

            var result = (await DocDBRepo.DB <BulkInviteResults> .GetItemsAsync(d => d.SubmissionId == submissionId)).SingleOrDefault();

            var response = result.InvitationResults.Responses.SingleOrDefault(r => r.Body.InvitedUserEmailAddress == email);

            return(new StatusDTO
            {
                Request = request,
                Response = response
            });
        }
Beispiel #7
0
        //private BulkInviteResults SubmitToGraphBatch(GraphBatch batch, BulkInviteSubmission submission)
        //{
        //    //** NOTE: this method was last tested against the beta API, circa Q3 CY17 **
        //    var res = new BulkInviteResults();
        //    var batchEndPoint = string.Format("{0}/beta/$batch", Settings.GraphResource);
        //    var serverResponse = CallGraph(batchEndPoint, batch, false, null, _userId);

        //    if (serverResponse.Successful)
        //    {
        //        res.InvitationResults = JsonConvert.DeserializeObject<GraphBatchResponse>(serverResponse.ResponseContent);
        //        if (submission.GroupList.Length > 0)
        //        {
        //            foreach (var item in res.InvitationResults.Responses)
        //            {
        //                var groupsAdded = AddUserToGroup(item.Body.InvitedUser.Id, submission.GroupList.ToList());
        //                if (!groupsAdded.Success)
        //                {
        //                    var resErrors = string.Join(", ", groupsAdded.Responses.Where(r => !r.Successful).Select(r => r.Message));
        //                    res.ErrorMessage += string.Format("\n\rOne or more groups failed while assigning to user \"{0}\" ({1})", item.Body.InvitedUserEmailAddress, resErrors);
        //                }
        //            }
        //        }
        //    }
        //    else
        //    {
        //        res.ErrorMessage = serverResponse.Message;
        //    }
        //    return res;
        //}

        private async Task <BulkInviteResults> SubmitLocally(GraphBatch batch, BulkInviteSubmission submission)
        {
            var res = new BulkInviteResults(submission.Id);

            GraphInvitation itemRes;
            var             mailTemplate = await TemplateUtilities.GetTemplate(submission.InviteTemplateId);

            try
            {
                foreach (var item in batch.Requests)
                {
                    itemRes = await SendGraphInvitationAsync(item.Body, submission.GroupList.ToList(), null, mailTemplate, _accessToken);

                    if (itemRes.Status != "Error")
                    {
                        submission.ItemsProcessed += 1;
                        submission = await BulkInviteSubmission.UpdateItem(submission);
                    }
                    item.Request.Status = itemRes.Status;
                    await GuestRequestRules.UpdateAsync(item.Request);

                    res.InvitationResults.Responses.Add(new BulkResponse
                    {
                        Status = itemRes.Status,
                        Body   = itemRes,
                        Id     = itemRes.id
                    });
                }

                await BulkInviteResults.AddItem(res);

                return(res);
            }
            catch (Exception ex)
            {
                res.ErrorMessage = ex.Message;
                await BulkInviteResults.AddItem(res);

                return(res);
            }
        }
Beispiel #8
0
        public async Task <BulkInviteResults> ProcessBulkInvitations(BulkInviteSubmission submission)
        {
            var res = new BulkInviteResults(submission.Id);

            try
            {
                var batch          = new GraphBatch();
                int counter        = 0;
                var inviteEndPoint = string.Format("/{0}/invitations", Settings.GraphApiVersion);
                var headerColl     = new Dictionary <string, string>
                {
                    { "Content-Type", "application/json" }
                };

                var items = await BulkInviteSubmission.GetGuestRequestsPending(submission.Id);

                foreach (var item in items)
                {
                    counter++;
                    // Setup invitation
                    GraphInvitation invitation = new GraphInvitation()
                    {
                        InvitedUserDisplayName  = item.EmailAddress,
                        InvitedUserEmailAddress = item.EmailAddress,
                        InviteRedirectUrl       = _profileUrl,
                        SendInvitationMessage   = (!Settings.UseSMTP),
                        InvitedUserType         = submission.MemberType.ToString()
                    };

                    if (submission.InvitationMessage.Length > 0)
                    {
                        invitation.InvitedUserMessageInfo = new InvitedUserMessageInfo
                        {
                            CustomizedMessageBody = submission.InvitationMessage
                        };
                    }

                    batch.Requests.Add(new BulkInviteRequest
                    {
                        Id             = counter.ToString(),
                        GuestRequestId = item.Id,
                        Request        = item,
                        Method         = "POST",
                        Headers        = headerColl,
                        Url            = inviteEndPoint,
                        Body           = invitation
                    });
                }

                /* NOTE:
                 * This process is designed to leverage the Microsoft Graph batch processor:
                 *     https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching
                 * However, the batch processor is currently (2018) in preview and limited to 20 submissions per request
                 * For the time being, we'll loop the collection and make individual synchronous calls
                 */
                //res = SubmitToGraphBatch(batch, submission, userId);

                res = await SubmitLocally(batch, submission);


                return(res);
            }
            catch (Exception ex)
            {
                var msg = "Error processing bulk invitation";
                res.ErrorMessage = Logging.WriteToAppLog(msg, System.Diagnostics.EventLogEntryType.Error, ex);
                await BulkInviteResults.AddItem(res);

                return(res);
            }
        }
Beispiel #9
0
 public async Task <IEnumerable <BulkInviteSubmission> > GetBatchPending()
 {
     return((await BulkInviteSubmission.GetItemsPending()).OrderByDescending(c => c.SubmissionDate));
 }
Beispiel #10
0
        public async Task <IEnumerable <BulkInviteSubmission> > GetBulkProcessingStatus()
        {
            var batches = (await BulkInviteSubmission.GetItemsPending()).OrderByDescending(c => c.SubmissionDate);

            return(batches);
        }