def update_organization(self, organization, username, state):
     organization_db_model = self.session.query(Organization).filter(
         Organization.uuid == organization.uuid).first()
     if organization_db_model is None:
         raise OrganizationNotFoundException()
     self._update_organization(organization_db_model, organization,
                               username, state)
Example #2
0
 def persist_publish_org_transaction_hash(self, org_uuid, transaction_hash,
                                          wallet_address, nonce, username):
     organization_db_model = self.session.query(Organization).filter(
         Organization.uuid == org_uuid).first()
     org_owner = self.session.query(OrganizationMember).filter(OrganizationMember.role == Role.OWNER.value) \
         .filter(OrganizationMember.org_uuid == org_uuid).first()
     if organization_db_model is None or org_owner is None:
         raise OrganizationNotFoundException()
     try:
         organization_db_model.org_state[0].wallet_address = wallet_address
         organization_db_model.org_state[
             0].state = OrganizationStatus.PUBLISH_IN_PROGRESS.value
         organization_db_model.org_state[0].updated_on = datetime.utcnow()
         organization_db_model.org_state[0].updated_by = username
         organization_db_model.org_state[
             0].transaction_hash = transaction_hash
         organization_db_model.org_state[0].nonce = nonce
         org_owner.address = wallet_address
         org_owner.transaction_hash = transaction_hash
         if org_owner != OrganizationMemberStatus.PUBLISHED.value:
             org_owner.status = OrganizationMemberStatus.PUBLISH_IN_PROGRESS.value
         self.session.commit()
     except Exception:
         self.session.rollback()
         raise
Example #3
0
 def get_org_for_org_id(self, org_id):
     organization = self.session.query(Organization).filter(
         Organization.org_id == org_id).first()
     if organization is None:
         raise OrganizationNotFoundException()
     organization_domain_entity = OrganizationFactory.org_domain_entity_from_repo_model(
         organization)
     self.session.commit()
     return organization_domain_entity
 def daemon_config(self, environment):
     organization = OrganizationPublisherRepository().get_org_for_org_uuid(
         self._org_uuid)
     if not organization:
         raise OrganizationNotFoundException()
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if not service:
         raise ServiceNotFoundException()
     organization_members = OrganizationPublisherRepository(
     ).get_org_member(org_uuid=self._org_uuid)
     network_name = NETWORKS[NETWORK_ID]["name"].lower()
     # this is how network name is set in daemon for mainnet
     network_name = "main" if network_name == "mainnet" else network_name
     if environment is EnvironmentType.TEST.value:
         daemon_config = {
             "allowed_user_flag":
             True,
             "allowed_user_addresses":
             [member.address for member in organization_members] +
             [BLOCKCHAIN_TEST_ENV["publisher_address"]],
             "authentication_addresses":
             [member.address for member in organization_members],
             "blockchain_enabled":
             False,
             "passthrough_enabled":
             True,
             "organization_id":
             organization.id,
             "service_id":
             service.service_id
         }
     elif environment is EnvironmentType.MAIN.value:
         daemon_config = {
             "ipfs_end_point":
             f"{IPFS_URL['url']}:{IPFS_URL['port']}",
             "blockchain_network_selected":
             network_name,
             "organization_id":
             organization.id,
             "service_id":
             service.service_id,
             "metering_end_point":
             f"https://{network_name}-marketplace.singularitynet.io",
             "authentication_addresses":
             [member.address for member in organization_members],
             "blockchain_enabled":
             True,
             "passthrough_enabled":
             True
         }
     else:
         raise EnvironmentNotFoundException()
     return daemon_config
Example #5
0
    def register_or_update_service_in_blockchain(self, org_id, service_id,
                                                 metadata_uri, tags):
        if not self.is_org_published(org_id=org_id):
            raise OrganizationNotFoundException()

        if self.is_service_published(org_id=org_id, service_id=service_id):
            transaction_hash = self.update_service_in_blockchain(
                org_id, service_id, metadata_uri)
        else:
            transaction_hash = self.register_service_in_blockchain(
                org_id, service_id, metadata_uri, tags)
        return transaction_hash
    def submit_service_for_approval(self, payload):

        user_as_contributor = [{"email_id": self._username, "name": ""}]
        payload["contributors"] = payload.get(
            "contributors", user_as_contributor) + user_as_contributor

        organization = OrganizationPublisherRepository().get_org_for_org_uuid(
            self._org_uuid)
        if not organization:
            raise OrganizationNotFoundException()
        if not organization.org_state:
            raise InvalidOrganizationStateException()
        if not organization.org_state.state == OrganizationStatus.PUBLISHED.value:
            raise OrganizationNotPublishedException()

        service = service_factory.create_service_entity_model(
            self._org_uuid, self._service_uuid, payload,
            ServiceStatus.APPROVAL_PENDING.value)

        # publish service data with test config on ipfs
        service = self.obj_service_publisher_domain_service.publish_service_data_to_ipfs(
            service, EnvironmentType.TEST.value)

        comments = payload.get("comments",
                               {}).get(UserType.SERVICE_PROVIDER.value, "")
        if bool(comments):
            service_provider_comment = service_factory. \
                create_service_comment_entity_model(org_uuid=self._org_uuid,
                                                    service_uuid=self._service_uuid,
                                                    support_type="SERVICE_APPROVAL",
                                                    user_type="SERVICE_PROVIDER",
                                                    commented_by=self._username,
                                                    comment=comments)
            ServicePublisherRepository().save_service_comments(
                service_provider_comment)
        service = ServicePublisherRepository().save_service(
            self._username, service, service.service_state.state)

        # publish service on test network
        response = self.obj_service_publisher_domain_service.publish_service_on_blockchain(
            org_id=organization.id,
            service=service,
            environment=EnvironmentType.TEST.value)

        # notify service contributors via email
        self.notify_service_contributor_when_user_submit_for_approval(
            organization.id, service.service_id, service.contributors)

        # notify approval team via slack
        self.notify_approval_team(service.service_id, service.display_name,
                                  organization.id, organization.name)
        return response
 def persist_publish_org_transaction_hash(self, org_uuid, transaction_hash,
                                          wallet_address, username):
     organization_db_model = self.session.query(Organization).filter(
         Organization.uuid == org_uuid).first()
     if organization_db_model is None:
         raise OrganizationNotFoundException()
     organization_db_model.org_state[0].trasaction_hash = transaction_hash
     organization_db_model.org_state[0].wallet_address = wallet_address
     organization_db_model.org_state[
         0].state = OrganizationStatus.PUBLISH_IN_PROGRESS.value
     organization_db_model.org_state[0].updated_on = datetime.utcnow()
     organization_db_model.org_state[0].updated_by = username
     self.session.commit()