Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
refactor files
Browse files Browse the repository at this point in the history
  • Loading branch information
MJedr committed Oct 18, 2023
1 parent cbe6acb commit c42a845
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

version: 2
updates:
- package-ecosystem: "pip" # pip supports also poetry https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
- package-ecosystem: "pip" # pip supports also poetry https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
interval: "monthly"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:
type=ref,event=pr
type=ref,event=tag
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
password: ${{ secrets.HARBOR_PASSWORD }}
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
--env POSTGRES_PASSWORD=inspire
--env POSTGRES_HOST=127.0.0.1
${{ inputs.image }}
run pytest
run pytest
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- name: black
uses: psf/black@stable
with:
options: '--verbose'
options: "--verbose"

- name: run flake8
uses: julianwachholz/flake8-action@v2
with:
checkName: 'flake8'
checkName: "flake8"
2 changes: 1 addition & 1 deletion .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
lint:
uses: ./.github/workflows/lint.yml
with:
ref: ${{ github.ref }}
ref: ${{ github.ref }}
test:
uses: ./.github/workflows/test.yml
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
uses: ./.github/workflows/integration-tests.yml
with:
ref: ${{ inputs.ref }}
image: "registry.cern.ch/cern-sis/inspire/backoffice@${{ needs.build.outputs.image-id }}"
image: "registry.cern.ch/cern-sis/inspire/backoffice@${{ needs.build.outputs.image-id }}"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ repos:
rev: "3.9.2"
hooks:
- id: flake8
args: ["--config=backend/setup.cfg"]
args: ["--config=.flake8"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name):
# site is created.
# To avoid this, we need to manually update DB sequence and make sure it's
# greater than the maximum value.
max_id = site_model.objects.order_by('-id').first().id
max_id = site_model.objects.order_by("-id").first().id
with connection.cursor() as cursor:
cursor.execute("SELECT last_value from django_site_id_seq")
(current_id,) = cursor.fetchone()
Expand Down
3 changes: 0 additions & 3 deletions backoffice/management/admin.py

This file was deleted.

2 changes: 1 addition & 1 deletion backoffice/management/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class ManagementConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "management"
name = "backoffice.management"
5 changes: 2 additions & 3 deletions backoffice/management/groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth.models import Group


admin_group, created = Group.objects.get_or_create(name='admin')
curator_group, created = Group.objects.get_or_create(name='curator')
admin_group, created = Group.objects.get_or_create(name="admin")
curator_group, created = Group.objects.get_or_create(name="curator")
3 changes: 0 additions & 3 deletions backoffice/management/models.py

This file was deleted.

2 changes: 1 addition & 1 deletion backoffice/management/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def has_object_permission(self, request, view, obj):


class IsAdminOrCuratorUser(PermissionCheckBase):
required_groups = ['admin', 'curator']
required_groups = ["admin", "curator"]
26 changes: 13 additions & 13 deletions backoffice/management/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.test import TestCase
from rest_framework.response import Response
from rest_framework.test import APIRequestFactory, force_authenticate
from rest_framework.views import APIView
from rest_framework.response import Response
from django.test import TestCase
from management.permissions import IsAdminOrCuratorUser
from django.contrib.auth import get_user_model

from backoffice.management.permissions import IsAdminOrCuratorUser

User = get_user_model()

Expand All @@ -19,27 +19,27 @@ def get(self, request):

class PermissionCheckTests(TestCase):
def setUp(self):
self.user = User.objects.create_user(email='[email protected]', password='testpassword')
self.admin_group, _ = Group.objects.get_or_create(name='admin')
self.curator_group, _ = Group.objects.get_or_create(name='curator')
self.user = User.objects.create_user(email="[email protected]", password="testpassword")

self.admin_group, _ = Group.objects.get_or_create(name="admin")
self.curator_group, _ = Group.objects.get_or_create(name="curator")

def test_user_in_required_group(self):
self.user.groups.add(self.admin_group)

factory = APIRequestFactory()
request = factory.get('/mock/')
request = factory.get("/mock/")
force_authenticate(request, user=self.user)

view = MockView.as_view()
response = view(request)
self.assertEqual(response.status_code, 200)

def test_user_not_in_required_group(self):
factory = APIRequestFactory()
request = factory.get('/mock/')
request = factory.get("/mock/")
force_authenticate(request, user=self.user)

view = MockView.as_view()
response = view(request)
self.assertEqual(response.status_code, 403)
3 changes: 0 additions & 3 deletions backoffice/management/views.py

This file was deleted.

1 change: 1 addition & 0 deletions backoffice/users/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

if typing.TYPE_CHECKING:
from allauth.socialaccount.models import SocialLogin

from backoffice.users.models import User


Expand Down
2 changes: 1 addition & 1 deletion backoffice/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import admin as auth_admin
from django.contrib.auth import get_user_model, decorators
from django.contrib.auth import decorators, get_user_model
from django.utils.translation import gettext_lazy as _

from backoffice.users.forms import UserAdminChangeForm, UserAdminCreationForm
Expand Down
1 change: 0 additions & 1 deletion backoffice/users/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from backoffice.users.models import User as UserType


User = get_user_model()


Expand Down
16 changes: 4 additions & 12 deletions backoffice/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class Migration(migrations.Migration):
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
models.DateTimeField(blank=True, null=True, verbose_name="last login"),
),
(
"is_superuser",
Expand All @@ -44,9 +42,7 @@ class Migration(migrations.Migration):
),
(
"email",
models.EmailField(
unique=True, max_length=254, verbose_name="email address"
),
models.EmailField(unique=True, max_length=254, verbose_name="email address"),
),
(
"is_staff",
Expand All @@ -66,15 +62,11 @@ class Migration(migrations.Migration):
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
models.DateTimeField(default=django.utils.timezone.now, verbose_name="date joined"),
),
(
"name",
models.CharField(
blank=True, max_length=255, verbose_name="Name of User"
),
models.CharField(blank=True, max_length=255, verbose_name="Name of User"),
),
(
"groups",
Expand Down
6 changes: 1 addition & 5 deletions backoffice/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
from backoffice.users.forms import UserAdminChangeForm
from backoffice.users.models import User
from backoffice.users.tests.factories import UserFactory
from backoffice.users.views import (
UserRedirectView,
UserUpdateView,
user_detail_view,
)
from backoffice.users.views import UserRedirectView, UserUpdateView, user_detail_view

pytestmark = pytest.mark.django_db

Expand Down
6 changes: 1 addition & 5 deletions backoffice/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from django.urls import path

from backoffice.users.views import (
user_detail_view,
user_redirect_view,
user_update_view,
)
from backoffice.users.views import user_detail_view, user_redirect_view, user_update_view

app_name = "users"
urlpatterns = [
Expand Down
3 changes: 0 additions & 3 deletions backoffice/workflows/admin.py

This file was deleted.

5 changes: 3 additions & 2 deletions backoffice/workflows/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework import serializers
from workflows.models import Workflow

from backoffice.workflows.models import Workflow


class WorkflowSerializer(serializers.ModelSerializer):
class Meta:
model = Workflow
fields = '__all__'
fields = "__all__"
7 changes: 3 additions & 4 deletions backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from workflows.models import Workflow
from rest_framework import viewsets

from backoffice.workflows.models import Workflow

from rest_framework import viewsets
from .serializers import WorkflowSerializer


Expand All @@ -10,8 +10,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
serializer_class = WorkflowSerializer

def get_queryset(self):
status = self.request.query_params.get('status')
status = self.request.query_params.get("status")
if status:
return self.queryset.filter(status__status=status)
return self.queryset

2 changes: 1 addition & 1 deletion backoffice/workflows/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class WorkflowsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "workflows"
name = "backoffice.workflows"
22 changes: 9 additions & 13 deletions backoffice/workflows/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
from django.db import models
import uuid

from django.db import models


class Workflow(models.Model):
PREPROCESSING = 'PREPROCESSING'
APPROVAL = 'APPROVAL'
POSTPROCESSING = 'POSTPROCESSING'
PREPROCESSING = "PREPROCESSING"
APPROVAL = "APPROVAL"
POSTPROCESSING = "POSTPROCESSING"
STATUS_CHOICES = (
(PREPROCESSING, 'Preprocessing'),
(APPROVAL, 'Approval'),
(POSTPROCESSING, 'Postprocessing'),
(PREPROCESSING, "Preprocessing"),
(APPROVAL, "Approval"),
(POSTPROCESSING, "Postprocessing"),
)
id = models.UUIDField(
primary_key = True,
default = uuid.uuid4,
editable = False
)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

data = models.JSONField()
status = models.CharField(
Expand All @@ -25,4 +22,3 @@ class Workflow(models.Model):
)
core = models.BooleanField()
is_update = models.BooleanField()

3 changes: 0 additions & 3 deletions backoffice/workflows/tests.py

This file was deleted.

17 changes: 9 additions & 8 deletions backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
from rest_framework.test import APIClient
from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.test import TestCase
from django.apps import apps
from rest_framework.test import APIClient

User = get_user_model()
Workflow = apps.get_model(app_label='workflows', model_name='Workflow')
Workflow = apps.get_model(app_label="workflows", model_name="Workflow")


class TestWorkflowViewSet(TestCase):
endpoint = '/api/workflows/'
endpoint = "/api/workflows/"

def setUp(self):
self.curator_group = Group.objects.create(name="curator")
self.admin_group = Group.objects.create(name="admin")

self.curator = User.objects.create_user(email='[email protected]', password='12345')
self.admin = User.objects.create_user(email='[email protected]', password='12345')
self.user = User.objects.create_user(email='[email protected]', password='12345')
self.curator = User.objects.create_user(email="[email protected]", password="12345")
self.admin = User.objects.create_user(email="[email protected]", password="12345")
self.user = User.objects.create_user(email="[email protected]", password="12345")

self.curator.groups.add(self.curator_group)
self.admin.groups.add(self.admin_group)

self.api_client = APIClient()
self.workflow = Workflow.objects.create(data={}, status='APPROVAL', core=True, is_update=False)
self.workflow = Workflow.objects.create(data={}, status="APPROVAL", core=True, is_update=False)

def test_list_curator(self):
self.api_client.force_authenticate(user=self.curator)
Expand Down
3 changes: 1 addition & 2 deletions backoffice/workflows/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.contrib import admin
from django.urls import include, path


urlpatterns = [
path("workflows/", include("workflows.urls")),
path("admin/", admin.site.urls),
]
]
3 changes: 1 addition & 2 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from backoffice.users.api.views import UserViewSet
from backoffice.workflows.api.views import WorkflowViewSet


if settings.DEBUG:
router = DefaultRouter()
else:
Expand All @@ -13,7 +12,7 @@
router.register("users", UserViewSet)

# Workflows
router.register("workflows", WorkflowViewSet, basename='workflows')
router.register("workflows", WorkflowViewSet, basename="workflows")

app_name = "api"
urlpatterns = router.urls
Loading

0 comments on commit c42a845

Please sign in to comment.