patch CSRF and CI
Some checks failed
ERP CI/CD Pipeline / test (push) Has been cancelled
ERP CI/CD Pipeline / Deploy (server git pull + compose) (push) Has been cancelled

This commit is contained in:
mariomitte
2026-07-10 23:00:06 +02:00
parent 88de1a503a
commit 4c9b6bba96
4 changed files with 69 additions and 16 deletions

View File

@@ -1,6 +1,24 @@
name: ERP CI Pipeline name: ERP CI/CD Pipeline
on: [push, pull_request] on:
push:
branches: [main, master]
paths:
- "backend/**"
- "frontend/**"
- "docker-compose*.yml"
- ".gitea/workflows/ci.yml"
pull_request:
branches: [main, master]
paths:
- "backend/**"
- "frontend/**"
- "docker-compose*.yml"
- ".gitea/workflows/ci.yml"
concurrency:
group: erp-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
test: test:
@@ -12,28 +30,42 @@ jobs:
POSTGRES_DB: erp_db POSTGRES_DB: erp_db
POSTGRES_PASSWORD: password POSTGRES_PASSWORD: password
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v5
with: with:
python-version: '3.11' python-version: "3.11"
- name: Install dependencies - name: Install deps
run: | run: |
pip install -r backend/requirements.txt pip install -r backend/requirements.txt
pip install pytest pytest-django pip install pytest pytest-django
- name: Run Unit Tests - name: Run tests
env: env:
DATABASE_URL: postgres://postgres:password@localhost:5432/erp_db DATABASE_URL: postgres://postgres:password@localhost:5432/erp_db
run: | run: |
# Pokrećemo testove iz našeg backend direktorija
pytest backend/modules/invoicing/tests/test_services.py pytest backend/modules/invoicing/tests/test_services.py
- name: Run Task Management Tests
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/erp_db
run: |
pytest backend/modules/task_management/tests/test_services.py pytest backend/modules/task_management/tests/test_services.py
deploy:
name: Deploy (server git pull + compose)
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master')
steps:
- name: SSH deploy
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: ${{ secrets.DEPLOY_PORT }}
script_stop: true
script: |
set -e
export DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}"
export DEPLOY_BRANCH="${{ github.ref_name }}"
/usr/local/bin/erp-deploy.sh

View File

@@ -115,7 +115,6 @@ CORS_ALLOW_CREDENTIALS = True
REST_FRAMEWORK = { REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ( 'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication', 'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
), ),
'DEFAULT_PERMISSION_CLASSES': ( 'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.IsAuthenticated',

View File

@@ -4,6 +4,18 @@ DEBUG = True
# ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'backend'] # ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'backend']
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
# CSRF trusted origins (env + poznate domene)
CSRF_TRUSTED_ORIGINS = [
origin.strip()
for origin in os.environ.get('CSRF_TRUSTED_ORIGINS', '').split(',')
if origin.strip()
] + [
'https://api-004.captain.mitteworkspace.cloud',
'https://serviseri-004.captain.mitteworkspace.cloud',
'http://localhost:4321',
'http://127.0.0.1:4321',
]
# SQLite za brzi lokalni razvoj (nema potrebe za instalacijom Postgresa na laptopu) # SQLite za brzi lokalni razvoj (nema potrebe za instalacijom Postgresa na laptopu)
# DATABASES = { # DATABASES = {
# 'default': { # 'default': {

View File

@@ -23,6 +23,16 @@ CSRF_COOKIE_SECURE = True
# Produkcijski CORS (samo domena na kojoj vrti Astro) # Produkcijski CORS (samo domena na kojoj vrti Astro)
CORS_ALLOWED_ORIGINS = os.environ.get('CORS_ALLOWED_ORIGINS', '').split(',') CORS_ALLOWED_ORIGINS = os.environ.get('CORS_ALLOWED_ORIGINS', '').split(',')
# csrf trusted origins za produkciju (env + poznate domene)
CSRF_TRUSTED_ORIGINS = [
origin.strip()
for origin in os.environ.get('CSRF_TRUSTED_ORIGINS', '').split(',')
if origin.strip()
] + [
'https://api-004.captain.mitteworkspace.cloud',
'https://serviseri-004.captain.mitteworkspace.cloud',
]
# Statika i Mediji # Statika i Mediji
STATIC_ROOT = '/app/staticfiles' STATIC_ROOT = '/app/staticfiles'
MEDIA_ROOT = '/app/media' MEDIA_ROOT = '/app/media'