/// <summary> /// Sends the invite. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="component">The component.</param> /// <param name="document">The document.</param> /// <param name="person">The person.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private bool SendInvite(RockContext rockContext, DigitalSignatureComponent component, SignatureDocument document, Person person, out List <string> errors) { errors = new List <string>(); if (document != null && document.SignatureDocumentTemplate != null && document.SignatureDocumentTemplate.InviteSystemCommunicationId.HasValue && person != null && !string.IsNullOrWhiteSpace(person.Email)) { string inviteLink = component.GetInviteLink(document, person, out errors); if (!errors.Any()) { var systemEmail = new SystemCommunicationService(rockContext).Get(document.SignatureDocumentTemplate.InviteSystemCommunicationId.Value); if (systemEmail != null) { var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, person); mergeFields.Add("SignatureDocument", document); mergeFields.Add("InviteLink", inviteLink); var emailMessage = new RockEmailMessage(systemEmail); emailMessage.AddRecipient(new RockEmailMessageRecipient(person, mergeFields)); emailMessage.Send(); } } else { return(false); } } return(true); }
/// <summary> /// Returns a queryable of <see cref="Rock.Model.Communication"/> where the <paramref name="person"/> is authorized /// to <see cref="Rock.Security.Authorization.VIEW">view</see> the communication. /// This is based on the VIEW auth of the <see cref="Rock.Model.CommunicationTemplate"/> and/or <see cref="Rock.Model.SystemCommunication"/> that /// is associated with each communication. /// </summary> /// <param name="qryCommunications">The qry communications.</param> /// <param name="rockContext">The rock context.</param> /// <param name="person">The person.</param> /// <returns>IQueryable<Communication>.</returns> public static IQueryable <Communication> WherePersonAuthorizedToView(this IQueryable <Communication> qryCommunications, RockContext rockContext, Person person) { // We want to limit to only communications that they are authorized to view, but if there are a large number of communications, that could be very slow. // So, since communication security is based on CommunicationTemplate or SystemCommunication, take a shortcut and just limit based on // authorized CommunicationTemplates and authorized SystemCommunications var authorizedCommunicationTemplateIds = new CommunicationTemplateService(rockContext).Queryable() .Where(a => qryCommunications.Any(x => x.CommunicationTemplateId.HasValue && x.CommunicationTemplateId == a.Id)) .ToList().Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, person)).Select(a => a.Id).ToList(); var authorizedSystemCommunicationIds = new SystemCommunicationService(rockContext).Queryable() .Where(a => qryCommunications.Any(x => x.SystemCommunicationId.HasValue && a.Id == x.SystemCommunicationId)) .ToList().Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, person)).Select(a => a.Id).ToList(); return(qryCommunications.Where(a => (a.CommunicationTemplateId == null || authorizedCommunicationTemplateIds.Contains(a.CommunicationTemplateId.Value)) && (a.SystemCommunicationId == null || authorizedSystemCommunicationIds.Contains(a.SystemCommunicationId.Value)) )); }