예제 #1
0
def org_verification(event, context):
    query_parameters = event["queryStringParameters"]
    if "verification_type" not in query_parameters:
        raise BadRequestException()
    verification_type = query_parameters["verification_type"]
    response = OrganizationPublisherService(None, None).update_verification(verification_type, query_parameters)
    return generate_lambda_response(
        StatusCode.CREATED,
        {"status": "success", "data": response, "error": {}}, cors_enabled=False
    )
예제 #2
0
def delete(event, context):
    query_parameters = event["queryStringParameters"]

    if "type" not in query_parameters:
        raise BadRequestException()
    response = FileService().delete(query_parameters)
    return generate_lambda_response(
        StatusCode.CREATED,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #3
0
def create_organization(event, context):
    payload = json.loads(event["body"])
    required_keys = []
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    if not validate_dict(payload, required_keys):
        raise BadRequestException()
    response = OrganizationPublisherService(None, username).create_organization(payload)
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #4
0
def get_group_for_org(event, context):
    path_parameters = event["pathParameters"]
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    if "org_uuid" not in path_parameters:
        raise BadRequestException()
    org_uuid = path_parameters["org_uuid"]
    response = OrganizationPublisherService(org_uuid, username).get_groups_for_org()
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #5
0
def verify_org_id(event, context):
    logger.info(event)
    query_parameters = event["queryStringParameters"]
    if "org_id" not in query_parameters:
        raise BadRequestException()
    org_id = query_parameters["org_id"]
    response = OrganizationPublisherService(None, None).get_org_id_availability_status(org_id)
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #6
0
def verify_code(event, context):
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    query_string_parameters = event["queryStringParameters"]
    if "invite_code" not in query_string_parameters:
        raise BadRequestException()
    invite_code = query_string_parameters["invite_code"]
    response = OrganizationPublisherService(None, username).verify_invite(invite_code)
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #7
0
 def save_transaction_hash_for_publish_org(self, payload):
     transaction_hash = payload.get("transaction_hash")
     if transaction_hash is None:
         raise BadRequestException()
     user_address = payload.get("wallet_address")
     nonce = payload.get("nonce")
     logger.info(f"save transaction hash for publish organization org_uuid: {self.org_uuid} "
                 f"transaction_hash: {transaction_hash} user_address: {user_address} nonce: {nonce}")
     org_repo.persist_publish_org_transaction_hash(self.org_uuid, transaction_hash, user_address, nonce,
                                                   self.username)
     return "OK"
예제 #8
0
def register_member(event, context):
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    payload = json.loads(event["body"])
    if "invite_code" not in payload and "wallet_address" not in payload:
        raise BadRequestException()
    invite_code = payload["invite_code"]
    wallet_address = payload["wallet_address"]
    response = OrganizationPublisherService(None, username).register_member(invite_code, wallet_address)
    return generate_lambda_response(
        StatusCode.CREATED,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #9
0
def save_transaction_hash_for_publish_org(event, context):
    payload = json.loads(event["body"])
    path_parameters = event["pathParameters"]
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    if "org_uuid" not in path_parameters:
        raise BadRequestException()
    org_uuid = path_parameters["org_uuid"]
    response = OrganizationPublisherService(org_uuid, username).save_transaction_hash_for_publish_org(payload)
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #10
0
def delete_members(event, context):
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    payload = json.loads(event["body"])
    path_parameters = event["pathParameters"]
    if "org_uuid" not in path_parameters or "members" not in payload:
        raise BadRequestException()
    org_uuid = path_parameters["org_uuid"]
    org_members = payload["members"]
    response = OrganizationPublisherService(org_uuid, username).delete_members(org_members)
    return generate_lambda_response(
        StatusCode.CREATED,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #11
0
def get_all_members(event, context):
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    path_parameters = event["pathParameters"]
    query_parameters = event["queryStringParameters"]
    if "org_uuid" not in path_parameters:
        raise BadRequestException()
    org_uuid = path_parameters["org_uuid"]
    status = query_parameters.get("status", None)
    role = query_parameters.get("role", None)
    response = OrganizationPublisherService(org_uuid, username).get_all_member(status, role, query_parameters)
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #12
0
 def domain_address_entity_from_payload(payload):
     address_type = payload.get("address_type", None)
     if address_type not in [OrganizationAddressType.HEAD_QUARTER_ADDRESS.value,
                             OrganizationAddressType.MAIL_ADDRESS.value]:
         raise BadRequestException()
     street_address = payload.get("street_address", None)
     apartment = payload.get("apartment", None)
     city = payload.get("city", None)
     pincode = payload.get("pincode", None)
     state = payload.get("state", None)
     country = payload.get("country", None)
     address = OrganizationAddress(address_type=address_type, street_address=street_address, apartment=apartment,
                                   pincode=pincode, city=city, state=state, country=country)
     return address
예제 #13
0
def update_org(event, context):
    payload = json.loads(event["body"])
    path_parameters = event["pathParameters"]
    required_keys = []
    action = event["queryStringParameters"].get("action", None)
    username = event["requestContext"]["authorizer"]["claims"]["email"]
    org_uuid = path_parameters["org_uuid"]
    if not validate_dict(payload, required_keys):
        raise BadRequestException()
    org_service = OrganizationPublisherService(org_uuid, username)
    if action in [OrganizationActions.DRAFT.value, OrganizationActions.SUBMIT.value]:
        response = org_service.update_organization(payload, action)
    else:
        raise Exception("Invalid action")
    return generate_lambda_response(
        StatusCode.OK,
        {"status": "success", "data": response, "error": {}}, cors_enabled=True
    )
예제 #14
0
def slack_interaction_handler(event, context):
    logger.info(f"event:: {event}")
    event_body = event["body"]
    event_body_dict = parse_qs(event_body)
    payload = json.loads(event_body_dict["payload"][0])
    headers = event["headers"]

    slack_chat_operation = SlackChatOperation(
        username=payload["user"]["username"],
        channel_id=payload.get("channel", {}).get("id", None))
    # validate slack request
    slack_chat_operation.validate_slack_request(headers=headers,
                                                payload_raw=event_body,
                                                ignore=True)

    data = {}
    if payload["type"] == "block_actions":
        for action in payload["actions"]:
            if "button" == action.get("type"):
                data = json.loads(action.get("value", {}))
        if not data:
            raise BadRequestException()
        if data["path"] == "/service":
            org_id = data["org_id"]
            service_id = data["service_id"]
            slack_chat_operation.\
                create_and_send_view_service_modal(org_id=org_id, service_id=service_id, trigger_id=payload["trigger_id"])
        elif data["path"] == "/org":
            org_id = data["org_id"]
            slack_chat_operation.create_and_send_view_org_modal(
                org_id=org_id, trigger_id=payload["trigger_id"])
        else:
            raise BadRequestException()
    elif payload["type"] == "view_submission":
        approval_type = "service" if payload["view"]["title"][
            "text"] == "Service For Approval" else ""
        approval_type = "organization" if payload["view"]["title"][
            "text"] == "Org For Approval" else approval_type
        review_request_state = \
            payload["view"]["state"]["values"]["approval_state"]["selection"]["selected_option"]["value"]
        comment = payload["view"]["state"]["values"]["review_comment"][
            "comment"]["value"]
        params = {}
        if approval_type == "service":
            params = {
                "org_id":
                payload["view"]["blocks"][0]["fields"][0]["text"].split(
                    "\n")[1],
                "service_id":
                payload["view"]["blocks"][0]["fields"][1]["text"].split("\n")
                [1]
            }
        elif approval_type == "organization":
            params = {
                "org_id":
                payload["view"]["blocks"][0]["fields"][0]["text"].split("\n")
                [1]
            }
        response = slack_chat_operation.process_approval_comment(
            approval_type=approval_type,
            state=review_request_state,
            comment=comment,
            params=params)
    return {'statusCode': 200, 'body': ""}