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)
 def tearDown(self):
     pm_organizations.delete_organization(trace_id, test_organization_id)
     pm_organizations.delete_organization(trace_id, insert_organization_id)
     pm_organizations.delete_organization(trace_id, update_organization_id)
     pm_organizations.delete_organization(trace_id, delete_organization_id)
     pm_organizations.delete_organization(trace_id, batch_organization_id)
     pm_affiliation.delete_affiliation(batch_affiliation_user_id,
                                       batch_organization_id)
Exemplo n.º 3
0
    def tearDown(self):
        pm_orgNotifyMailDestinations.delete(trace_id, organization_id,
                                            notify_code)
        num = 1
        while num < 4:
            pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                              organization_id)
            num += 1

        pm_orgNotifySlack.delete(trace_id, organization_id, notify_code)
Exemplo n.º 4
0
 def tearDown(self):
     num = 1
     while num < 4:
         pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                           organization_id)
         num += 1
     pm_projects.delete_projects(trace_id, project_id)
     pm_organizations.delete_organization(trace_id, organization_id)
     pm_awsAccountCoops.delete_awscoops(trace_id,
                                        awscoops_template["CoopID"])
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id.format(str(999)))
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id_members_enable)
Exemplo n.º 5
0
    def tearDown(self):
        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_affiliation.delete_affiliation(
                user_id=delete_user_id,
                organization_id=affiliation_org_id_template.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_organizations.delete_organization(
                trace_id,
                organization_id=affiliation_org_id_template.format(str(num)))
            num += 1
Exemplo n.º 6
0
 def tearDown(self):
     num = 1
     while num < 4:
         pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                           organization_id)
         pm_reports.delete_reports(trace_id, report_id.format(str(num)))
         num += 1
     pm_projects.delete_projects(trace_id, project_id)
     pm_organizations.delete_organization(trace_id, organization_id)
     # Delete ReportJobDefs
     pm_batchJobDefs.delete_report_job_def(trace_id, code_aws)
     pm_batchJobDefs.delete_report_job_def(trace_id, code_json)
     pm_batchJobDefs.delete_report_job_def(trace_id, code_excel)
     pm_reports.delete_reports(trace_id, report_id.format(str(4)))
     pm_reports.delete_reports(trace_id, report_id.format(str(5)))
     pm_reports.delete_reports(trace_id, report_id.format(str(6)))
Exemplo n.º 7
0
    def tearDown(self):
        num = 0
        while num < 2:
            # Get data user_id delete and organization_id delete
            user_id = affiliation_template['UserID'].format(str(num))
            organization_id = template_organization_id.format(
                str(num))

            # Delete data table Organization and Affiliation
            pm_affiliation.delete_affiliation(user_id, organization_id)
            pm_organizations.delete_organization(trace_id, organization_id)
            pm_projects.delete_projects(
                trace_id, projects_id_template.format(str(num)))
            num += 1

        # remove data test function delete organaization
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_affiliation.delete_affiliation(
                user_id=delete_user_id,
                organization_id=template_organization_id.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_organizations.delete_organization(
                trace_id,
                organization_id=template_organization_id.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_project_id = projects_template['ProjectID'].format(str(num))
            pm_projects.delete_projects(trace_id, delete_project_id)
            num += 1
Exemplo n.º 8
0
 def tearDown(self):
     # 所属ユーザーの削除
     pm_affiliation.delete_affiliation(
         user_id=affiliation_template['UserID'].format("registered"),
         organization_id=registered_organization_id)
     # 未所属ユーザーの削除
     pm_affiliation.delete_affiliation(
         user_id=affiliation_template['UserID'].format("not_belong"),
         organization_id=not_belong_organization_id)
     # 権限不足ユーザーの削除
     pm_affiliation.delete_affiliation(
         user_id=affiliation_template['UserID'].format(
             "not_enough_permission"),
         organization_id=registered_organization_id)
Exemplo n.º 9
0
def execute_delete_invalid_user(trace_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())

    # Get Cognito UserPools status UNCONFIRMED
    try:
        list_user_unconfirmed = aws_common.get_cognito_user_pools(
            trace_id,
            CommonConst.COGNITO_STATUS_UNCONFIRMED,
            attribute_filter=CommonConst.ATTRIBUTE_FILTER_USER_STATUS)
    except PmError as e:
        pm_logger.error("[%s]Cognitoユーザー一覧情報取得に失敗しました。",
                        CommonConst.COGNITO_STATUS_UNCONFIRMED)
        raise common_utils.write_log_pm_error(e, pm_logger)

    # get current date
    current_date_time = date_utils.toDate(
        date_utils.get_current_date_by_format(
            date_utils.PATTERN_YYYYMMDDHHMMSS), date_utils.UTC)

    # loop user cognito UserPools status UNCONFIRMED
    for user_unconfirmed in list_user_unconfirmed:
        user_create_date = date_utils.toDate(
            date_utils.toString(user_unconfirmed['UserCreateDate'],
                                date_utils.PATTERN_YYYYMMDDHHMM),
            date_utils.UTC)
        if date_utils.difference_days(
                user_create_date,
                current_date_time) > CommonConst.TERM_USER_UNCONFIRMED_DAY:
            # delete Cognito UserPools status UNCONFIRMED update period greater than 1 days
            try:
                aws_common.delete_cognito_user_by_user_name(
                    trace_id, user_unconfirmed['Username'])
            except PmError as e:
                pm_logger.warning("CognitoでUserName = %sのユーザー削除に失敗しました。",
                                  user_unconfirmed['Username'])
                raise common_utils.write_log_pm_error(e, pm_logger)

    # Get Cognito UserPools status FORCE_CHANGE_PASSWORD
    try:
        list_user_force_change_password = aws_common.get_cognito_user_pools(
            trace_id,
            CommonConst.COGNITO_STATUS_FORCE_CHANGE_PASSWORD,
            attribute_filter=CommonConst.ATTRIBUTE_FILTER_USER_STATUS)
    except PmError as e:
        pm_logger.error("[%s]Cognitoユーザー一覧情報取得に失敗しました。",
                        CommonConst.COGNITO_STATUS_FORCE_CHANGE_PASSWORD)
        raise common_utils.write_log_pm_error(e, pm_logger)

    current_date = date_utils.toDate(
        date_utils.toString(current_date_time,
                            date_utils.PATTERN_YYYYMMDD_SLASH), date_utils.UTC)
    # loop user cognito UserPools status FORCE_CHANGE_PASSWORD
    for user_force_change_password in list_user_force_change_password:
        user_create_date = date_utils.toDate(
            date_utils.toString(user_force_change_password['UserCreateDate'],
                                date_utils.PATTERN_YYYYMMDD_SLASH),
            date_utils.UTC)
        if date_utils.difference_days(
                user_create_date, current_date
        ) > CommonConst.TERM_USER_FORCE_CHANGE_PASSWORD_DAY:
            # get list affiliations
            try:
                affiliations = pm_affiliation.query_userid_key(
                    trace_id, user_force_change_password['Username'])
            except PmError as e:
                pm_logger.warning(
                    "PM_Affiliationテーブルにて、UserID = %sのレコード取得に失敗しました。",
                    user_force_change_password['Username'])
                raise common_utils.write_log_pm_error(e, pm_logger)

            # delete affiliations user status FORCE_CHANGE_PASSWORD update period greater than 6 days
            for affiliation in affiliations:
                try:
                    pm_affiliation.delete_affiliation(
                        affiliation['UserID'], affiliation['OrganizationID'])
                except PmError as e:
                    pm_logger.warning(
                        "PM_Affiliationテーブルのレコード削除に失敗しました。UserID : %s / OrganizationID : %s",
                        affiliation['UserID'], affiliation['OrganizationID'])
                    raise common_utils.write_log_pm_error(e, pm_logger)

            # delete Cognito UserPools status FORCE_CHANGE_PASSWORD update period greater than 6 days
            try:
                aws_common.delete_cognito_user_by_user_name(
                    trace_id, user_force_change_password['Username'])
            except PmError as e:
                pm_logger.warning("CognitoでUserName = %sのユーザー削除に失敗しました。",
                                  user_force_change_password['Username'])
                raise common_utils.write_log_pm_error(e, pm_logger)
Exemplo n.º 10
0
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)