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

Commit

Permalink
Merge pull request #289 from SELab-2/development
Browse files Browse the repository at this point in the history
Milestone 3
  • Loading branch information
DeruytterA authored May 21, 2023
2 parents 1a852af + ffd2174 commit f22e4f0
Show file tree
Hide file tree
Showing 208 changed files with 8,552 additions and 2,772 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/frontend"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/backend"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
26 changes: 23 additions & 3 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: backend-tests
run-name: backend-tests
on: [push]
jobs:
Backend-linter-and-tests:
Backend-tests:
runs-on: self-hosted
environment: django tests
strategy:
Expand All @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
Expand All @@ -32,7 +32,27 @@ jobs:
python manage.py migrate
python manage.py test
working-directory: ./backend

Backend-linter:
runs-on: self-hosted
environment: django tests
strategy:
max-parallel: 4
matrix:
python-version: [ 3.11 ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
working-directory: ./backend
- name: Run Linter
run: |
flake8 --ignore=F405,F403,E501 .
working-directory: ./backend
working-directory: ./backend
65 changes: 65 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: frontend-tests
run-name: frontend-tests
on: [push]
jobs:
Frontend-tests:
runs-on: self-hosted
environment: vue tests
strategy:
max-parallel: 4

steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: latest
- name: Empty EchoFetch directory
run: |
rm -rf EchoFetch
working-directory: ./frontend/src/api
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Setup EchoFetch
run: |
npm install
npm run build
working-directory: ./frontend/src/api/EchoFetch
- name: Install Dependencies
run: |
npm install --force
working-directory: ./frontend
- name: Create env file
run: |
echo "${{ vars.ENV }}" > ./.env.local
working-directory: ./frontend
- name: Run Tests
run: |
npm run test:unit
working-directory: ./frontend

Frontend-linter:
runs-on: self-hosted
environment: vue tests
strategy:
max-parallel: 4

steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: latest
- name: Empty EchoFetch directory
run: |
rm -rf EchoFetch
working-directory: ./frontend/src/api
- name: Install Dependencies
run: |
npm install --force
npm i -D @vue/cli-plugin-eslint @vue/eslint-config-typescript --force
working-directory: ./frontend
- name: Run Linter
run: |
npm run lint
working-directory: ./frontend
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ fabric.properties

# environment map
env

# coverage niet wordt meegepusht
coverage
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# Dr-Trottoir-5
# Dr-Trottoir-5

[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

> Een webapp gemaakt voor [Dr-Trottoir](https://drtrottoir.be/) om hun werk te structureren en automatiseren.
## Table of Contents

- [Features](#features)
- [Technologiën](#technologies)
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Features

- Nieuwe klanten en medewerkers toevoegen
- Rondes tonen aan de medewerkers
- Aanmaken/inplannen rondes
- Uitvoeren van een ronde
- Problemen tijdens uitvoeren terugsturen naar de klanten

## Technologies

De web app is gemaakt met deze technologiën

- [Vue.js](https://vuejs.org/) - Een progressief JavaScript-framework voor het bouwen van gebruikersinterfaces.
- [Django](https://www.djangoproject.com/) - Een high-level Python webframework.
- [Hugo Docsy](https://www.docsy.dev/) - Een Hugo-thema voor technische documentatiewebsites.


## Installation

- see the README.md files in the [frontend](frontend/README.md), [backend](backend/README.md) and [docs](docs/README.md) folders

## Usage

- see the README.md files in the [frontend](frontend/README.md), [backend](backend/README.md) and [docs](docs/README.md) folders


## License

This project is licensed under the [MIT License](LICENSE). You are free to use, modify, and distribute this project in accordance with the terms of the license.

8 changes: 8 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Dr-trottoir django backend

## Info
The django backend works with these extra modules

- django rest framework
- Easily making REST API's
- simpleJWT
- simple json web tokens for the cookies and authentication

## Setup

The first thing to do is to clone the repository:
Expand Down
5 changes: 4 additions & 1 deletion backend/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
EMAIL=[email protected]
EMAIL_PASSWORD=my_app_password
EMAIL_PASSWORD=my_app_password
DEBUG_MODE=True
SECRET_KEY=django-insecure-mz0gymvj@n5wl2p0yau(vj0e3jdx_wok78+ead*=p4)$w)g5(z
SECURE_COOKIES=True
9 changes: 6 additions & 3 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-mz0gymvj@n5wl2p0yau(vj0e3jdx_wok78+ead*=p4)$w)g5(z' # TODO generate new one and keep secret
SECRET_KEY = env.get_value('SECRET_KEY', str, 'django-insecure-mz0gymvj@n5wl2p0yau(vj0e3jdx_wok78+ead*=p4)$w)g5(z')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

DEBUG = env.get_value('DEBUG_MODE', bool, False)

ALLOWED_HOSTS = [
'sel2-5.ugent.be', '157.193.244.115',
Expand All @@ -42,6 +43,8 @@
"http://192.168.178.34:8080",
"http://localhost:8081",
"http://192.168.178.34:8081",
"http://localhost:8082",
"http://192.168.178.34:8082",
"http://127.0.0.1:8080",
]

Expand Down Expand Up @@ -213,7 +216,7 @@
'AUTH_COOKIE': 'access_token', # Cookie name. Enables cookies if value is set.
'REFRESH_COOKIE': 'refresh',
'AUTH_COOKIE_DOMAIN': None, # A string like "example.com", or None for standard domain cookie.
'AUTH_COOKIE_SECURE': False, # Whether the auth cookies should be secure (https:// only). TODO TRUE FOR PRODUCTION
'AUTH_COOKIE_SECURE': env.get_value('SECURE_COOKIES', bool, False), # Whether the auth cookies should be secure (https:// only).
'AUTH_COOKIE_HTTP_ONLY': True, # Http only cookie flag.It's not fetch by javascript.
'AUTH_COOKIE_PATH': '/', # The path of the auth cookie.
'AUTH_COOKIE_SAMESITE': 'Lax',
Expand Down
4 changes: 2 additions & 2 deletions backend/backend/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.conf import settings
from django.views.static import serve
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.views import APIView


class MediaView(APIView):
permission_classes = [IsAuthenticated]
permission_classes = [IsAuthenticatedOrReadOnly]

def get(self, request, path):
return serve(request, path, document_root=settings.MEDIA_ROOT)
71 changes: 65 additions & 6 deletions backend/exceptions/exceptionHandler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime

from rest_framework import serializers

from django.db import models
from rest_framework.serializers import ValidationError

from trashtemplates.models import Status


class ExceptionHandler:
Expand All @@ -20,6 +21,10 @@ class ExceptionHandler:
blank_error = "Veld kan niet leeg zijn."
integer_error = "Veld moet een positief getal zijn."
boolean_error = "Veld moet een Boolse waarde zijn."
wrong_email_error = "Verkeerd email adres."
not_equal_error = "Waarde komt niet overeen."
inactive_error = "Object is verwijderd."
vervangen_error = "Kan geen aanpassingen doen aan vervangen template"

def __init__(self):
self.errors = []
Expand All @@ -28,9 +33,9 @@ def __init__(self):
def check(self):
self.checked = True
if len(self.errors) > 0:
raise serializers.ValidationError({
raise ValidationError({
"errors": self.errors
})
}, code='invalid')

def __del__(self):
if not self.checked:
Expand Down Expand Up @@ -79,8 +84,13 @@ def check_time_value(self, value, fieldname):
self.checked = False
if value is None:
return True
return self.check_time_format(value, fieldname, "%H:%M",
ExceptionHandler.time_format_error)
if not self.check_time_format(value, fieldname, "%H:%M", ExceptionHandler.time_format_error):
if self.check_time_format(value, fieldname, "%H:%M:%S", ExceptionHandler.time_format_error):
self.errors.pop()
return True
else:
return False
return True

def check_time_value_required(self, value, fieldname):
if not self.check_required(value, fieldname):
Expand Down Expand Up @@ -209,3 +219,52 @@ def check_not_blank_required(self, value, fieldname):
if not self.check_required(value, fieldname):
return False
return self.check_not_blank(value, fieldname)

def check_email(self, email, cls: models.Model):
self.checked = False
if email is None:
return True
try:
cls.objects.get(email=email)
return True
except cls.DoesNotExist:
self.errors.append({
"message": ExceptionHandler.wrong_email_error,
"field": "email"
})
return False

def check_equal(self, value1, value2, fieldname):
self.checked = False

if value1 != value2:
self.errors.append({
"message": ExceptionHandler.not_equal_error,
"field": fieldname
})
return False
return True

def check_not_inactive(self, template, fieldname):
self.checked = False
if template is None:
return True

if template.status == Status.INACTIEF:
self.errors.append({
"message": ExceptionHandler.inactive_error,
"field": fieldname
})
return False

def check_vervangen(self, template):
self.checked = False
if template is None:
return True

if template.status == Status.VERVANGEN:
self.errors.append({
"message": ExceptionHandler.vervangen_error,
"field": "template"
})
return False
Loading

0 comments on commit f22e4f0

Please sign in to comment.