def test_sns_organization_topic_success_case_exists_organization_id_and_user_id(
            self):
        expected_message = DataTestSns.MESSAGE

        # mock object
        patch_aws_sns = patch("premembers.common.aws_common.aws_sns")

        # start mock object
        mock_aws_sns = patch_aws_sns.start()

        # mock data
        mock_aws_sns.side_effect = None

        # addCleanup stop mock object
        self.addCleanup(patch_aws_sns.stop)

        # call Function test
        aws_common.sns_organization_topic(
            user_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG,
            organization_id, user_id)

        # check param call fuction aws_sns
        mock_aws_sns.assert_called_once_with(user_id, subject,
                                             json.dumps(expected_message),
                                             topic_arn_test)
def delete_user(trace_id, organization_id, user_id, email):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    # check the deletion condition
    if user_id == trace_id:
        try:
            count = pm_affiliation.query_users_check_authority_count(
                trace_id, user_id, organization_id, Authority.Owner)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_402, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)
        if count == 0:
            return common_utils.error_common(MsgConst.ERR_REQUEST_203,
                                             HTTPStatus.PRECONDITION_FAILED,
                                             pm_logger)
    # get user to delete
    try:
        user = pm_affiliation.query(user_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    if not user:
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    # delete user
    try:
        pm_affiliation.delete_affiliation(user_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # set task informaiton request delete in Organization Tasks
    task_id = str(uuid.uuid4())
    target = CommonConst.TARGET_DELETE_ORG_USER.format(user_id,
                                                       organization_id)

    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER,
            target, trace_id, email, Status.Waiting.value, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    try:
        # Send message to organization topic task
        aws_common.sns_organization_topic(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER)
    except PmError as e:
        common_utils.write_log_pm_error(e, pm_logger, exc_info=True)

    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
예제 #3
0
def delete_project(trace_id, email, project_id, organization_id):
    # Get logging
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        project = pm_projects.get_projects_by_organization_id(
            trace_id, project_id, organization_id, convert_response=True)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # 組織情報を取得します。
    if (not project):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    # プロジェクト削除の条件を満たしているかチェックを行います。現時点ではチェックすべき項目はありません。
    # 現時点ではチェックすべき項目はありません。

    # Delete project
    try:
        pm_projects.delete_projects(trace_id, project_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Create task
    task_id = str(uuid.uuid4())
    user_id = trace_id
    try:
        pm_organizationTasks.create_organizationTask(trace_id, task_id,
                                                     "DELETE_PRJ", project_id,
                                                     user_id, email,
                                                     Status.Waiting.value, 0,
                                                     3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    aws_common.sns_organization_topic(trace_id, task_id, "DELETE_PRJ")

    # data response
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
예제 #4
0
def delete_report(trace_id, email, report_id, organization_id, project_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        # get report
        report_item = pm_reports.query_report_filter_organization_project(
            trace_id, report_id, project_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    if (not report_item):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        # delete report
        pm_reports.delete_reports(trace_id, report_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    task_id = common_utils.get_uuid4()
    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(trace_id, task_id,
                                                     task_code, report_id,
                                                     trace_id, email, 0, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Send message to organization topic task
    aws_common.sns_organization_topic(trace_id, task_id, task_code)

    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
def delete_organization(trace_id, email, organization_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        organization_item = pm_organizations.get_organization(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    if (not organization_item):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        # delete organization
        pm_organizations.delete_organization(trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    try:
        # get affiliations get by organization id
        affiliation_items = pm_affiliation.query_organization_index(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    for affiliation in affiliation_items:
        try:
            # delete affiliations get by organization id
            pm_affiliation.delete_affiliation(affiliation["UserID"],
                                              organization_id)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_405, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        # set task informaiton request delete in Organization Tasks
        task_id = common_utils.get_uuid4()
        target = CommonConst.TARGET_DELETE_ORG_USER.format(
            affiliation["UserID"], organization_id)

        try:
            # create task informaiton request delete in Organization Tasks
            pm_organizationTasks.create_organizationTask(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER,
                target, trace_id, email, Status.Waiting.value, 0, 3)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        try:
            # Send message to organization topic task
            aws_common.sns_organization_topic(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER)
        except PmError as e:
            common_utils.write_log_pm_error(e, pm_logger, exc_info=True)

    # set task informaiton request delete in Organization Tasks
    task_id = common_utils.get_uuid4()
    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG,
            organization_id, trace_id, email, 0, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Send message to organization topic task
    aws_common.sns_organization_topic(trace_id, task_id,
                                      CommonConst.TASK_TYPE_CODE_DELETE_ORG,
                                      organization_id, trace_id)
    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)