public async Task <IHttpActionResult> GetByLinkAsync(string link, CancellationToken cancellationToken) { var actionLink = _actionLinkService.DecodeLink(link); var action = await _projectManager.GetActionByIdAsync(actionLink.ActionId, cancellationToken); var contact = actionLink.ContactId != null ? await _projectManager.GetContactByIdAsync((int)actionLink.ContactId, ContactField.None, cancellationToken) : null; await ApiSecurity.AuthorizeAsync(AccessObjectType.Project, action.Project.Id, AccessPermission.CanView, cancellationToken); return(new ActionLinkContentResult(_actionLinkService, action, contact, actionLink.CustomUri, this)); }
/// <summary> /// Asynchronously sends invitation to each of the users specified. /// </summary> private async Task InviteAsync( ActionLink actionLink, AuthTicket authTicket, ContactItem contact, WorkflowInvitationDto model, CancellationToken cancellationToken) { if (actionLink == null) { throw new ArgumentNullException(nameof(actionLink)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } if (model.Action == null) { throw new InvalidOperationException("An action link with the given ID was not found."); } if (model.To == null || model.To.Length == 0) { throw new InvalidOperationException("At least one person is required for invitation."); } var invActionLinkParams = _actionLinkService.DecodeLink(model.Action); var action = await _projectManager.GetActionByIdAsync(invActionLinkParams.ActionId, cancellationToken); if (action == null) { throw new InvalidOperationException($"The specified action link was not found: {invActionLinkParams.ToString()}"); } var project = await _projectManager.FindByIdAsync(action.Project.Id, cancellationToken); var context = Request.Properties["MS_HttpContext"] as HttpContextWrapper; var logEvent = context.Request.CreateEvent(); var invitation = new ProjectInvitation { From = contact, Message = model.Message, To = model.To.Select(c => c.ToContact()) }; var properties = new PropertyDictionary { { "Invitation", invitation } }; foreach (var to in invitation.To.Where(to => to != null)) { var eventItem = new EventItem { AnonymId = logEvent.AnonymId, Project = project, ClientId = logEvent.ClientId, CustomUri = actionLink.CustomUri, BrowserBrand = logEvent.BrowserBrand, BrowserVersion = logEvent.BrowserVersion, MobileDevice = logEvent.MobileDevice, ReferrerUrl = logEvent.ReferrerUrl }; await _workflowInvoker.InvokeAsync(new ActionActivityContext( project : project, action : action, authTicket : authTicket, contact : to, contactState : ObjectState.Unchanged, properties : properties, eventItem : eventItem), cancellationToken); } }