Skip to content

Commit

Permalink
feat: fix lint errors and remove unused github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimds committed Mar 8, 2024
1 parent 8ea2345 commit 04fa6c3
Show file tree
Hide file tree
Showing 24 changed files with 721 additions and 640 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[flake8]
max-line-length = 88
extend-ignore = E203, E501
exclude =
.venv
migrations
nextjs
95 changes: 0 additions & 95 deletions .github/actions/cached-build/action.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/build_dev_image.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/mirror.yml

This file was deleted.

68 changes: 45 additions & 23 deletions hub/graphql/mutations.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
from typing import List, Optional

import strawberry
import strawberry_django
from strawberry import auto
from hub import models
from . import types
from typing import List, Optional
from strawberry.field_extensions import InputMutationExtension
from strawberry_django.permissions import IsAuthenticated
from strawberry_django.auth.utils import get_current_user
from strawberry.types.info import Info
import procrastinate.contrib.django.models
from strawberry_django.auth.utils import get_current_user
from strawberry_django.permissions import IsAuthenticated

from hub import models

from . import types


@strawberry.input
class IDObject:
id: str


@strawberry_django.input(models.ExternalDataSource, partial=True)
class ExternalDataSourceInput:
id: auto
name: auto
description: auto
organisation: auto


@strawberry_django.input(models.AirtableSource)
class AirtableSourceInput(ExternalDataSourceInput):
id: Optional[strawberry.scalars.ID]
Expand All @@ -29,77 +34,94 @@ class AirtableSourceInput(ExternalDataSourceInput):
table_id: auto
organisation: Optional[str]


@strawberry.input
class UpdateConfigDictInput:
source: str
source_path: str
destination_column: str


@strawberry_django.input(models.ExternalDataSourceUpdateConfig, partial=True)
class ExternalDataSourceUpdateConfigInput:
id: auto
external_data_source: types.ExternalDataSource
postcode_column: auto
enabled: auto
mapping: List[UpdateConfigDictInput]



@strawberry.mutation(extensions=[IsAuthenticated(), InputMutationExtension()])
async def create_organisation(info: Info, name: str, slug: Optional[str] = None, description: Optional[str] = None) -> types.Membership:
org = await models.Organisation.objects.acreate(name=name, slug=slug, description=description)
async def create_organisation(
info: Info, name: str, slug: Optional[str] = None, description: Optional[str] = None
) -> types.Membership:
org = await models.Organisation.objects.acreate(
name=name, slug=slug, description=description
)
user = get_current_user(info)
membership = await models.Membership.objects.acreate(user=user, organisation=org, role="owner")
membership = await models.Membership.objects.acreate(
user=user, organisation=org, role="owner"
)
return membership


@strawberry_django.input(models.Organisation, partial=True)
class OrganisationInputPartial:
id: auto
name: str
slug: Optional[str]
description: Optional[str]


@strawberry.mutation(extensions=[IsAuthenticated()])
def enable_update_config (config_id: str) -> models.ExternalDataSourceUpdateConfig:
def enable_update_config(config_id: str) -> models.ExternalDataSourceUpdateConfig:
config = models.ExternalDataSourceUpdateConfig.objects.get(id=config_id)
config.enable()
return config


@strawberry.mutation(extensions=[IsAuthenticated()])
def disable_update_config (config_id: str) -> models.ExternalDataSourceUpdateConfig:
def disable_update_config(config_id: str) -> models.ExternalDataSourceUpdateConfig:
config = models.ExternalDataSourceUpdateConfig.objects.get(id=config_id)
config.disable()
return config


@strawberry.mutation(extensions=[IsAuthenticated()])
def update_all(config_id: str) -> models.ExternalDataSourceUpdateConfig:
config = models.ExternalDataSourceUpdateConfig.objects.get(id=config_id)
job_id = config.schedule_update_all()
config.schedule_update_all()
return config


@strawberry.mutation(extensions=[IsAuthenticated()])
def refresh_webhook (config_id: str) -> models.ExternalDataSourceUpdateConfig:
def refresh_webhook(config_id: str) -> models.ExternalDataSourceUpdateConfig:
config = models.ExternalDataSourceUpdateConfig.objects.get(id=config_id)
if config.external_data_source.automated_webhooks:
config.refresh_webhook()
return config


@strawberry.mutation(extensions=[IsAuthenticated()])
def create_airtable_source(info: Info, data: AirtableSourceInput) -> models.AirtableSource:
def create_airtable_source(
info: Info, data: AirtableSourceInput
) -> models.AirtableSource:
user = get_current_user(info)
organisation = data.organisation
if isinstance(data.organisation, strawberry.unset.UnsetType) or data.organisation is None:
if (
isinstance(data.organisation, strawberry.unset.UnsetType)
or data.organisation is None
):
if user.memberships.first() is not None:
print("Assigning the user's default organisation")
organisation = user.memberships.first().organisation
else:
print("Making an organisation for this user")
organisation = models.Organisation.objects.create(
name=f"{user.username}'s organisation",
slug=f'{user.username}-org'
name=f"{user.username}'s organisation", slug=f"{user.username}-org"
)
models.Membership.objects.create(
user=user,
organisation=organisation,
role="owner"
user=user, organisation=organisation, role="owner"
)

return models.AirtableSource.objects.create(
Expand All @@ -108,5 +130,5 @@ def create_airtable_source(info: Info, data: AirtableSourceInput) -> models.Airt
table_id=data.table_id,
organisation=organisation,
name=data.name,
description=data.description
)
description=data.description,
)
Loading

0 comments on commit 04fa6c3

Please sign in to comment.