private CustomFileDetails GetTemplatedLicenseForDownload(OrganizationLicense license, int orgId, string urlToSchema)
        {
            var result = new CustomFileDetails();

            // Get license template
            var template = _licenseTemplates.FirstOrDefault(i => i.ID == license.LicenseTemplateID.Value);

            // Get license document
            var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: license.ID);

            // Get schema file
            var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID);

            // Build content for templated license
            _licenseContentBuilder.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost,
                                                        orgId, license.ProviderEndpointID != 0);

            // Generate pdf file with content
            var pdfDocument = new HtmlToPdfConverter {
                PageFooterHtml = _licenseContentBuilder.GetFooterText(license.Status, _config.DataLinkerHost)
            };
            var bytes = pdfDocument.GeneratePdf(licenseDocument.OuterXml);

            // Setup result
            result.Content  = bytes;
            result.MimeType = "application/pdf";
            result.FileName = $"{template.Name}.pdf";

            // Return result
            return(result);
        }
Beispiel #2
0
        private string GetLicenseContent(OrganizationLicense licenseToProceed, int organisationId, OrganisationLicenseType type)
        {
            // Define result
            var result = string.Empty;
            OrganizationLicense license = licenseToProceed;

            // Check whether license is for consumer
            if (licenseToProceed.ProviderEndpointID == 0)
            {
                // Get license match
                var licenseMatch = _licenseMatches.FirstOrDefault(i => i.ConsumerLicenseID == licenseToProceed.ID);
                // Use provider license for generating content
                license = _orgLicenses.GetById(licenseMatch.ProviderLicenseID);
            }

            // Setup license content for license type
            switch (type)
            {
            case OrganisationLicenseType.FromTemplate:
            {
                // Get schema file
                var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID);

                // Setup url to schema
                var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID);

                // Get content for license
                var licenseDocument = _licenseContent.GetLicenseContent(organizationLicenseId: license.ID);

                // Setup license content with details
                _licenseContent.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost, organisationId, license.ProviderEndpointID != 0);

                result = licenseDocument.OuterXml;
                break;
            }

            case OrganisationLicenseType.Custom:
            {
                // Get content for license
                var urlToDownloadLicese = _urls.ToDownloadLicense(license.ApplicationID, license.DataSchemaID, license.ID);
                result = urlToDownloadLicese;
                break;
            }
            }

            // return result
            return(result);
        }
Beispiel #3
0
        public void LicenseIsPendingApproval(int userId,
                                             string linkToConfirmScreen,
                                             string linkToSchema,
                                             string linkToDataLinker,
                                             string schemaName,
                                             int licenseId)
        {
            var license         = _licenseService.FirstOrDefault(i => i.ID == licenseId);
            var application     = _applicationService.FirstOrDefault(i => i.ID == license.ApplicationID);
            var organization    = _organizationService.FirstOrDefault(i => i.ID == application.OrganizationID);
            var template        = _licenseTemplateService.FirstOrDefault(i => i.ID == license.LicenseTemplateID.Value);
            var licenseDocument = _licenseContentBuilder.GetLicenseContent(license.ID);

            _licenseContentBuilder.InsertLicenseDetails(licenseDocument, linkToSchema, linkToDataLinker, organization.ID, application.IsProvider);
            var pdfDocument = new HtmlToPdfConverter {
                PageFooterHtml = _licenseContentBuilder.GetFooterText(license.Status, linkToDataLinker)
            };
            var pdfBytes   = pdfDocument.GeneratePdf(licenseDocument.OuterXml);
            var stream     = new MemoryStream(pdfBytes);
            var attachment = new List <Attachment>
            {
                new Attachment(stream, $"{template.Name}{MailFileFormat}",
                               MediaTypeNames.Application.Pdf)
            };

            var user = _userService.FirstOrDefault(i => i.ID == userId);

            if (user != null)
            {
                var email = new LegalOfficerVerificationLicenseEmail
                {
                    To   = user.Email,
                    From = _emailSettings.SmtpFromEmail,
                    Name = user.Name,
                    LinkToConfirmationScreen = linkToConfirmScreen,
                    OrganizationName         = organization.Name,
                    SchemaName  = schemaName,
                    IsProvider  = application.IsProvider,
                    Attachments = attachment
                };

                Send(email);
            }
        }
        public LegalApprovalModel GetLegalApprovalModel(string token, LoggedInUserDetails user)
        {
            _security.CheckBasicAccess(user);
            var tokenInfo = _tokens.ParseConsumerProviderRegistrationToken(token);


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

            if (request == null)
            {
                throw new BaseException("Access denied. Request token does not exist.");
            }

            if (request.SentTo != user.ID.Value)
            {
                throw new BaseException("Access denied. Invalid user.");
            }

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

            if (!IsLegalOfficer(user))
            {
                throw new BaseException("Access denied. Not a legal officer.");
            }

            // 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.");
            }

            // Get license
            var license = _licenseService.FirstOrDefault(p => p.ID == tokenInfo.ID.Value);

            // Get license type whether it is custom or default.
            var licenseType = license.CustomLicenseID != null ? OrganisationLicenseType.Custom : OrganisationLicenseType.FromTemplate;
            var result      = string.Empty;
            // Get organisation details
            var organization = _organisations.FirstOrDefault(i => i.ID == user.Organization.ID);

            switch (licenseType)
            {
            case OrganisationLicenseType.FromTemplate:
            {
                // Get schema file
                var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID);

                // Setup url to schema
                var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID);

                // Get content for license
                var licenseDocument = _licenseContent.GetLicenseContent(organizationLicenseId: license.ID);

                // Setup license content with details
                _licenseContent.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost, organization.ID, license.ProviderEndpointID != 0);

                result = licenseDocument.OuterXml;
                break;
            }

            case OrganisationLicenseType.Custom:
            {
                // Get content for license
                var urlToDownloadLicese = _urls.ToDownloadLicense(license.ApplicationID, license.DataSchemaID, license.ID);
                result = urlToDownloadLicese;
                break;
            }
            }

            // Always expire request
            if (request != null)
            {
                request.ExpiresAt = DateTime.UtcNow;
                _verificationRequests.Update(request);
            }

            var legalApprovalModel = new LegalApprovalModel
            {
                ConsumerProviderRegistrationID = tokenInfo.ConsumerProviderRegistrationId.Value,
                LicenseContent = result,
                Type           = licenseType
            };

            return(legalApprovalModel);
        }