Ejemplo n.º 1
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 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);
        }