def test_changes_after_onboarding_approved(self):
        """ Non Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(False, None)))
        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(True, {})))
        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes with org_id """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(True, {"values_changed": {"root._Organization__id"}})))
        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.DRAFT.value)

        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.SUBMIT.value)
    def test_changes_after_onboarding(self):
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING.value))
        self.assertEqual(OrganizationStatus.ONBOARDING.value,
                         Organization.next_state(current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING.value,
                         Organization.next_state(current_org, Mock(), OrganizationActions.SUBMIT.value))
    def test_changes_after_published(self):
        current_org = Mock(get_status=Mock(
            return_value=OrganizationStatus.PUBLISHED.value))
        self.assertEqual(
            OrganizationStatus.APPROVED.value,
            Organization.next_state(current_org, Mock(),
                                    OrganizationActions.DRAFT.value))

        self.assertEqual(
            OrganizationStatus.APPROVED.value,
            Organization.next_state(current_org, Mock(),
                                    OrganizationActions.SUBMIT.value))
    def parse_organization_metadata(org_uuid, ipfs_org_metadata, origin,
                                    duns_no, addresses, metadata_uri,
                                    existing_assets, transaction_hash,
                                    members):
        org_id = ipfs_org_metadata.get("org_id", None)
        org_name = ipfs_org_metadata.get("org_name", None)
        org_type = ipfs_org_metadata.get("org_type", None)
        description = ipfs_org_metadata.get("description", None)
        short_description = ""
        url = ""
        long_description = ""

        if description:
            short_description = description.get("short_description", None)
            long_description = description.get("description", None)
            url = description.get("url", None)

        contacts = ipfs_org_metadata.get("contacts", None)
        assets = OrganizationFactory.parse_organization_metadata_assets(
            ipfs_org_metadata.get("assets", None), existing_assets)
        metadata_ipfs_hash = metadata_uri
        owner = ""
        groups = OrganizationFactory.group_domain_entity_from_group_list_metadata(
            ipfs_org_metadata.get("groups", []))

        organization = Organization(
            org_uuid, org_id, org_name, org_type, origin, long_description,
            short_description, url, contacts, assets, metadata_ipfs_hash,
            duns_no, groups, addresses, OrganizationStatus.PUBLISHED.value,
            members)

        return organization
    def org_domain_entity_from_payload(payload):

        org_uuid = payload["org_uuid"]
        org_id = payload["org_id"]
        org_name = payload["org_name"]
        org_type = payload["org_type"]
        description = payload["description"]
        short_description = payload["short_description"]
        url = payload["url"]
        duns_no = payload["duns_no"]
        origin = payload["origin"]
        if origin not in ALLOWED_ORIGIN:
            raise InvalidOriginException()
        contacts = payload["contacts"]
        assets = payload["assets"]
        metadata_ipfs_uri = payload["metadata_ipfs_uri"]
        groups = OrganizationFactory.group_domain_entity_from_group_list_payload(
            payload["groups"])
        addresses = OrganizationFactory \
            .domain_address_entity_from_address_list_payload(payload["org_address"]["addresses"])
        organization = Organization(org_uuid, org_id, org_name, org_type,
                                    origin, description, short_description,
                                    url, contacts, assets, metadata_ipfs_uri,
                                    duns_no, groups, addresses, None, [])
        return organization
    def test_changes_after_published(self):
        """ Non Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.PUBLISHED.value),
                           is_major_change=Mock(return_value=(False, None)))
        self.assertEqual(OrganizationStatus.APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.PUBLISHED.value),
                           is_major_change=Mock(return_value=(True, {})))
        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.DRAFT.value)

        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.SUBMIT.value)
Beispiel #7
0
 def create_organization(self, payload):
     logger.info(f"create organization for user: {self.username}")
     organization = OrganizationFactory.org_domain_entity_from_payload(payload)
     organization.setup_id()
     logger.info(f"assigned org_uuid : {organization.uuid}")
     org_ids = self.get_all_org_id()
     if organization.id in org_ids:
         raise Exception("Org_id already exists")
     updated_state = Organization.next_state(None, None, OrganizationActions.CREATE.value)
     org_repo.add_organization(organization, self.username, updated_state)
     return organization.to_response()
Beispiel #8
0
    def update_organization(self, payload, action):
        logger.info(f"update organization for user: {self.username} org_uuid: {self.org_uuid} action: {action}")
        updated_organization = OrganizationFactory.org_domain_entity_from_payload(payload)
        current_organization = org_repo.get_org_for_org_uuid(self.org_uuid)

        self._archive_current_organization(current_organization)
        updated_state = Organization.next_state(current_organization, updated_organization, action)
        if updated_state == OrganizationStatus.ONBOARDING.value:
            self.notify_approval_team(updated_organization.id, updated_organization.name)
            self.notify_user_on_start_of_onboarding_process(updated_organization.id, recipients=[self.username])
        org_repo.update_organization(updated_organization, self.username, updated_state)
        return "OK"
 def update_organization(self, payload, action):
     logger.info(
         f"update organization for user: {self.username} org_uuid: {self.org_uuid} action: {action}"
     )
     updated_organization = OrganizationFactory.org_domain_entity_from_payload(
         payload)
     current_organization = org_repo.get_organization(
         org_uuid=self.org_uuid)
     self._archive_current_organization(current_organization)
     updated_state = Organization.next_state(current_organization,
                                             updated_organization, action)
     org_repo.update_organization(updated_organization, self.username,
                                  updated_state)
     return "OK"
Beispiel #10
0
 def create_organization(self, payload):
     logger.info(f"create organization for user: {self.username}")
     organization = OrganizationFactory.org_domain_entity_from_payload(
         payload)
     organization.setup_id()
     if not organization.create_setup():
         raise Exception("Invalid Organization information")
     logger.info(f"assigned org_uuid : {organization.uuid}")
     org_ids = self.get_all_org_id()
     if organization.id in org_ids:
         raise Exception("Org_id already exists")
     updated_state = Organization.next_state(
         None, None, OrganizationActions.CREATE.value)
     self.notify_approval_team(organization.id, organization.name)
     self.notify_user_on_start_of_onboarding_process(
         organization.id, recipients=[self.username])
     org_repo.add_organization(organization, self.username, updated_state)
     return organization.to_response()
Beispiel #11
0
 def org_domain_entity_from_repo_model(organization_repo_model):
     return Organization(
         uuid=organization_repo_model.uuid,
         name=organization_repo_model.name,
         org_id=organization_repo_model.org_id,
         org_type=organization_repo_model.org_type,
         origin=organization_repo_model.origin,
         description=organization_repo_model.description,
         short_description=organization_repo_model.short_description,
         url=organization_repo_model.url,
         contacts=organization_repo_model.contacts,
         assets=organization_repo_model.assets,
         metadata_ipfs_uri=organization_repo_model.metadata_ipfs_uri,
         duns_no=organization_repo_model.duns_no,
         groups=OrganizationFactory.parse_group_data_model(organization_repo_model.groups),
         addresses=OrganizationFactory.parse_organization_address_data_model(organization_repo_model.addresses),
         org_state=OrganizationFactory.parse_organization_state_data_model(organization_repo_model.org_state),
         members=[],
         registration_id=organization_repo_model.registration_id,
         registration_type=organization_repo_model.registration_type
     )
    def _process_organization_create_event(self, org_id, ipfs_org_metadata, org_metadata_uri, transaction_hash, owner,
                                           recieved_members_list):
        try:

            existing_publish_in_progress_organization = self._get_existing_organization_records(org_id)
            org_id = ipfs_org_metadata.get("org_id", None)
            org_name = ipfs_org_metadata.get("org_name", None)
            org_type = ipfs_org_metadata.get("org_type", None)
            description = ipfs_org_metadata.get("description", None)
            short_description = ""
            url = ""
            long_description = ""

            if description:
                short_description = description.get("short_description", None)
                long_description = description.get("description", None)
                url = description.get("url", None)

            contacts = ipfs_org_metadata.get("contacts", None)
            assets = OrganizationFactory.parse_organization_metadata_assets(ipfs_org_metadata.get("assets", None),
                                                                            None)

            groups = OrganizationFactory.group_domain_entity_from_group_list_metadata(
                ipfs_org_metadata.get("groups", []))

            org_uuid = ""
            origin = ""
            duns_no = ""
            addresses = []
            members = []

            received_organization_event = Organization(org_uuid, org_id, org_name, org_type,
                                                       origin, long_description,
                                                       short_description, url, contacts, assets, org_metadata_uri,
                                                       duns_no, groups,
                                                       addresses,
                                                       OrganizationStatus.DRAFT.value,
                                                       members)

            test_transaction_hash = RegistryBlockChainUtil(EnvironmentType.TEST.value) \
                .publish_organization_to_test_network(received_organization_event)

            if not existing_publish_in_progress_organization:
                existing_members = []

                received_organization_event.setup_id()
                org_uuid = received_organization_event.uuid
                self._create_event_outside_publisher_portal(received_organization_event, test_transaction_hash)

            elif existing_publish_in_progress_organization.org_state.transaction_hash != transaction_hash \
                    and existing_publish_in_progress_organization.is_blockchain_major_change(received_organization_event)[0]:

                org_uuid = existing_publish_in_progress_organization.uuid
                logger.info(f"Detected Major change for {org_uuid}")
                existing_members = self._organization_repository.get_org_member(
                    org_uuid=existing_publish_in_progress_organization.uuid)
                self._organization_repository.store_organization(
                    existing_publish_in_progress_organization, BLOCKCHAIN_USER,
                    OrganizationStatus.APPROVAL_PENDING.value, test_transaction_hash=test_transaction_hash)
            else:
                org_uuid = existing_publish_in_progress_organization.uuid
                existing_members = self._organization_repository.get_org_member(
                    org_uuid=existing_publish_in_progress_organization.uuid)
                self._mark_existing_publish_in_progress_as_published(existing_publish_in_progress_organization,
                                                                     test_transaction_hash)
            owner = OrganizationFactory.parser_org_owner_from_metadata(org_uuid, owner,
                                                                       OrganizationMemberStatus.PUBLISHED.value)
            recieved_members = OrganizationFactory.parser_org_members_from_metadata(org_uuid, recieved_members_list,
                                                                                    OrganizationMemberStatus.PUBLISHED.value)

            self._process_members(org_uuid, owner, existing_members, recieved_members)
        except Exception as e:
            traceback.print_exc()
            logger.exception(e)
            raise Exception(f"Error while processing org created event for org_id {org_id}")