Beispiel #1
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);
            }
        }
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);
        }
        public CustomFileDetails GetAgreement(int agreementId, LoggedInUserDetails user)
        {
            // Get agreements
            var agreement = _agreements.FirstOrDefault(i => i.ID == agreementId);

            // Return error if data not found
            if (agreement == null)
            {
                throw new BaseException("License Agreement not found");
            }

            // Check whether user has access
            _security.CheckBasicAccess(user);

            var consumerRegistration      = _consumerProviderRegistrations.GetById(agreement.ConsumerProviderRegistrationId);
            var providerLicense           = _licenses.FirstOrDefault(i => i.ID == consumerRegistration.OrganizationLicenseID);
            var consumerApp               = _applications.FirstOrDefault(i => i.ID == consumerRegistration.ConsumerApplicationID);
            var providerApp               = _applications.FirstOrDefault(i => i.ID == providerLicense.ApplicationID);
            var isFromConsumerSide        = user.Organization.ID == consumerApp.OrganizationID;
            var isFromProviderSide        = user.Organization.ID == providerApp.OrganizationID;
            var isFromAllowedOrganization = isFromProviderSide || isFromConsumerSide;

            // Return error if not access to data
            if (!user.IsSysAdmin && !isFromAllowedOrganization)
            {
                throw new BaseException("Access denied.");
            }

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

            // Get provider licese
            if (providerLicense.CustomLicenseID != null)
            {
                // Get uploaded by provider file
                var customLicenseResult = GetCustomLicenseForDownload(providerLicense.CustomLicenseID.Value);

                // Return custom license result
                return(customLicenseResult);
            }

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

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

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

            // Setup license content
            var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: providerLicense.ID);

            // Insert provider details
            _licenseContentBuilder.InsertAgreementDetails(licenseDocument, agreement.ID, urlToSchema, _config.DataLinkerHost);

            // Get butes for generated pdf
            var bytes = new HtmlToPdfConverter().GeneratePdf(licenseDocument.OuterXml);

            var result = new CustomFileDetails
            {
                Content  = bytes,
                FileName = template.Name + ".pdf",
                MimeType = "application/pdf"
            };

            return(result);
        }
        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);
        }