private void SendNotificationToLegalOfficers(OrganizationLicense license, List <User> legalOfficers, string schemaName, string urlToSchema, LoggedInUserDetails user)
        {
            // Send notification to legal officers
            foreach (var legalOfficer in legalOfficers)
            {
                // Generate secure token
                var tokenInfo = _tokens.GenerateLicenseVerificationToken(legalOfficer.ID, license.ID);

                // Create approval request
                var request = new LicenseApprovalRequest
                {
                    accessToken           = tokenInfo.TokenInfoEncoded,
                    Token                 = tokenInfo.Token,
                    ExpiresAt             = tokenInfo.TokenExpire.Value,
                    OrganizationLicenseID = license.ID,
                    SentAt                = GetDate,
                    SentBy                = user.ID.Value,
                    SentTo                = legalOfficer.ID
                };

                // Save request
                _verificationRequests.Add(request);

                // Setup url to confirmation screen
                var urlToConfirmScreen = _urls.ToLicenseVerification(license.ApplicationID, license.DataSchemaID, tokenInfo.TokenInfoEncoded);

                // Send notificaion to legal officer with templated license
                if (license.LicenseTemplateID != null)
                {
                    // Send notification
                    _notificationService.LegalOfficer.LicenseIsPendingApprovalInBackground(legalOfficer.ID, $"{urlToConfirmScreen}#Clauses",
                                                                                           urlToSchema, _config.DataLinkerHost, schemaName, license.ID);
                }

                // Send notificaion to legal officer with custom license
                if (license.CustomLicenseID != null)
                {
                    // Send notification
                    _notificationService.LegalOfficer.LicenseVerificationRequiredInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName,
                                                                                              license.ID);
                }
            }
        }
        private void SendNotificationToLegalOfficers(OrganizationLicense license, int consumerProviderRegistrationId, List <User> legalOfficers, string schemaName, string urlToSchema, LoggedInUserDetails user, bool toProviderLegal)
        {
            // Send notification to legal officers
            foreach (var legalOfficer in legalOfficers)
            {
                // Generate secure token
                //var tokenInfo = _tokens.GenerateLicenseVerificationToken(legalOfficer.ID, license.ID);
                var tokenInfo = _tokens.GenerateConsumerProviderRegistrationToken(legalOfficer.ID, license.ID, consumerProviderRegistrationId);

                // Create approval request
                var request = new LicenseApprovalRequest
                {
                    accessToken           = tokenInfo.TokenInfoEncoded,
                    Token                 = tokenInfo.Token,
                    ExpiresAt             = tokenInfo.TokenExpire.Value,
                    OrganizationLicenseID = license.ID,
                    SentAt                = DateTime.UtcNow,
                    SentBy                = user.ID.Value,
                    SentTo                = legalOfficer.ID
                };

                // Save request
                _verificationRequests.Add(request);

                // Setup url to confirmation screen
                // var urlToConfirmScreen = _urls.ToLicenseVerification(license.ApplicationID, license.DataSchemaID, tokenInfo.TokenInfoEncoded);
                var urlToConfirmScreen = $"{_config.DataLinkerHost}/consumer-provider-registration/{consumerProviderRegistrationId}/consumer-legal-approval?token={tokenInfo.TokenInfoEncoded}";
                if (toProviderLegal)
                {
                    urlToConfirmScreen = $"{_config.DataLinkerHost}/consumer-provider-registration/{consumerProviderRegistrationId}/provider-legal-approval?token={tokenInfo.TokenInfoEncoded}";
                }

                if (license.LicenseTemplateID != null)
                {
                    urlToConfirmScreen = $"{urlToConfirmScreen}#Clauses";
                }

                // Send notificaion to legal officer with templated license
                //if (license.LicenseTemplateID != null)
                //{
                if (toProviderLegal)
                {
                    _notificationService.ConsumerProviderRegistration.ProviderLegalApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, urlToSchema, _config.DataLinkerHost, schemaName, consumerProviderRegistrationId);
                }
                else
                {
                    _notificationService.ConsumerProviderRegistration.ConsumerLegalApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, urlToSchema, _config.DataLinkerHost, schemaName, consumerProviderRegistrationId);
                }

                //}

                //// Send notificaion to legal officer with custom license
                //if (license.CustomLicenseID != null)
                //{
                //    if(toProviderLegal)
                //    {
                //        _notificationService.ConsumerProviderRegistration.ProviderLegalCustomLicenseApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName, license.ID);
                //    }
                //    else
                //    {
                //        _notificationService.ConsumerProviderRegistration.ConsumerLegalCustomLicenseApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName, license.ID);
                //    }
                //}
            }
        }
Beispiel #3
0
        public LicenseConfirmModel GetConfirmModel(string token, LoggedInUserDetails user)
        {
            OrganizationLicense    license = null;
            LicenseApprovalRequest request = null;

            try
            {
                // Check access
                _security.CheckBasicAccess(user);

                // Process token
                var tokenInfo = _tokens.ParseLicenseVerificationToken(token);

                // Get license
                license = _orgLicenses.FirstOrDefault(i => i.ID == tokenInfo.ID.Value);

                // Get request
                request = _verificationRequests.FirstOrDefault(i => i.Token == tokenInfo.Token);

                // Check whether token exists
                if (request == null)
                {
                    throw new BaseException("Access denied.");
                }

                // Check whether token belongs to user
                if (request.SentTo != user.ID.Value)
                {
                    request.ExpiresAt = GetDate;
                    _verificationRequests.Update(request);
                    throw new BaseException("Access denied.");
                }

                // Check whether token expired
                if (request.ExpiresAt != tokenInfo.TokenExpire || request.ExpiresAt < DateTime.Now)
                {
                    throw new BaseException(
                              "Approval link is expired.");
                }

                // Check whether user is Legal officer for organisation
                CheckForLegalOfficer(user);

                // Check whether organisation is active
                if (!user.Organization.IsActive)
                {
                    throw new BaseException(
                              "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker team.");
                }

                // Check whether licese is pending approval
                if (license.Status != (int)PublishStatus.PendingApproval)
                {
                    throw new BaseException("This license is not pending approval.");
                }

                // Get organisation details
                var organization = _organisations.FirstOrDefault(i => i.ID == user.Organization.ID);

                // Determine license type
                var type = GetType(license);

                // Get content for license
                var licenseContent = GetLicenseContent(license, organization.ID, type);

                // Setup result
                var result = new LicenseConfirmModel
                {
                    OrganizationName = organization.Name,
                    ID             = license.ID,
                    LicenseContent = licenseContent,
                    Type           = type,
                    IsProvider     = license.ProviderEndpointID != 0
                };

                // Return result
                return(result);
            }
            catch (BaseException)
            {
                // Set license status to draft
                if (license != null && license.Status == (int)PublishStatus.PendingApproval)
                {
                    license.Status = (int)PublishStatus.Draft;
                    _orgLicenses.Update(license);
                }
                throw;
            }
            finally
            {
                // Always expire request
                if (request != null)
                {
                    request.ExpiresAt = GetDate;
                    _verificationRequests.Update(request);
                }
            }
        }