Beispiel #1
0
        public void Approve(int licenseId, string urlToLicenses, LoggedInUserDetails user)
        {
            // Check access
            var checkResult = CheckAccess(licenseId, user);

            // Setup license details
            checkResult.License.ApprovedAt = GetDate;
            checkResult.License.ApprovedBy = user.ID;
            checkResult.License.Status     = (int)PublishStatus.ReadyToPublish;
            _orgLicenses.Update(checkResult.License);

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

            // Get schema
            var schema = _dataSchemas.FirstOrDefault(i => i.ID == checkResult.License.DataSchemaID);

            var isProvider = checkResult.License.ProviderEndpointID != 0;

            // Notify user, who made an approval request
            _notifications.User.StatusForLicenseUpdatedInBackground(checkResult.VerificationRequest.SentBy,
                                                                    urlToLicenses, schema.Name, organizaiton.Name, isProvider, checkResult.License.Status);

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

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

            // Notify legal officer about approved license
            _notifications.LegalOfficer.LicenseApprovedSuccessfullyInBackground(user.ID.Value,
                                                                                urlToDownloadSchema, _config.DataLinkerHost, schema.Name, checkResult.License.ID, isProvider);
        }
        public CustomFileDetails GetTemplatedLicenseForPreview(List <SectionsWithClauses> model, int orgId, int schemaId, LoggedInUserDetails user)
        {
            // Check access
            _security.CheckBasicAccess(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 administrator.");
            }

            // Define result
            var result = new CustomFileDetails();

            // Get published license template
            var template = _licenseTemplates.FirstOrDefault(i => i.Status == (int)TemplateStatus.Active);

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

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

            // Setup content for document
            var document = _licenseContentBuilder.GetDocument(model, schemaId, orgId, template, _config.DataLinkerHost, urlToSchema);

            // Create pdf document
            var pdfDocument = new HtmlToPdfConverter
            {
                PageFooterHtml = _licenseContentBuilder.GetFooterText((int)PublishStatus.Draft, _config.DataLinkerHost)
            };

            // Get bytes from document
            var bytes = pdfDocument.GeneratePdf(document.OuterXml);

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

            // Return result
            return(result);
        }
        public void RequestForAccess(int consumerAppId, int providerLicenseId, LoggedInUserDetails user)
        {
            var registeredProvider = _consumerProviderRegistration.Where(p => p.ConsumerApplicationID == consumerAppId && p.OrganizationLicenseID == providerLicenseId).SingleOrDefault();

            if (registeredProvider == null)
            {
                registeredProvider = new ConsumerProviderRegistration()
                {
                    ConsumerApplicationID = consumerAppId,
                    OrganizationLicenseID = providerLicenseId,
                    Status    = (int)ConsumerProviderRegistrationStatus.PendingConsumerApproval,
                    CreatedAt = DateTime.UtcNow,
                    CreatedBy = user.ID.Value
                };
                _consumerProviderRegistration.Add(registeredProvider);
            }
            else
            {
                registeredProvider.Status = (int)ConsumerProviderRegistrationStatus.PendingConsumerApproval;
                _consumerProviderRegistration.Update(registeredProvider);
            }

            var license = _licenseService.FirstOrDefault(p => p.ID == providerLicenseId);

            // Get legal officers for organisation
            var legalOfficers = _users.Where(i => i.OrganizationID == user.Organization.ID)
                                .Where(i => i.IsActive == true && i.IsIntroducedAsLegalOfficer == true && i.IsVerifiedAsLegalOfficer == true)
                                .ToList();

            // Get schema
            var schema = _schemaService.FirstOrDefault(i => i.ID == license.DataSchemaID);

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

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

            // Send notification to legal officers.
            SendNotificationToLegalOfficers(license, registeredProvider.ID, legalOfficers, schema.Name, urlToSchema, user, false);
        }
        public void RequestLicenseVerification(int id, int appId, int schemaId, LoggedInUserDetails user)
        {
            // Check access
            var application = _security.CheckAccessToApplication(user, appId);

            // Check whether organisation is active
            if (!user.Organization.IsActive)
            {
                throw new BaseException(orgIsInactiveError);
            }

            // Get license
            var license = _service.FirstOrDefault(i => i.ID == id);

            // Only draft license can be sent for legal approval
            if (license.Status != (int)PublishStatus.Draft)
            {
                throw new BaseException("Only in draft status license can be sent to Legal Officer.");
            }

            var pendingApprovalLicenses = new List <OrganizationLicense>();

            // Check whether it's a provider
            if (application.IsProvider)
            {
                // Provider can have only one pending approval license
                pendingApprovalLicenses = _service.Where(i => i.ApplicationID == appId)
                                          .Where(i => i.DataSchemaID == schemaId && i.Status == (int)PublishStatus.PendingApproval).ToList();
            }
            else
            {
                // Update status for another templated pending approval licenses for consumer
                pendingApprovalLicenses = _service.Where(i => i.ApplicationID == appId)
                                          .Where(i => i.DataSchemaID == schemaId && i.Status == (int)PublishStatus.PendingApproval && i.LicenseTemplateID != 0).ToList();
            }

            // Change status to draft for other pending approval licenses
            foreach (var pendingApprovalLicense in pendingApprovalLicenses)
            {
                pendingApprovalLicense.Status = (int)PublishStatus.Draft;
                _service.Update(pendingApprovalLicense);
            }

            // Update license status
            license.Status = (int)PublishStatus.PendingApproval;
            _service.Update(license);

            // Get schema
            var schema = _dataSchemaService.FirstOrDefault(i => i.ID == license.DataSchemaID);

            // Get schema file
            var schemaFile = _schemaFileService.FirstOrDefault(i => i.DataSchemaID == schema.ID);

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

            // Get legal officers for organisation
            var legalOfficers = _users.Where(i => i.OrganizationID == user.Organization.ID)
                                .Where(i => i.IsActive == true && i.IsIntroducedAsLegalOfficer == true && i.IsVerifiedAsLegalOfficer == true)
                                .ToList();

            // Send notification to legal officers
            SendNotificationToLegalOfficers(license, legalOfficers, schema.Name, urlToSchema, user);
        }
Beispiel #5
0
        public void CreateLicenseAgreement(LicenseDetails licenseDetails, LoggedInApplication loggedInApp)
        {
            if (!loggedInApp.IsProvider)
            {
                throw new BaseException("Access denied");
            }

            var providedSchemas = licenseDetails.accepted_schemas.Split(' ');

            foreach (var schemaPublicId in providedSchemas)
            {
                // Get schema
                var schema = _dataSchemas.FirstOrDefault(i => i.PublicID == schemaPublicId);
                if (schema == null)
                {
                    // Return error is schema was not found
                    throw new BaseApiException($"Specified schema '{schemaPublicId}' was not found");
                }
                // Setup Jwt reader
                var tokenHandler = new JwtSecurityTokenHandler();
                // Read Jwt token
                var           jwt = (JwtSecurityToken)tokenHandler.ReadToken(licenseDetails.software_statement);
                SecurityToken validatedToken;
                // Verify signature in jwt
                tokenHandler.ValidateToken(licenseDetails.software_statement, TokenValidationParameters, out validatedToken);
                // Retrieve from jwt public id for consumer application
                var consumerPublicId    = jwt.Payload["software_id"].ToString();
                var consumerAppPublicId = new Guid(consumerPublicId);
                // Get provider service
                var providerApp = _applications.FirstOrDefault(i => i.ID == loggedInApp.ID);
                // Get consumer application
                var consumerApp = _applications.FirstOrDefault(i => i.PublicID == consumerAppPublicId);
                if (consumerApp == null)
                {
                    throw new BaseApiException($"Specified consumer '{consumerPublicId}' not found");
                }
                // Both parties should have published data agreement for schema which must match
                var agreement = CreateAgreementIfNotExists(licenseDetails, consumerApp, schema, schemaPublicId, providerApp);
                // Skip this scope if agreement already exists
                if (agreement == null)
                {
                    continue;
                }
                // Save new license agreement
                _licenseAgreements.Add(agreement);

                // TODO: Audit log
                //AuditLog.Log(AuditStream.LegalAgreements, "License agreement created",
                //    new {LoggedInApplication.Name, LoggedInApplication.TokenUsedToAuthorize, OrgId = LoggedInApplication.Organization.ID},
                //    new {agreement.ID, schemaName = schema.PublicID});

                // Get schema file
                var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == schema.ID);
                // Setup url to schema
                var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID);
                // Setup url to download license agreement
                var linkToDownloadLicense = $"{_host}{_linkToDownloadAgreement}{agreement.ID}";
                // Notify legal officers about new license agreement
                _notificationService.LegalOfficer.LicenseAgreementCreatedInBackground(agreement.ID,
                                                                                      linkToDownloadLicense, urlToSchema, _host);
            }
        }