Exemple #1
0
def delete_jackal_agol(agol_account=None, network=None, connection=None):

    if connection is None:
        try:
            connection = DataConnection.objects.get(jackal_network=network,
                                                    agol_account=agol_account)
        except DataConnection.DoesNotExist:
            print("connection does not exist")
            return

    agol_account = connection.agol_account

    jackal_agol_connection = connection.jackal_agol_connection

    agol.delete_feature_layers(
        layer_ids=[
            connection.agol_layer_id,
            jackal_agol_connection.jackal_calls_table_id,
            jackal_agol_connection.jackal_contacts_table_id,
            jackal_agol_connection.jackal_texts_table_id,
            jackal_agol_connection.jackal_wa_calls_table_id,
            jackal_agol_connection.jackal_wa_groups_table_id,
            jackal_agol_connection.jackal_wa_messages_table_id,
            jackal_agol_connection.jackal_wa_users_table_id
        ],
        feature_service_url=agol_account.feature_service_url,
        agol_account=agol_account,
    )

    cloudwatch.delete_cloudwatch_rule(connection.cloudwatch_update_rule_name)

    jackal_agol_connection.delete()
    connection.delete()
def delete_drives_kml(drive_account):
    "Deschedules Lambda function outputting Drive data to KML in S3."

    if drive_account.cloudwatch_update_kml_rule_names:
        update_kml_rule_names = drive_account.cloudwatch_update_kml_rule_names.split(',')
        for rule_name in update_kml_rule_names:
            cloudwatch.delete_cloudwatch_rule(rule_name)

    drive_account.cloudwatch_update_kml_rule_names = None
    drive_account.save()
Exemple #3
0
def delete_jackal_kml(network):

    if network.cloudwatch_update_kml_rule_names:
        update_kml_rule_names = network.cloudwatch_update_kml_rule_names.split(
            ",")
        for rule_name in update_kml_rule_names:
            cloudwatch.delete_cloudwatch_rule(rule_name)

    network.cloudwatch_update_kml_rule_names = None
    network.save()
Exemple #4
0
def delete_source_kml(source):
    "docs"

    if source.cloudwatch_update_kml_rule_names:
        update_kml_rule_names = source.cloudwatch_update_kml_rule_names.split(
            ",")
        for rule_name in update_kml_rule_names:
            cloudwatch.delete_cloudwatch_rule(rule_name)

    source.cloudwatch_update_kml_rule_names = None
    source.save()
def delete_drives_agol(agol_account=None, drive_account=None, connection=None):
    "Deschedules Lambda function outputting Drive data to AGOL and deletes connection object."

    if connection is None:
        try:
            connection = DataConnection.objects.get(drive_account=drive_account, agol_account=agol_account)
        except DataConnection.DoesNotExist:
            print('connection does not exist, no problem')
            return

    agol_account = connection.agol_account

    if connection.agol_sheet_ids_to_layer_ids:
        sheet_ids_to_layer_ids = json.loads(connection.agol_sheet_ids_to_layer_ids)
        layer_ids = list(sheet_ids_to_layer_ids.values())
        agol.delete_feature_layers(layer_ids, agol_account.feature_service_url, agol_account)

    cloudwatch.delete_cloudwatch_rule(connection.cloudwatch_update_rule_name)
    connection.delete()
Exemple #6
0
    def post(self, request):
        serializer = common_serializers.DeleteAccountSerializer(
            data=request.data)
        serializer.is_valid(raise_exception=True)

        # TODO: verify that all CF rules being removed

        user, data = request.user, serializer.data

        try:
            realtime_account = RealTimeAccount.objects.get(
                uid=data["account_uid"], is_active=True)
        except RealTimeAccount.DoesNotExist:
            return Response(
                {
                    "error": "account_does_not_exist",
                    "message": "account does not exist",
                },
                status=status.HTTP_400_BAD_REQUEST,
            )

        if realtime_account.organization != request.user.organization:
            return Response(status=status.HTTP_403_FORBIDDEN)

        cloudwatch.delete_cloudwatch_rule(
            realtime_account.cloudwatch_get_data_rule_name)

        connections.delete_realtime_kml(realtime_account)

        try:  # if agol account exists, try to delete connection...
            connections.delete_realtime_agol(agol_account=user.agol_account,
                                             realtime_account=realtime_account)
        except AgolAccount.DoesNotExist:
            pass

        realtime_account.is_active = False
        realtime_account.datetime_deleted = datetime.utcnow().replace(
            tzinfo=timezone.utc)  # TODO: use shared function
        realtime_account.save()

        return Response(status=status.HTTP_200_OK)
Exemple #7
0
def delete_source_agol(agol_account=None, source=None, connection=None):
    "docs"

    if connection is None:
        try:
            connection = DataConnection.objects.get(custom_source=source,
                                                    agol_account=agol_account)
        except DataConnection.DoesNotExist:
            print("connection does not exist, no problem")
            return

    agol_account = connection.agol_account

    agol.delete_feature_layers(
        layer_ids=[connection.agol_layer_id],
        feature_service_url=agol_account.feature_service_url,
        agol_account=agol_account,
    )

    cloudwatch.delete_cloudwatch_rule(connection.cloudwatch_update_rule_name)
    connection.delete()
Exemple #8
0
    def post(self, request):
        serializer = serializers.DeleteDriveFileSerializer(data=request.data)
        serializer.is_valid(True)

        user = request.user

        account_uid = serializer.data["account_uid"]

        try:
            drive_account = DriveFileAccount.objects.get(uid=account_uid)
        except DriveFileAccount.DoesNotExist:
            return Response(
                {
                    "error": "account_does_not_exist",
                    "message": "account does not exist",
                },
                status=status.HTTP_400_BAD_REQUEST,
            )

        if drive_account.organization != request.user.organization:
            return Response(status=status.HTTP_403_FORBIDDEN)

        cloudwatch.delete_cloudwatch_rule(
            drive_account.cloudwatch_get_data_rule_name)

        drives_connections.delete_drives_kml(drive_account)

        # TODO: delete KML files

        try:
            drives_connections.delete_drives_agol(
                agol_account=user.agol_account, drive_account=drive_account)
        except AgolAccount.DoesNotExist:
            pass

        drive_account.is_active = False
        drive_account.save()

        return Response(status=status.HTTP_200_OK)
Exemple #9
0
    def post(self, request):

        user = request.user

        try:
            agol_account = user.agol_account
        except AgolAccount.DoesNotExist:
            pass
        else:
            connections = agol_account.connections.all()
            for connection in connections:
                cloudwatch.delete_cloudwatch_rule(
                    connection.cloudwatch_update_rule_name)

            now = datetime.utcnow().replace(tzinfo=timezone.utc)
            title = f'Caracal (Disconnected - {str(now).split(".")[0]})'

            arcgis = saw.ArcgisAPI(
                access_token=agol_account.oauth_access_token,
                refresh_token=agol_account.oauth_refresh_token,
                username=agol_account.username,
                client_id=settings.AGOL_CLIENT_ID)

            try:
                arcgis.services.update_feature_service(
                    agol_account.feature_service_id, title=title)
            except saw.exceptions.ArcGISException as e:
                print(
                    str(e)
                )  # likely agol account exists in db but no service in agol

            connections.delete()
            agol_account.delete()

        user.agol_account = None
        user.save()

        return Response(status=status.HTTP_200_OK)