Compare commits
2 Commits
b7f50ce30f
...
fix/argocd
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d9d01c240 | |||
| b290d39d64 |
@@ -60,7 +60,7 @@ jobs:
|
||||
chmod +x /usr/local/bin/yq
|
||||
yq --version
|
||||
|
||||
- name: Read ${{ matrix.description }} image from deployment
|
||||
- name: Read ${{ matrix.description }} image from deployment (old vs new)
|
||||
id: img
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -211,17 +211,28 @@ jobs:
|
||||
echo "ERROR: Found $ctype \"$cname\" image repo is \"$new_repo\" but expected \"$expected_repo\""
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "${old_image:-}" ]; then
|
||||
old_tag="${old_image##*:}"
|
||||
else
|
||||
old_tag=""
|
||||
fi
|
||||
|
||||
registry="$(echo "$new_repo" | awk -F/ '{print $1}')"
|
||||
|
||||
{
|
||||
echo "changed=$([ "$old_tag" != "$new_tag" ] && echo true || echo false)"
|
||||
echo "new_image=$new_image"
|
||||
echo "new_repo=$new_repo"
|
||||
echo "new_tag=$new_tag"
|
||||
echo "registry=$registry"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Skip if tag unchanged
|
||||
if: steps.img.outputs.changed != 'true'
|
||||
run: echo "${{ matrix.description }} image tag unchanged; skipping build."
|
||||
|
||||
- name: Check if image exists on registry
|
||||
if: steps.img.outputs.changed == 'true'
|
||||
id: check_image
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -256,15 +267,15 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Skip if image already exists
|
||||
if: steps.check_image.outputs.exists == 'true'
|
||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'true'
|
||||
run: echo "${{ matrix.description }} image ${{ steps.img.outputs.new_image }} already exists on registry; skipping build."
|
||||
|
||||
- name: Set up Buildx
|
||||
if: steps.check_image.outputs.exists == 'false'
|
||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to registry
|
||||
if: steps.check_image.outputs.exists == 'false'
|
||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ steps.img.outputs.registry }}
|
||||
@@ -272,7 +283,7 @@ jobs:
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and push ${{ matrix.description }} (exact tag from deployment)
|
||||
if: steps.check_image.outputs.exists == 'false'
|
||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ${{ matrix.build_context }}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
on:
|
||||
push:
|
||||
# branches:
|
||||
# - main
|
||||
# - development
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
name: SonarQube Scan
|
||||
jobs:
|
||||
sonarqube:
|
||||
name: SonarQube Trigger
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checking out
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: |
|
||||
coverage run --source='.' manage.py test
|
||||
coverage xml
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Cache SonarQube packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.sonar/cache
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
|
||||
- name: Download and setup SonarScanner
|
||||
run: |
|
||||
mkdir -p $HOME/.sonar
|
||||
wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
|
||||
unzip -q sonar-scanner-cli-5.0.1.3006-linux.zip -d $HOME/.sonar/
|
||||
echo "$HOME/.sonar/sonar-scanner-5.0.1.3006-linux/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Verify Java version
|
||||
run: java -version
|
||||
|
||||
- name: SonarQube Scan
|
||||
env:
|
||||
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
|
||||
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
||||
run: |
|
||||
sonar-scanner \
|
||||
-Dsonar.projectKey=${{ github.event.repository.name }} \
|
||||
-Dsonar.sources=. \
|
||||
-Dsonar.host.url=${SONAR_HOST_URL} \
|
||||
-Dsonar.token=${SONAR_TOKEN} \
|
||||
-Dsonar.python.coverage.reportPaths=coverage.xml
|
||||
16
Dockerfile
16
Dockerfile
@@ -1,4 +1,4 @@
|
||||
FROM python:3.14 AS baustelle
|
||||
FROM python:3.13-slim AS baustelle
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
@@ -7,21 +7,22 @@ RUN pip install --upgrade pip
|
||||
COPY requirements.txt /app/
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
FROM python:3.14-slim
|
||||
FROM python:3.13-slim
|
||||
RUN useradd -m -r appuser && \
|
||||
mkdir /app && \
|
||||
chown -R appuser /app
|
||||
|
||||
COPY --from=baustelle /usr/local/lib/python3.14/site-packages/ /usr/local/lib/python3.14/site-packages/
|
||||
COPY --from=baustelle /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
|
||||
COPY --from=baustelle /usr/local/bin/ /usr/local/bin/
|
||||
RUN rm /usr/bin/tar /usr/lib/x86_64-linux-gnu/libncur*
|
||||
RUN rm /usr/bin/tar
|
||||
RUN rm /usr/lib/x86_64-linux-gnu/libncur*
|
||||
WORKDIR /app
|
||||
COPY --chown=appuser:appuser . .
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
USER appuser
|
||||
EXPOSE 8000
|
||||
RUN rm -rvf /app/Dockerfile* \
|
||||
RUN rm -rf /app/Dockerfile* \
|
||||
/app/README.md \
|
||||
/app/argocd \
|
||||
/app/k8s \
|
||||
@@ -30,8 +31,7 @@ RUN rm -rvf /app/Dockerfile* \
|
||||
/app/requirements.txt \
|
||||
/app/node_modules \
|
||||
/app/*.json \
|
||||
/app/scripts
|
||||
/app/test_*.py && \
|
||||
python3 /app/manage.py collectstatic --noinput
|
||||
/app/test_*.py
|
||||
RUN python3 manage.py collectstatic
|
||||
CMD ["gunicorn","--bind","0.0.0.0:8000","--workers","3","VorgabenUI.wsgi:application"]
|
||||
|
||||
|
||||
95
Documentation/ARGOCD-INGRESS-FIX.md
Normal file
95
Documentation/ARGOCD-INGRESS-FIX.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# ArgoCD Ingress "Progressing" State Fix
|
||||
|
||||
## Problem
|
||||
|
||||
The `django` Ingress resource in the `vorgabenui` namespace was stuck in "Progressing" state in ArgoCD and would not transition to "Healthy".
|
||||
|
||||
### Root Cause
|
||||
|
||||
ArgoCD determines Ingress health by checking if the `status.loadBalancer.ingress` field is populated with an IP address or hostname. Without this field, the Ingress is considered "Progressing" indefinitely.
|
||||
|
||||
The issue occurred because **Traefik was not configured to report its IP address** in the Ingress status field.
|
||||
|
||||
## Solution
|
||||
|
||||
Two changes were made to fix this issue:
|
||||
|
||||
### 1. Update Ingress Annotation (Applied)
|
||||
|
||||
**File**: `argocd/ingress.yaml`
|
||||
|
||||
**Change**:
|
||||
```yaml
|
||||
# Before
|
||||
annotations:
|
||||
argocd.argoproj.io/ignore-healthcheck: "true"
|
||||
|
||||
# After
|
||||
annotations:
|
||||
argocd.argoproj.io/sync-wave: "1"
|
||||
```
|
||||
|
||||
**Rationale**:
|
||||
- The `ignore-healthcheck` annotation was causing ArgoCD to not monitor the Ingress health at all
|
||||
- The `sync-wave: "1"` annotation ensures the Ingress syncs after the Deployment and Service are ready (which have default sync-wave of 0)
|
||||
- This allows ArgoCD to properly assess the Ingress health status
|
||||
|
||||
### 2. Configure Traefik to Report Ingress Status (Cluster Patch)
|
||||
|
||||
**Patch Command**:
|
||||
```bash
|
||||
kubectl patch deployment traefik -n traefik --type='json' \
|
||||
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--providers.kubernetesingress.ingressendpoint.publishedservice=traefik/traefik"}]'
|
||||
```
|
||||
|
||||
**Configuration Flag Added**:
|
||||
```
|
||||
--providers.kubernetesingress.ingressendpoint.publishedservice=traefik/traefik
|
||||
```
|
||||
|
||||
**Rationale**:
|
||||
This flag tells Traefik to:
|
||||
- Watch for changes to Ingress resources in the cluster
|
||||
- Monitor the Service `traefik/traefik` (the Traefik LoadBalancer service)
|
||||
- Automatically populate `status.loadBalancer.ingress[].ip` with the service's external IP address
|
||||
- Allow ArgoCD to detect when the Ingress has been assigned an IP and transition to "Healthy"
|
||||
|
||||
## Result
|
||||
|
||||
✅ **Status**: RESOLVED
|
||||
|
||||
**Current State**:
|
||||
- Ingress Address: `192.168.17.53` (Traefik LoadBalancer IP)
|
||||
- Ingress Health: Healthy
|
||||
- ArgoCD Application Health: Healthy
|
||||
- Accessible at: `http://vorgabenportal.knowyoursecurity.com/`
|
||||
|
||||
## Verification
|
||||
|
||||
To verify the fix is working:
|
||||
|
||||
```bash
|
||||
# Check Ingress status
|
||||
kubectl get ingress django -n vorgabenui -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
|
||||
# Should output: 192.168.17.53
|
||||
|
||||
# Check ArgoCD application health
|
||||
kubectl get application vorgabenui -n argocd -o jsonpath='{.status.health.status}'
|
||||
# Should output: Healthy
|
||||
|
||||
# Check Traefik configuration
|
||||
kubectl get deploy traefik -n traefik -o jsonpath='{.spec.template.spec.containers[0].args}' | jq 'map(select(. | contains("publishedservice")))'
|
||||
# Should output the publishedservice flag
|
||||
```
|
||||
|
||||
## Documentation Location
|
||||
|
||||
The Traefik configuration patch is documented in:
|
||||
- `argocd/traefik-middleware.yaml` - ConfigMap with patch details and rationale
|
||||
|
||||
## Notes for Future Maintenance
|
||||
|
||||
- If Traefik is upgraded or redeployed via Helm, ensure the `--providers.kubernetesingress.ingressendpoint.publishedservice=traefik/traefik` flag is preserved
|
||||
- The flag must point to the correct LoadBalancer Service that has an external IP
|
||||
- In this case, it's `traefik/traefik` (namespace/service-name) with external IP `192.168.17.53`
|
||||
- If the Traefik service configuration changes, this flag may need adjustment
|
||||
@@ -540,5 +540,5 @@ digraph {
|
||||
Bei Fragen oder Problemen mit Diagrammen:
|
||||
1. Code auf https://kroki.io/ testen
|
||||
2. Syntax-Dokumentation des jeweiligen Diagrammtyps konsultieren
|
||||
3. (Nur mit Shell-Zugriff auf Kubernetes-Pod möglich): Diagramm-Cache leeren: `python manage.py clear_diagram_cache`
|
||||
3. Diagramm-Cache leeren: `python manage.py clear_diagram_cache`
|
||||
4. Bei technischen Problemen: Information Security Management BIT kontaktieren
|
||||
|
||||
@@ -24,7 +24,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
SECRET_KEY = os.environ.get("SECRET_KEY")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = bool(os.environ.get("DEBUG", default=0))
|
||||
DEBUG = bool(os.environ.get("DEBUG", default=0)
|
||||
|
||||
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS","127.0.0.1").split(",")
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ USE_TZ = True
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
#STATIC_ROOT="/home/adebaumann/VorgabenUI/staticfiles/"
|
||||
STATIC_ROOT="staticfiles/"
|
||||
STATIC_ROOT="/app/staticfiles/"
|
||||
STATICFILES_DIRS= (
|
||||
os.path.join(BASE_DIR,"static"),
|
||||
)
|
||||
@@ -151,24 +151,6 @@ LOGIN_URL = 'login'
|
||||
LOGIN_REDIRECT_URL = '/'
|
||||
LOGOUT_REDIRECT_URL = 'login'
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
"OPTIONS": {
|
||||
"min_length": 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
#LOGGING = {
|
||||
# "version": 1,
|
||||
# "handlers" :{
|
||||
|
||||
@@ -18,14 +18,14 @@ spec:
|
||||
fsGroupChangePolicy: "OnRootMismatch"
|
||||
initContainers:
|
||||
- name: loader
|
||||
image: git.baumann.gr/adebaumann/vui-data-loader:0.11
|
||||
image: git.baumann.gr/adebaumann/vui-data-loader:0.10
|
||||
command: [ "sh","-c","cp -n preload/preload.sqlite3 /data/db.sqlite3; chown -R 999:999 /data; ls -la /data; sleep 10; exit 0" ]
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
containers:
|
||||
- name: web
|
||||
image: git.baumann.gr/adebaumann/vui:0.974
|
||||
image: git.baumann.gr/adebaumann/vui:0.961
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
|
||||
@@ -4,7 +4,7 @@ metadata:
|
||||
name: django
|
||||
namespace: vorgabenui
|
||||
annotations:
|
||||
argocd.argoproj.io/ignore-healthcheck: "true"
|
||||
argocd.argoproj.io/sync-wave: "1"
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
|
||||
24
argocd/traefik-middleware.yaml
Normal file
24
argocd/traefik-middleware.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# Traefik configuration to enable Ingress status updates
|
||||
# This patch configures Traefik to report its IP address in Ingress.status.loadBalancer
|
||||
# which is required for ArgoCD to properly assess Ingress health status
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: traefik-patch-note
|
||||
namespace: traefik
|
||||
annotations:
|
||||
description: "Manual patch applied to traefik deployment to enable ingress status reporting"
|
||||
data:
|
||||
patch-command: |
|
||||
kubectl patch deployment traefik -n traefik --type='json' \
|
||||
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--providers.kubernetesingress.ingressendpoint.publishedservice=traefik/traefik"}]'
|
||||
|
||||
rationale: |
|
||||
The Ingress resource needs its status.loadBalancer.ingress field populated for ArgoCD to assess health.
|
||||
Without this, Ingress resources remain in "Progressing" state indefinitely.
|
||||
|
||||
This flag tells Traefik to:
|
||||
- Monitor the specified Service (traefik/traefik - the LoadBalancer service)
|
||||
- Automatically update Ingress.status.loadBalancer with the service's external IP
|
||||
- Allow ArgoCD to transition the Ingress from "Progressing" to "Healthy"
|
||||
Binary file not shown.
BIN
data/db.sqlite3
BIN
data/db.sqlite3
Binary file not shown.
@@ -94,17 +94,9 @@ class EinleitungInline(NestedStackedInline):
|
||||
|
||||
class VorgabeForm(forms.ModelForm):
|
||||
referenzen = TreeNodeMultipleChoiceField(queryset=Referenz.objects.all(), required=False)
|
||||
|
||||
class Meta:
|
||||
model = Vorgabe
|
||||
fields = '__all__'
|
||||
|
||||
def clean_thema(self):
|
||||
"""Validate that thema is provided."""
|
||||
thema = self.cleaned_data.get('thema')
|
||||
if not thema:
|
||||
raise forms.ValidationError('Thema ist ein Pflichtfeld. Bitte wählen Sie ein Thema aus.')
|
||||
return thema
|
||||
|
||||
class VorgabeInline(SortableInlineAdminMixin, NestedStackedInline):
|
||||
model = Vorgabe
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
import xml.etree.ElementTree as ET
|
||||
from datetime import datetime
|
||||
from dokumente.models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Checklistenfrage
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Export all dokumente as XML'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--output',
|
||||
type=str,
|
||||
help='Output file path (default: stdout)',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
dokumente = Dokument.objects.filter(aktiv=True).prefetch_related(
|
||||
'autoren', 'pruefende', 'vorgaben__thema',
|
||||
'vorgaben__referenzen', 'vorgaben__stichworte',
|
||||
'vorgaben__checklistenfragen', 'vorgaben__vorgabekurztext_set',
|
||||
'vorgaben__vorgabelangtext_set', 'geltungsbereich_set',
|
||||
'einleitung_set', 'changelog__autoren'
|
||||
).order_by('nummer')
|
||||
|
||||
root = ET.Element('Vorgabendokumente')
|
||||
|
||||
for dokument in dokumente:
|
||||
doc_element = ET.SubElement(root, 'Vorgabendokument')
|
||||
|
||||
ET.SubElement(doc_element, 'Typ').text = dokument.dokumententyp.name if dokument.dokumententyp else ""
|
||||
ET.SubElement(doc_element, 'Nummer').text = dokument.nummer
|
||||
ET.SubElement(doc_element, 'Name').text = dokument.name
|
||||
|
||||
autoren_element = ET.SubElement(doc_element, 'Autoren')
|
||||
for autor in dokument.autoren.all():
|
||||
ET.SubElement(autoren_element, 'Autor').text = autor.name
|
||||
|
||||
pruefende_element = ET.SubElement(doc_element, 'Pruefende')
|
||||
for pruefender in dokument.pruefende.all():
|
||||
ET.SubElement(pruefende_element, 'Pruefender').text = pruefender.name
|
||||
|
||||
gueltigkeit_element = ET.SubElement(doc_element, 'Gueltigkeit')
|
||||
ET.SubElement(gueltigkeit_element, 'Von').text = dokument.gueltigkeit_von.strftime("%Y-%m-%d") if dokument.gueltigkeit_von else ""
|
||||
ET.SubElement(gueltigkeit_element, 'Bis').text = dokument.gueltigkeit_bis.strftime("%Y-%m-%d") if dokument.gueltigkeit_bis else None
|
||||
|
||||
ET.SubElement(doc_element, 'SignaturCSO').text = dokument.signatur_cso
|
||||
|
||||
geltungsbereich_sections = dokument.geltungsbereich_set.all().order_by('order')
|
||||
if geltungsbereich_sections:
|
||||
geltungsbereich_element = ET.SubElement(doc_element, 'Geltungsbereich')
|
||||
abschnitt_element = ET.SubElement(geltungsbereich_element, 'Abschnitt')
|
||||
for gb in geltungsbereich_sections:
|
||||
section = ET.SubElement(abschnitt_element, 'Teil')
|
||||
section.set('typ', gb.abschnitttyp.abschnitttyp if gb.abschnitttyp else "text")
|
||||
section.text = gb.inhalt
|
||||
|
||||
einleitung_sections = dokument.einleitung_set.all().order_by('order')
|
||||
if einleitung_sections:
|
||||
einleitung_element = ET.SubElement(doc_element, 'Einleitung')
|
||||
abschnitt_element = ET.SubElement(einleitung_element, 'Abschnitt')
|
||||
for ei in einleitung_sections:
|
||||
section = ET.SubElement(abschnitt_element, 'Teil')
|
||||
section.set('typ', ei.abschnitttyp.abschnitttyp if ei.abschnitttyp else "text")
|
||||
section.text = ei.inhalt
|
||||
|
||||
ET.SubElement(doc_element, 'Ziel').text = ""
|
||||
ET.SubElement(doc_element, 'Grundlagen').text = ""
|
||||
|
||||
changelog_element = ET.SubElement(doc_element, 'Changelog')
|
||||
for cl in dokument.changelog.all().order_by('-datum'):
|
||||
entry = ET.SubElement(changelog_element, 'Eintrag')
|
||||
ET.SubElement(entry, 'Datum').text = cl.datum.strftime("%Y-%m-%d")
|
||||
autoren = ET.SubElement(entry, 'Autoren')
|
||||
for autor in cl.autoren.all():
|
||||
ET.SubElement(autoren, 'Autor').text = autor.name
|
||||
ET.SubElement(entry, 'Aenderung').text = cl.aenderung
|
||||
|
||||
anhaenge_element = ET.SubElement(doc_element, 'Anhaenge')
|
||||
ET.SubElement(anhaenge_element, 'Anhang').text = dokument.anhaenge
|
||||
|
||||
ET.SubElement(doc_element, 'Verantwortlich').text = "Information Security Management BIT"
|
||||
ET.SubElement(doc_element, 'Klassifizierung').text = ""
|
||||
|
||||
glossar_element = ET.SubElement(doc_element, 'Glossar')
|
||||
|
||||
vorgaben_element = ET.SubElement(doc_element, 'Vorgaben')
|
||||
|
||||
for vorgabe in dokument.vorgaben.all().order_by('order'):
|
||||
vorgabe_el = ET.SubElement(vorgaben_element, 'Vorgabe')
|
||||
|
||||
ET.SubElement(vorgabe_el, 'Nummer').text = str(vorgabe.nummer)
|
||||
ET.SubElement(vorgabe_el, 'Titel').text = vorgabe.titel
|
||||
ET.SubElement(vorgabe_el, 'Thema').text = vorgabe.thema.name if vorgabe.thema else ""
|
||||
|
||||
kurztext_sections = vorgabe.vorgabekurztext_set.all().order_by('order')
|
||||
if kurztext_sections:
|
||||
kurztext_element = ET.SubElement(vorgabe_el, 'Kurztext')
|
||||
abschnitt = ET.SubElement(kurztext_element, 'Abschnitt')
|
||||
for kt in kurztext_sections:
|
||||
teil = ET.SubElement(abschnitt, 'Teil')
|
||||
teil.set('typ', kt.abschnitttyp.abschnitttyp if kt.abschnitttyp else "text")
|
||||
teil.text = kt.inhalt
|
||||
|
||||
langtext_sections = vorgabe.vorgabelangtext_set.all().order_by('order')
|
||||
if langtext_sections:
|
||||
langtext_element = ET.SubElement(vorgabe_el, 'Langtext')
|
||||
abschnitt = ET.SubElement(langtext_element, 'Abschnitt')
|
||||
for lt in langtext_sections:
|
||||
teil = ET.SubElement(abschnitt, 'Teil')
|
||||
teil.set('typ', lt.abschnitttyp.abschnitttyp if lt.abschnitttyp else "text")
|
||||
teil.text = lt.inhalt
|
||||
|
||||
referenz_element = ET.SubElement(vorgabe_el, 'Referenzen')
|
||||
for ref in vorgabe.referenzen.all():
|
||||
ref_text = f"{ref.name_nummer}: {ref.name_text}" if ref.name_text else ref.name_nummer
|
||||
ET.SubElement(referenz_element, 'Referenz').text = ref_text
|
||||
|
||||
vorgabe_gueltigkeit = ET.SubElement(vorgabe_el, 'Gueltigkeit')
|
||||
ET.SubElement(vorgabe_gueltigkeit, 'Von').text = vorgabe.gueltigkeit_von.strftime("%Y-%m-%d") if vorgabe.gueltigkeit_von else ""
|
||||
ET.SubElement(vorgabe_gueltigkeit, 'Bis').text = vorgabe.gueltigkeit_bis.strftime("%Y-%m-%d") if vorgabe.gueltigkeit_bis else None
|
||||
|
||||
checklistenfragen_element = ET.SubElement(vorgabe_el, 'Checklistenfragen')
|
||||
for cf in vorgabe.checklistenfragen.all():
|
||||
ET.SubElement(checklistenfragen_element, 'Frage').text = cf.frage
|
||||
|
||||
stichworte_element = ET.SubElement(vorgabe_el, 'Stichworte')
|
||||
for stw in vorgabe.stichworte.all():
|
||||
ET.SubElement(stichworte_element, 'Stichwort').text = stw.stichwort
|
||||
|
||||
xml_str = ET.tostring(root, encoding='unicode', method='xml')
|
||||
xml_output = self._prettify_xml(xml_str)
|
||||
|
||||
if options['output']:
|
||||
with open(options['output'], 'w', encoding='utf-8') as f:
|
||||
f.write(xml_output)
|
||||
self.stdout.write(self.style.SUCCESS(f'XML exported to {options["output"]}'))
|
||||
else:
|
||||
self.stdout.write(xml_output)
|
||||
|
||||
def _prettify_xml(self, xml_string):
|
||||
import xml.dom.minidom
|
||||
dom = xml.dom.minidom.parseString(xml_string)
|
||||
return dom.toprettyxml(indent=" ", encoding="UTF-8").decode('utf-8')
|
||||
@@ -71,7 +71,6 @@ class Command(BaseCommand):
|
||||
"name": name,
|
||||
"gueltigkeit_von": options["gueltigkeit_von"],
|
||||
"gueltigkeit_bis": options["gueltigkeit_bis"],
|
||||
"aktiv":False,
|
||||
},
|
||||
)
|
||||
if created:
|
||||
@@ -320,7 +319,6 @@ class Command(BaseCommand):
|
||||
thema=thema,
|
||||
titel=v["titel"],
|
||||
gueltigkeit_von=timezone.now().date(),
|
||||
order=0,
|
||||
)
|
||||
|
||||
# Stichworte
|
||||
|
||||
@@ -54,34 +54,6 @@ class Dokument(models.Model):
|
||||
def __str__(self):
|
||||
return f"{self.nummer} – {self.name}"
|
||||
|
||||
@property
|
||||
def dates(self):
|
||||
"""
|
||||
Returns an array of unique, chronologically sorted dates representing
|
||||
state-change dates from all Vorgaben in this document.
|
||||
|
||||
These are dates where Vorgaben become active (gueltigkeit_von) or change state
|
||||
(the day after gueltigkeit_bis). The very last date in the list is excluded
|
||||
as it has no relevance (nothing changes after it).
|
||||
"""
|
||||
dates_set = set()
|
||||
|
||||
# Get all vorgaben for this document
|
||||
for vorgabe in self.vorgaben.all():
|
||||
# Add gueltigkeit_von (when vorgabe becomes active)
|
||||
if vorgabe.gueltigkeit_von:
|
||||
dates_set.add(vorgabe.gueltigkeit_von)
|
||||
|
||||
# Add the day after gueltigkeit_bis (when vorgabe expires/changes state)
|
||||
# Only if gueltigkeit_bis is defined (not None)
|
||||
if vorgabe.gueltigkeit_bis:
|
||||
dates_set.add(vorgabe.gueltigkeit_bis + datetime.timedelta(days=1))
|
||||
|
||||
# Return sorted unique dates from oldest to newest, excluding the last date
|
||||
# (but only if there are multiple dates; single dates are kept)
|
||||
sorted_dates = sorted(list(dates_set))
|
||||
return sorted_dates[:-1] if len(sorted_dates) > 1 else sorted_dates
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural="Dokumente"
|
||||
verbose_name="Dokument"
|
||||
@@ -169,12 +141,6 @@ class Vorgabe(models.Model):
|
||||
"""
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
# Check that thema is provided
|
||||
if not self.thema_id:
|
||||
raise ValidationError({
|
||||
'thema': 'Thema ist ein Pflichtfeld. Bitte wählen Sie ein Thema aus.'
|
||||
})
|
||||
|
||||
# Check for conflicts with existing Vorgaben
|
||||
conflicts = self.find_conflicts()
|
||||
if conflicts:
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Alle Kommentare</h1>
|
||||
|
||||
{% if total_comments == 0 %}
|
||||
<div class="alert alert-info">
|
||||
<p>Es gibt noch keine Kommentare zu Vorgaben.</p>
|
||||
<p><a href="{% url 'standard_list' %}">Zu den Standards</a></p>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">Insgesamt {{ total_comments }} Kommentar{{ total_comments|pluralize:"e" }}</p>
|
||||
|
||||
{% for dokument, comments in comments_by_document.items %}
|
||||
<div class="panel panel-default" style="margin-top: 2rem;">
|
||||
<div class="panel-heading">
|
||||
<h2 style="margin: 0;">
|
||||
<a href="{% url 'standard_detail' nummer=dokument.nummer %}">
|
||||
{{ dokument.nummer }} – {{ dokument.name }}
|
||||
</a>
|
||||
</h2>
|
||||
<p style="margin: 0; color: #666; font-size: 0.9rem;">
|
||||
{{ comments|length }} Kommentar{{ comments|length|pluralize:"e" }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="list-group">
|
||||
{% for comment in comments %}
|
||||
<div class="list-group-item" style="border-left: 3px solid #007bff; padding: 1rem;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: flex-start;">
|
||||
<div style="flex: 1;">
|
||||
<h4 style="margin: 0 0 0.5rem 0;">
|
||||
<a href="{% url 'standard_detail' nummer=comment.vorgabe.dokument.nummer %}#{{ comment.vorgabe.Vorgabennummer }}">
|
||||
{{ comment.vorgabe.Vorgabennummer }}
|
||||
</a> {{ comment.vorgabe.titel }}
|
||||
</h4>
|
||||
<p style="margin: 0 0 0.75rem 0; color: #666; font-size: 0.9rem;">
|
||||
<strong>Benutzer:</strong> {{ comment.user.first_name }} {{ comment.user.last_name }}<br>
|
||||
<strong>Erstellt:</strong> {{ comment.created_at|date:"d.m.Y H:i" }}
|
||||
{% if comment.updated_at != comment.created_at %}
|
||||
<br>
|
||||
<strong>Bearbeitet:</strong> {{ comment.updated_at|date:"d.m.Y H:i" }}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<form method="POST" action="{% url 'delete_vorgabe_comment' comment.id %}"
|
||||
style="display: inline; margin-left: 1rem;"
|
||||
onsubmit="return confirm('Sind Sie sicher, dass Sie diesen Kommentar löschen möchten?');">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-sm btn-danger">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
<div style="background: #f8f9fa; padding: 0.75rem; border-radius: 4px; margin-top: 0.5rem; white-space: pre-wrap; word-wrap: break-word;">
|
||||
{{ comment.text }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<div style="margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #ddd;">
|
||||
<a href="{% url 'standard_list' %}" class="btn btn-default">Zu den Standards</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -16,32 +16,9 @@
|
||||
|
||||
{% if standard.history == True %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{% if standard.is_future %}
|
||||
<strong>Zukünftige Version vom {{ standard.check_date }}</strong>
|
||||
{% else %}
|
||||
<strong>Historische Version vom {{ standard.check_date }}</strong>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- History Dates Dropdown -->
|
||||
{% if standard.dates %}
|
||||
<div class="mb-3">
|
||||
<div class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="text-decoration: none;">
|
||||
📅 Historische Versionen
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="/dokumente/{{ standard.nummer }}/">Aktuelle Version</a></li>
|
||||
<li class="divider"></li>
|
||||
{% for date in standard.dates %}
|
||||
<li><a href="/dokumente/{{ standard.nummer }}/history/{{ date|date:'Y-m-d' }}/">{{ date|date:'d.m.Y' }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Einleitung -->
|
||||
{% if standard.einleitung_html %}
|
||||
<div class="row mb-4">
|
||||
@@ -193,28 +170,23 @@
|
||||
<h2>Metadaten</h2>
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Autoren:</dt>
|
||||
<dd class="col-sm-9">{{ standard.autoren.all|join:", " }}</dd>
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Autoren:</dt>
|
||||
<dd class="col-sm-9">{{ standard.autoren.all|join:", " }}</dd>
|
||||
|
||||
<dt class="col-sm-3">Prüfende:</dt>
|
||||
<dd class="col-sm-9">{{ standard.pruefende.all|join:", " }}</dd>
|
||||
<dt class="col-sm-3">Prüfende:</dt>
|
||||
<dd class="col-sm-9">{{ standard.pruefende.all|join:", " }}</dd>
|
||||
|
||||
<dt class="col-sm-3">Gültigkeit:</dt>
|
||||
<dd class="col-sm-9">{{ standard.gueltigkeit_von }} bis {{ standard.gueltigkeit_bis|default_if_none:"auf weiteres" }}</dd>
|
||||
</dl>
|
||||
<p>
|
||||
<a href="{% url 'standard_json' standard.nummer %}"
|
||||
class="btn btn-secondary icon icon--before icon--download"
|
||||
download="{{ standard.nummer }}.json">
|
||||
JSON herunterladen
|
||||
</a>
|
||||
<a href="{% url 'standard_xml' standard.nummer %}"
|
||||
class="btn btn-secondary icon icon--before icon--download"
|
||||
download="{{ standard.nummer }}.xml">
|
||||
XML herunterladen
|
||||
</a>
|
||||
</p>
|
||||
<dt class="col-sm-3">Gültigkeit:</dt>
|
||||
<dd class="col-sm-9">{{ standard.gueltigkeit_von }} bis {{ standard.gueltigkeit_bis|default_if_none:"auf weiteres" }}</dd>
|
||||
</dl>
|
||||
<p>
|
||||
<a href="{% url 'standard_json' standard.nummer %}"
|
||||
class="btn btn-secondary icon icon--before icon--download"
|
||||
download="{{ standard.nummer }}.json">
|
||||
JSON herunterladen
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Meine Kommentare</h1>
|
||||
|
||||
{% if total_comments == 0 %}
|
||||
<div class="alert alert-info">
|
||||
<p>Sie haben noch keine Kommentare zu Vorgaben hinterlassen.</p>
|
||||
<p><a href="{% url 'standard_list' %}">Zu den Standards</a></p>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">Insgesamt {{ total_comments }} Kommentar{{ total_comments|pluralize:"e" }}</p>
|
||||
|
||||
{% for dokument, comments in comments_by_document.items %}
|
||||
<div class="panel panel-default" style="margin-top: 2rem;">
|
||||
<div class="panel-heading">
|
||||
<h2 style="margin: 0;">
|
||||
<a href="{% url 'standard_detail' nummer=dokument.nummer %}">
|
||||
{{ dokument.nummer }} – {{ dokument.name }}
|
||||
</a>
|
||||
</h2>
|
||||
<p style="margin: 0; color: #666; font-size: 0.9rem;">
|
||||
{{ comments|length }} Kommentar{{ comments|length|pluralize:"e" }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="list-group">
|
||||
{% for comment in comments %}
|
||||
<div class="list-group-item" style="border-left: 3px solid #007bff; padding: 1rem;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: flex-start;">
|
||||
<div style="flex: 1;">
|
||||
<h4 style="margin: 0 0 0.5rem 0;">
|
||||
<a href="{% url 'standard_detail' nummer=comment.vorgabe.dokument.nummer %}#{{ comment.vorgabe.Vorgabennummer }}">
|
||||
{{ comment.vorgabe.Vorgabennummer }}
|
||||
</a> {{ comment.vorgabe.titel }}
|
||||
</h4>
|
||||
<p style="margin: 0 0 0.75rem 0; color: #666; font-size: 0.9rem;">
|
||||
<strong>Erstellt:</strong> {{ comment.created_at|date:"d.m.Y H:i" }}
|
||||
{% if comment.updated_at != comment.created_at %}
|
||||
<br>
|
||||
<strong>Bearbeitet:</strong> {{ comment.updated_at|date:"d.m.Y H:i" }}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<form method="POST" action="{% url 'delete_vorgabe_comment' comment.id %}"
|
||||
style="display: inline; margin-left: 1rem;"
|
||||
onsubmit="return confirm('Sind Sie sicher, dass Sie diesen Kommentar löschen möchten?');">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-sm btn-danger">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
<div style="background: #f8f9fa; padding: 0.75rem; border-radius: 4px; margin-top: 0.5rem; white-space: pre-wrap; word-wrap: break-word;">
|
||||
{{ comment.text }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<div style="margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #ddd;">
|
||||
<a href="{% url 'standard_list' %}" class="btn btn-default">Zu den Standards</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,960 +0,0 @@
|
||||
"""
|
||||
Tests for the import-document management command.
|
||||
|
||||
This test suite covers:
|
||||
- Basic import functionality
|
||||
- Dry-run mode
|
||||
- Purge functionality
|
||||
- Error handling (missing file, dokumententyp, thema, abschnitttyp)
|
||||
- Context switching (einleitung → geltungsbereich → vorgabe)
|
||||
- Header normalization
|
||||
- Vorgaben with Kurztext, Langtext, Stichworte, Checklistenfragen
|
||||
- Edge cases and malformed input
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from django.test import TestCase
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from dokumente.models import (
|
||||
Dokumententyp,
|
||||
Dokument,
|
||||
Thema,
|
||||
Vorgabe,
|
||||
VorgabeKurztext,
|
||||
VorgabeLangtext,
|
||||
Geltungsbereich,
|
||||
Einleitung,
|
||||
Checklistenfrage,
|
||||
)
|
||||
from abschnitte.models import AbschnittTyp
|
||||
from stichworte.models import Stichwort
|
||||
|
||||
|
||||
class ImportDocumentCommandTestCase(TestCase):
|
||||
"""Test cases for the import-document management command"""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test fixtures"""
|
||||
# Create required Dokumententyp
|
||||
self.dokumententyp = Dokumententyp.objects.create(
|
||||
name="IT-Sicherheit",
|
||||
verantwortliche_ve="TEST-VE"
|
||||
)
|
||||
|
||||
# Create required AbschnittTyp instances
|
||||
self.text_typ = AbschnittTyp.objects.create(abschnitttyp="text")
|
||||
self.liste_geordnet_typ = AbschnittTyp.objects.create(
|
||||
abschnitttyp="liste geordnet"
|
||||
)
|
||||
self.liste_ungeordnet_typ = AbschnittTyp.objects.create(
|
||||
abschnitttyp="liste ungeordnet"
|
||||
)
|
||||
|
||||
# Create test Themen
|
||||
self.thema_organisation = Thema.objects.create(
|
||||
name="Organisation",
|
||||
erklaerung="Organisatorische Anforderungen"
|
||||
)
|
||||
self.thema_technik = Thema.objects.create(
|
||||
name="Technik",
|
||||
erklaerung="Technische Anforderungen"
|
||||
)
|
||||
# Additional Themen for r009.txt example
|
||||
self.thema_informationen = Thema.objects.create(
|
||||
name="Informationen",
|
||||
erklaerung="Informationssicherheit"
|
||||
)
|
||||
self.thema_systeme = Thema.objects.create(
|
||||
name="Systeme",
|
||||
erklaerung="Systemanforderungen"
|
||||
)
|
||||
self.thema_anwendungen = Thema.objects.create(
|
||||
name="Anwendungen",
|
||||
erklaerung="Anwendungsanforderungen"
|
||||
)
|
||||
self.thema_zonen = Thema.objects.create(
|
||||
name="Zonen",
|
||||
erklaerung="Zonenanforderungen"
|
||||
)
|
||||
|
||||
def create_test_file(self, content):
|
||||
"""Helper to create a temporary test file with given content"""
|
||||
fd, path = tempfile.mkstemp(suffix=".txt", text=True)
|
||||
with os.fdopen(fd, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
return path
|
||||
|
||||
def test_basic_import_creates_document(self):
|
||||
"""Test that basic import creates a document"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
This is the introduction.
|
||||
|
||||
>>>geltungsbereich
|
||||
>>>text
|
||||
This is the scope.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Test Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Short description.
|
||||
>>>Langtext
|
||||
>>>Text
|
||||
Long description.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-001',
|
||||
'--name', 'Test Document',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
# Check document was created
|
||||
dokument = Dokument.objects.get(nummer='TEST-001')
|
||||
self.assertEqual(dokument.name, 'Test Document')
|
||||
self.assertEqual(dokument.dokumententyp, self.dokumententyp)
|
||||
|
||||
# Check output message
|
||||
output = out.getvalue()
|
||||
self.assertIn('Created Document TEST-001', output)
|
||||
self.assertIn('Imported document TEST-001', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_import_creates_einleitung(self):
|
||||
"""Test that Einleitung sections are created"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
This is the introduction text.
|
||||
|
||||
>>>geltungsbereich
|
||||
>>>text
|
||||
Scope text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-002',
|
||||
'--name', 'Test Document 2',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-002')
|
||||
einleitung = Einleitung.objects.filter(einleitung=dokument)
|
||||
self.assertEqual(einleitung.count(), 1)
|
||||
self.assertEqual(einleitung.first().inhalt, 'This is the introduction text.')
|
||||
self.assertEqual(einleitung.first().abschnitttyp, self.text_typ)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_import_creates_geltungsbereich(self):
|
||||
"""Test that Geltungsbereich sections are created"""
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>text
|
||||
This standard applies to all servers.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-003',
|
||||
'--name', 'Test Document 3',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-003')
|
||||
geltungsbereich = Geltungsbereich.objects.filter(geltungsbereich=dokument)
|
||||
self.assertEqual(geltungsbereich.count(), 1)
|
||||
self.assertEqual(
|
||||
geltungsbereich.first().inhalt,
|
||||
'This standard applies to all servers.'
|
||||
)
|
||||
self.assertEqual(geltungsbereich.first().abschnitttyp, self.text_typ)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_import_creates_vorgabe_with_all_fields(self):
|
||||
"""Test creating a Vorgabe with all fields"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Complete Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Short text here.
|
||||
>>>Langtext
|
||||
>>>Text
|
||||
Long text here.
|
||||
>>>Stichworte
|
||||
Testing, Management, Security
|
||||
>>>Checkliste
|
||||
Is the requirement met?
|
||||
Has documentation been provided?
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-004',
|
||||
'--name', 'Test Document 4',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-004')
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument, nummer=1)
|
||||
|
||||
# Check basic fields
|
||||
self.assertEqual(vorgabe.titel, 'Complete Requirement')
|
||||
self.assertEqual(vorgabe.thema, self.thema_organisation)
|
||||
|
||||
# Check Kurztext
|
||||
kurztext = VorgabeKurztext.objects.filter(abschnitt=vorgabe)
|
||||
self.assertEqual(kurztext.count(), 1)
|
||||
self.assertEqual(kurztext.first().inhalt, 'Short text here.')
|
||||
|
||||
# Check Langtext
|
||||
langtext = VorgabeLangtext.objects.filter(abschnitt=vorgabe)
|
||||
self.assertEqual(langtext.count(), 1)
|
||||
self.assertEqual(langtext.first().inhalt, 'Long text here.')
|
||||
|
||||
# Check Stichworte
|
||||
stichworte = vorgabe.stichworte.all()
|
||||
self.assertEqual(stichworte.count(), 3)
|
||||
stichwort_names = {s.stichwort for s in stichworte}
|
||||
self.assertEqual(stichwort_names, {'Testing', 'Management', 'Security'})
|
||||
|
||||
# Check Checklistenfragen
|
||||
fragen = Checklistenfrage.objects.filter(vorgabe=vorgabe)
|
||||
self.assertEqual(fragen.count(), 2)
|
||||
frage_texts = {f.frage for f in fragen}
|
||||
self.assertEqual(frage_texts, {
|
||||
'Is the requirement met?',
|
||||
'Has documentation been provided?'
|
||||
})
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_import_multiple_vorgaben(self):
|
||||
"""Test importing multiple Vorgaben"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
First Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
First requirement text.
|
||||
|
||||
>>>Vorgabe Technik
|
||||
>>>Nummer 2
|
||||
>>>Titel
|
||||
Second Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Second requirement text.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 3
|
||||
>>>Titel
|
||||
Third Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Third requirement text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-005',
|
||||
'--name', 'Test Document 5',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-005')
|
||||
vorgaben = Vorgabe.objects.filter(dokument=dokument).order_by('nummer')
|
||||
|
||||
self.assertEqual(vorgaben.count(), 3)
|
||||
self.assertEqual(vorgaben[0].nummer, 1)
|
||||
self.assertEqual(vorgaben[0].thema, self.thema_organisation)
|
||||
self.assertEqual(vorgaben[1].nummer, 2)
|
||||
self.assertEqual(vorgaben[1].thema, self.thema_technik)
|
||||
self.assertEqual(vorgaben[2].nummer, 3)
|
||||
self.assertEqual(vorgaben[2].thema, self.thema_organisation)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_dry_run_creates_no_data(self):
|
||||
"""Test that dry-run mode creates no database records"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
Introduction text.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Test Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Short text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-DRY',
|
||||
'--name', 'Dry Run Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
'--dry-run',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
# Document is created (for counting purposes) but not saved
|
||||
output = out.getvalue()
|
||||
self.assertIn('Dry run: no database changes will be made', output)
|
||||
self.assertIn('Dry run complete', output)
|
||||
|
||||
# Check that Einleitung and Vorgabe were NOT created
|
||||
dokument = Dokument.objects.get(nummer='TEST-DRY')
|
||||
self.assertEqual(Einleitung.objects.filter(einleitung=dokument).count(), 0)
|
||||
self.assertEqual(Vorgabe.objects.filter(dokument=dokument).count(), 0)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_dry_run_verbose_shows_details(self):
|
||||
"""Test that dry-run with verbose shows detailed output"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
Introduction.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Test
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Short.
|
||||
>>>Langtext
|
||||
>>>Text
|
||||
Long.
|
||||
>>>Stichworte
|
||||
Keyword1, Keyword2
|
||||
>>>Checkliste
|
||||
Question 1?
|
||||
Question 2?
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-VERBOSE',
|
||||
'--name', 'Verbose Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
'--dry-run',
|
||||
'--verbose',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn('[DRY RUN] Einleitung Abschnitt', output)
|
||||
self.assertIn('[DRY RUN] Would create Vorgabe 1', output)
|
||||
self.assertIn('Stichworte: Keyword1, Keyword2', output)
|
||||
self.assertIn('Checkliste: Question 1?', output)
|
||||
self.assertIn('Checkliste: Question 2?', output)
|
||||
self.assertIn('Kurztext', output)
|
||||
self.assertIn('Langtext', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_purge_deletes_existing_content(self):
|
||||
"""Test that --purge deletes existing content before import"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
New Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
New text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
# First import
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-PURGE',
|
||||
'--name', 'Purge Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-PURGE')
|
||||
self.assertEqual(Vorgabe.objects.filter(dokument=dokument).count(), 1)
|
||||
|
||||
# Second import with different content and --purge
|
||||
test_content_2 = """>>>Vorgabe Technik
|
||||
>>>Nummer 2
|
||||
>>>Titel
|
||||
Replacement Requirement
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Replacement text.
|
||||
"""
|
||||
test_file_2 = self.create_test_file(test_content_2)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file_2,
|
||||
'--nummer', 'TEST-PURGE',
|
||||
'--name', 'Purge Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
'--purge',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
# Old Vorgabe should be deleted, only new one exists
|
||||
vorgaben = Vorgabe.objects.filter(dokument=dokument)
|
||||
self.assertEqual(vorgaben.count(), 1)
|
||||
self.assertEqual(vorgaben.first().nummer, 2)
|
||||
self.assertEqual(vorgaben.first().thema, self.thema_technik)
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn('Purged', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file_2)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_purge_dry_run_shows_what_would_be_deleted(self):
|
||||
"""Test that --purge with --dry-run shows deletion counts"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Original
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
# First import to create data
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-PURGE-DRY',
|
||||
'--name', 'Purge Dry Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
# Dry run with purge
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-PURGE-DRY',
|
||||
'--name', 'Purge Dry Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
'--purge',
|
||||
'--dry-run',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn('[DRY RUN] Would purge:', output)
|
||||
self.assertIn('1 Vorgaben', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_header_normalization(self):
|
||||
"""Test that headers with hyphens are normalized correctly"""
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>Liste-ungeordnet
|
||||
Item 1
|
||||
Item 2
|
||||
Item 3
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-NORM',
|
||||
'--name', 'Normalization Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-NORM')
|
||||
geltungsbereich = Geltungsbereich.objects.get(geltungsbereich=dokument)
|
||||
|
||||
# Should have normalized "Liste-ungeordnet" to "liste ungeordnet"
|
||||
self.assertEqual(geltungsbereich.abschnitttyp, self.liste_ungeordnet_typ)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_missing_file_raises_error(self):
|
||||
"""Test that missing file raises CommandError"""
|
||||
with self.assertRaises(CommandError) as cm:
|
||||
call_command(
|
||||
'import-document',
|
||||
'/nonexistent/file.txt',
|
||||
'--nummer', 'TEST-ERR',
|
||||
'--name', 'Error Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
self.assertIn('does not exist', str(cm.exception))
|
||||
|
||||
def test_missing_dokumententyp_raises_error(self):
|
||||
"""Test that missing Dokumententyp raises CommandError"""
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>text
|
||||
Text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
with self.assertRaises(CommandError) as cm:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-ERR',
|
||||
'--name', 'Error Test',
|
||||
'--dokumententyp', 'NonExistentType'
|
||||
)
|
||||
self.assertIn('does not exist', str(cm.exception))
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_missing_thema_skips_vorgabe(self):
|
||||
"""Test that missing Thema causes Vorgabe to be skipped with warning"""
|
||||
test_content = """>>>Vorgabe NonExistentThema
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Test
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-SKIP',
|
||||
'--name', 'Skip Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-SKIP')
|
||||
# Vorgabe should NOT be created
|
||||
self.assertEqual(Vorgabe.objects.filter(dokument=dokument).count(), 0)
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn('not found, skipping Vorgabe', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_missing_abschnitttyp_defaults_to_text(self):
|
||||
"""Test that missing AbschnittTyp defaults to 'text' with warning"""
|
||||
# Delete all but text type
|
||||
AbschnittTyp.objects.exclude(abschnitttyp='text').delete()
|
||||
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>liste geordnet
|
||||
Item 1
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-DEFAULT',
|
||||
'--name', 'Default Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-DEFAULT')
|
||||
geltungsbereich = Geltungsbereich.objects.get(geltungsbereich=dokument)
|
||||
|
||||
# Should default to 'text' type
|
||||
self.assertEqual(geltungsbereich.abschnitttyp.abschnitttyp, 'text')
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn("not found; defaulting to 'text'", output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_inline_titel(self):
|
||||
"""Test that inline title (on same line as header) is parsed"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel Inline Title Here
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-INLINE',
|
||||
'--name', 'Inline Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-INLINE')
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument)
|
||||
self.assertEqual(vorgabe.titel, 'Inline Title Here')
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_inline_stichworte(self):
|
||||
"""Test that inline Stichworte (on same line as header) are parsed"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel Test
|
||||
>>>Stichworte Security, Testing, Compliance
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Text.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-INLINE-STW',
|
||||
'--name', 'Inline Stichwort Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-INLINE-STW')
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument)
|
||||
stichworte = {s.stichwort for s in vorgabe.stichworte.all()}
|
||||
self.assertEqual(stichworte, {'Security', 'Testing', 'Compliance'})
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_gueltigkeit_dates(self):
|
||||
"""Test that validity dates are set correctly"""
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>text
|
||||
Scope.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-DATES',
|
||||
'--name', 'Date Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
'--gueltigkeit_von', '2024-01-01',
|
||||
'--gueltigkeit_bis', '2024-12-31'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-DATES')
|
||||
self.assertEqual(str(dokument.gueltigkeit_von), '2024-01-01')
|
||||
self.assertEqual(str(dokument.gueltigkeit_bis), '2024-12-31')
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_existing_document_updates(self):
|
||||
"""Test that importing to existing document number shows warning"""
|
||||
test_content = """>>>geltungsbereich
|
||||
>>>text
|
||||
First version.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
# First import
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-EXISTS',
|
||||
'--name', 'Existing Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
output1 = out.getvalue()
|
||||
self.assertIn('Created Document TEST-EXISTS', output1)
|
||||
|
||||
# Second import with same number
|
||||
out2 = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-EXISTS',
|
||||
'--name', 'Existing Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out2
|
||||
)
|
||||
|
||||
output2 = out2.getvalue()
|
||||
self.assertIn('already exists', output2)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_multiple_kurztext_sections(self):
|
||||
"""Test Vorgabe with multiple Kurztext sections"""
|
||||
test_content = """>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel Multiple Sections
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
First kurztext section.
|
||||
>>>Liste ungeordnet
|
||||
Item A
|
||||
Item B
|
||||
>>>Langtext
|
||||
>>>Text
|
||||
Langtext.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-MULTI',
|
||||
'--name', 'Multi Section Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-MULTI')
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument)
|
||||
kurztext_sections = VorgabeKurztext.objects.filter(abschnitt=vorgabe).order_by('id')
|
||||
|
||||
self.assertEqual(kurztext_sections.count(), 2)
|
||||
self.assertEqual(kurztext_sections[0].abschnitttyp.abschnitttyp, 'text')
|
||||
self.assertEqual(kurztext_sections[1].abschnitttyp.abschnitttyp, 'liste ungeordnet')
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_empty_file(self):
|
||||
"""Test importing an empty file"""
|
||||
test_content = ""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-EMPTY',
|
||||
'--name', 'Empty Test',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-EMPTY')
|
||||
# Document created but no content
|
||||
self.assertEqual(Einleitung.objects.filter(einleitung=dokument).count(), 0)
|
||||
self.assertEqual(Geltungsbereich.objects.filter(geltungsbereich=dokument).count(), 0)
|
||||
self.assertEqual(Vorgabe.objects.filter(dokument=dokument).count(), 0)
|
||||
|
||||
output = out.getvalue()
|
||||
self.assertIn('with 0 Vorgaben', output)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_unicode_content(self):
|
||||
"""Test that Unicode characters (German umlauts, etc.) are handled correctly"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
Übersicht über die Sicherheitsanforderungen für IT-Systeme.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel
|
||||
Überprüfung der Systemkonfiguration
|
||||
>>>Kurztext
|
||||
>>>Text
|
||||
Die Konfiguration muss regelmäßig überprüft werden.
|
||||
>>>Stichworte
|
||||
Überprüfung, Sicherheit, Qualität
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-UNICODE',
|
||||
'--name', 'Unicode Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-UNICODE')
|
||||
|
||||
# Check Einleitung
|
||||
einleitung = Einleitung.objects.get(einleitung=dokument)
|
||||
self.assertIn('Übersicht', einleitung.inhalt)
|
||||
|
||||
# Check Vorgabe
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument)
|
||||
self.assertEqual(vorgabe.titel, 'Überprüfung der Systemkonfiguration')
|
||||
|
||||
# Check Kurztext
|
||||
kurztext = VorgabeKurztext.objects.get(abschnitt=vorgabe)
|
||||
self.assertIn('regelmäßig', kurztext.inhalt)
|
||||
|
||||
# Check Stichworte
|
||||
stichworte = {s.stichwort for s in vorgabe.stichworte.all()}
|
||||
self.assertIn('Überprüfung', stichworte)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_context_switching(self):
|
||||
"""Test that context switches correctly between sections"""
|
||||
test_content = """>>>Einleitung
|
||||
>>>text
|
||||
Intro text 1.
|
||||
>>>text
|
||||
Intro text 2.
|
||||
|
||||
>>>geltungsbereich
|
||||
>>>text
|
||||
Scope text 1.
|
||||
>>>text
|
||||
Scope text 2.
|
||||
|
||||
>>>Vorgabe Organisation
|
||||
>>>Nummer 1
|
||||
>>>Titel Test
|
||||
>>>Kurztext
|
||||
>>>text
|
||||
Kurztext 1.
|
||||
>>>text
|
||||
Kurztext 2.
|
||||
>>>Langtext
|
||||
>>>text
|
||||
Langtext 1.
|
||||
"""
|
||||
test_file = self.create_test_file(test_content)
|
||||
|
||||
try:
|
||||
call_command(
|
||||
'import-document',
|
||||
test_file,
|
||||
'--nummer', 'TEST-CONTEXT',
|
||||
'--name', 'Context Test',
|
||||
'--dokumententyp', 'IT-Sicherheit'
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='TEST-CONTEXT')
|
||||
|
||||
# Check Einleitung has 2 sections
|
||||
einleitung = Einleitung.objects.filter(einleitung=dokument)
|
||||
self.assertEqual(einleitung.count(), 2)
|
||||
|
||||
# Check Geltungsbereich has 2 sections
|
||||
geltungsbereich = Geltungsbereich.objects.filter(geltungsbereich=dokument)
|
||||
self.assertEqual(geltungsbereich.count(), 2)
|
||||
|
||||
# Check Vorgabe has correct Kurztext and Langtext counts
|
||||
vorgabe = Vorgabe.objects.get(dokument=dokument)
|
||||
kurztext = VorgabeKurztext.objects.filter(abschnitt=vorgabe)
|
||||
langtext = VorgabeLangtext.objects.filter(abschnitt=vorgabe)
|
||||
self.assertEqual(kurztext.count(), 2)
|
||||
self.assertEqual(langtext.count(), 1)
|
||||
|
||||
finally:
|
||||
os.unlink(test_file)
|
||||
|
||||
def test_real_world_example(self):
|
||||
"""Test importing the real r009.txt example document"""
|
||||
# Use the actual example file
|
||||
example_file = Path(__file__).parent.parent / 'Documentation' / 'import formats' / 'r009.txt'
|
||||
|
||||
if not example_file.exists():
|
||||
self.skipTest("r009.txt example file not found")
|
||||
|
||||
out = StringIO()
|
||||
call_command(
|
||||
'import-document',
|
||||
str(example_file),
|
||||
'--nummer', 'R009',
|
||||
'--name', 'IT-Sicherheit Serversysteme',
|
||||
'--dokumententyp', 'IT-Sicherheit',
|
||||
stdout=out
|
||||
)
|
||||
|
||||
dokument = Dokument.objects.get(nummer='R009')
|
||||
|
||||
# Check that Einleitung was created
|
||||
self.assertGreater(Einleitung.objects.filter(einleitung=dokument).count(), 0)
|
||||
|
||||
# Check that Geltungsbereich was created
|
||||
self.assertGreater(Geltungsbereich.objects.filter(geltungsbereich=dokument).count(), 0)
|
||||
|
||||
# Check that multiple Vorgaben were created (r009.txt has 23 Vorgaben)
|
||||
vorgaben = Vorgabe.objects.filter(dokument=dokument)
|
||||
self.assertGreaterEqual(vorgaben.count(), 20)
|
||||
|
||||
# Verify output message
|
||||
output = out.getvalue()
|
||||
self.assertIn('Imported document R009', output)
|
||||
1223
dokumente/tests.py
1223
dokumente/tests.py
File diff suppressed because it is too large
Load Diff
@@ -4,14 +4,11 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('', views.standard_list, name='standard_list'),
|
||||
path('unvollstaendig/', views.incomplete_vorgaben, name='incomplete_vorgaben'),
|
||||
path('meine-kommentare/', views.user_comments, name='user_comments'),
|
||||
path('alle-kommentare/', views.all_comments, name='all_comments'),
|
||||
path('<str:nummer>/', views.standard_detail, name='standard_detail'),
|
||||
path('<str:nummer>/history/<str:check_date>/', views.standard_detail),
|
||||
path('<str:nummer>/history/', views.standard_detail, {"check_date":"today"}, name='standard_history'),
|
||||
path('<str:nummer>/checkliste/', views.standard_checkliste, name='standard_checkliste'),
|
||||
path('<str:nummer>/json/', views.standard_json, name='standard_json'),
|
||||
path('<str:nummer>/xml/', views.standard_xml, name='standard_xml'),
|
||||
path('comments/<int:vorgabe_id>/', views.get_vorgabe_comments, name='get_vorgabe_comments'),
|
||||
path('comments/<int:vorgabe_id>/add/', views.add_vorgabe_comment, name='add_vorgabe_comment'),
|
||||
path('comments/delete/<int:comment_id>/', views.delete_vorgabe_comment, name='delete_vorgabe_comment'),
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
from django.http import JsonResponse
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.views.decorators.http import require_POST
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.html import escape, mark_safe
|
||||
from django.utils.safestring import SafeString
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
from .models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Checklistenfrage, VorgabeComment
|
||||
from abschnitte.utils import render_textabschnitte
|
||||
|
||||
@@ -30,11 +29,9 @@ def standard_detail(request, nummer,check_date=""):
|
||||
if check_date:
|
||||
check_date = calendar.parseDT(check_date)[0].date()
|
||||
standard.history = True
|
||||
standard.is_future = check_date > date.today()
|
||||
else:
|
||||
check_date = date.today()
|
||||
standard.history = False
|
||||
standard.is_future = False
|
||||
standard.check_date=check_date
|
||||
vorgaben = list(standard.vorgaben.order_by("thema","nummer").select_related("thema","dokument")) # convert queryset to list so we can attach attributes
|
||||
|
||||
@@ -255,138 +252,6 @@ def standard_json(request, nummer):
|
||||
return JsonResponse(doc_data, json_dumps_params={'indent': 2, 'ensure_ascii': False}, encoder=DjangoJSONEncoder)
|
||||
|
||||
|
||||
def standard_xml(request, nummer):
|
||||
"""
|
||||
Export a single Dokument as XML
|
||||
"""
|
||||
# Get the document with all related data
|
||||
dokument = get_object_or_404(
|
||||
Dokument.objects.prefetch_related(
|
||||
'autoren', 'pruefende', 'vorgaben__thema',
|
||||
'vorgaben__referenzen', 'vorgaben__stichworte',
|
||||
'vorgaben__checklistenfragen', 'vorgaben__vorgabekurztext_set',
|
||||
'vorgaben__vorgabelangtext_set', 'geltungsbereich_set',
|
||||
'einleitung_set', 'changelog__autoren'
|
||||
),
|
||||
nummer=nummer
|
||||
)
|
||||
|
||||
root = ET.Element('Vorgabendokument')
|
||||
|
||||
ET.SubElement(root, 'Typ').text = dokument.dokumententyp.name if dokument.dokumententyp else ""
|
||||
ET.SubElement(root, 'Nummer').text = dokument.nummer
|
||||
ET.SubElement(root, 'Name').text = dokument.name
|
||||
|
||||
autoren_element = ET.SubElement(root, 'Autoren')
|
||||
for autor in dokument.autoren.all():
|
||||
ET.SubElement(autoren_element, 'Autor').text = autor.name
|
||||
|
||||
pruefende_element = ET.SubElement(root, 'Pruefende')
|
||||
for pruefender in dokument.pruefende.all():
|
||||
ET.SubElement(pruefende_element, 'Pruefender').text = pruefender.name
|
||||
|
||||
gueltigkeit_element = ET.SubElement(root, 'Gueltigkeit')
|
||||
ET.SubElement(gueltigkeit_element, 'Von').text = dokument.gueltigkeit_von.strftime("%Y-%m-%d") if dokument.gueltigkeit_von else ""
|
||||
ET.SubElement(gueltigkeit_element, 'Bis').text = dokument.gueltigkeit_bis.strftime("%Y-%m-%d") if dokument.gueltigkeit_bis else None
|
||||
|
||||
ET.SubElement(root, 'SignaturCSO').text = dokument.signatur_cso
|
||||
|
||||
geltungsbereich_sections = dokument.geltungsbereich_set.all().order_by('order')
|
||||
if geltungsbereich_sections:
|
||||
geltungsbereich_element = ET.SubElement(root, 'Geltungsbereich')
|
||||
abschnitt_element = ET.SubElement(geltungsbereich_element, 'Abschnitt')
|
||||
for gb in geltungsbereich_sections:
|
||||
section = ET.SubElement(abschnitt_element, 'Teil')
|
||||
section.set('typ', gb.abschnitttyp.abschnitttyp if gb.abschnitttyp else "text")
|
||||
section.text = gb.inhalt
|
||||
|
||||
einleitung_sections = dokument.einleitung_set.all().order_by('order')
|
||||
if einleitung_sections:
|
||||
einleitung_element = ET.SubElement(root, 'Einleitung')
|
||||
abschnitt_element = ET.SubElement(einleitung_element, 'Abschnitt')
|
||||
for ei in einleitung_sections:
|
||||
section = ET.SubElement(abschnitt_element, 'Teil')
|
||||
section.set('typ', ei.abschnitttyp.abschnitttyp if ei.abschnitttyp else "text")
|
||||
section.text = ei.inhalt
|
||||
|
||||
ET.SubElement(root, 'Ziel').text = ""
|
||||
ET.SubElement(root, 'Grundlagen').text = ""
|
||||
|
||||
changelog_element = ET.SubElement(root, 'Changelog')
|
||||
for cl in dokument.changelog.all().order_by('-datum'):
|
||||
entry = ET.SubElement(changelog_element, 'Eintrag')
|
||||
ET.SubElement(entry, 'Datum').text = cl.datum.strftime("%Y-%m-%d")
|
||||
autoren = ET.SubElement(entry, 'Autoren')
|
||||
for autor in cl.autoren.all():
|
||||
ET.SubElement(autoren, 'Autor').text = autor.name
|
||||
ET.SubElement(entry, 'Aenderung').text = cl.aenderung
|
||||
|
||||
anhaenge_element = ET.SubElement(root, 'Anhaenge')
|
||||
ET.SubElement(anhaenge_element, 'Anhang').text = dokument.anhaenge
|
||||
|
||||
ET.SubElement(root, 'Verantwortlich').text = "Information Security Management BIT"
|
||||
ET.SubElement(root, 'Klassifizierung').text = ""
|
||||
|
||||
glossar_element = ET.SubElement(root, 'Glossar')
|
||||
|
||||
vorgaben_element = ET.SubElement(root, 'Vorgaben')
|
||||
|
||||
for vorgabe in dokument.vorgaben.all().order_by('order'):
|
||||
vorgabe_el = ET.SubElement(vorgaben_element, 'Vorgabe')
|
||||
|
||||
ET.SubElement(vorgabe_el, 'Nummer').text = str(vorgabe.nummer)
|
||||
ET.SubElement(vorgabe_el, 'Titel').text = vorgabe.titel
|
||||
ET.SubElement(vorgabe_el, 'Thema').text = vorgabe.thema.name if vorgabe.thema else ""
|
||||
|
||||
kurztext_sections = vorgabe.vorgabekurztext_set.all().order_by('order')
|
||||
if kurztext_sections:
|
||||
kurztext_element = ET.SubElement(vorgabe_el, 'Kurztext')
|
||||
abschnitt = ET.SubElement(kurztext_element, 'Abschnitt')
|
||||
for kt in kurztext_sections:
|
||||
teil = ET.SubElement(abschnitt, 'Teil')
|
||||
teil.set('typ', kt.abschnitttyp.abschnitttyp if kt.abschnitttyp else "text")
|
||||
teil.text = kt.inhalt
|
||||
|
||||
langtext_sections = vorgabe.vorgabelangtext_set.all().order_by('order')
|
||||
if langtext_sections:
|
||||
langtext_element = ET.SubElement(vorgabe_el, 'Langtext')
|
||||
abschnitt = ET.SubElement(langtext_element, 'Abschnitt')
|
||||
for lt in langtext_sections:
|
||||
teil = ET.SubElement(abschnitt, 'Teil')
|
||||
teil.set('typ', lt.abschnitttyp.abschnitttyp if lt.abschnitttyp else "text")
|
||||
teil.text = lt.inhalt
|
||||
|
||||
referenz_element = ET.SubElement(vorgabe_el, 'Referenzen')
|
||||
for ref in vorgabe.referenzen.all():
|
||||
ref_text = f"{ref.name_nummer}: {ref.name_text}" if ref.name_text else ref.name_nummer
|
||||
ET.SubElement(referenz_element, 'Referenz').text = ref_text
|
||||
|
||||
vorgabe_gueltigkeit = ET.SubElement(vorgabe_el, 'Gueltigkeit')
|
||||
ET.SubElement(vorgabe_gueltigkeit, 'Von').text = vorgabe.gueltigkeit_von.strftime("%Y-%m-%d") if vorgabe.gueltigkeit_von else ""
|
||||
ET.SubElement(vorgabe_gueltigkeit, 'Bis').text = vorgabe.gueltigkeit_bis.strftime("%Y-%m-%d") if vorgabe.gueltigkeit_bis else None
|
||||
|
||||
checklistenfragen_element = ET.SubElement(vorgabe_el, 'Checklistenfragen')
|
||||
for cf in vorgabe.checklistenfragen.all():
|
||||
ET.SubElement(checklistenfragen_element, 'Frage').text = cf.frage
|
||||
|
||||
stichworte_element = ET.SubElement(vorgabe_el, 'Stichworte')
|
||||
for stw in vorgabe.stichworte.all():
|
||||
ET.SubElement(stichworte_element, 'Stichwort').text = stw.stichwort
|
||||
|
||||
xml_str = ET.tostring(root, encoding='unicode', method='xml')
|
||||
xml_output = _prettify_xml(xml_str)
|
||||
|
||||
response = HttpResponse(xml_output, content_type='application/xml; charset=utf-8')
|
||||
response['Content-Disposition'] = f'attachment; filename="{dokument.nummer}.xml"'
|
||||
return response
|
||||
|
||||
|
||||
def _prettify_xml(xml_string):
|
||||
import xml.dom.minidom
|
||||
dom = xml.dom.minidom.parseString(xml_string)
|
||||
return dom.toprettyxml(indent=" ", encoding="UTF-8").decode('utf-8')
|
||||
|
||||
|
||||
@login_required
|
||||
def get_vorgabe_comments(request, vorgabe_id):
|
||||
"""Get comments for a specific Vorgabe"""
|
||||
@@ -501,57 +366,3 @@ def delete_vorgabe_comment(request, comment_id):
|
||||
response['Content-Security-Policy'] = "default-src 'self'"
|
||||
response['X-Content-Type-Options'] = 'nosniff'
|
||||
return response
|
||||
|
||||
|
||||
@login_required
|
||||
def user_comments(request):
|
||||
"""
|
||||
Display all comments made by the logged-in user, grouped by document.
|
||||
"""
|
||||
# Get all comments by the current user
|
||||
user_comments = VorgabeComment.objects.filter(
|
||||
user=request.user
|
||||
).select_related('vorgabe', 'vorgabe__dokument').order_by(
|
||||
'vorgabe__dokument__nummer', '-created_at'
|
||||
)
|
||||
|
||||
# Group comments by document
|
||||
comments_by_document = {}
|
||||
for comment in user_comments:
|
||||
dokument = comment.vorgabe.dokument
|
||||
if dokument not in comments_by_document:
|
||||
comments_by_document[dokument] = []
|
||||
comments_by_document[dokument].append(comment)
|
||||
|
||||
return render(request, 'standards/user_comments.html', {
|
||||
'comments_by_document': comments_by_document,
|
||||
'total_comments': user_comments.count(),
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(is_staff_user)
|
||||
def all_comments(request):
|
||||
"""
|
||||
Display all comments from all users, grouped by document.
|
||||
Staff only.
|
||||
"""
|
||||
# Get all comments
|
||||
all_comments_qs = VorgabeComment.objects.select_related(
|
||||
'vorgabe', 'vorgabe__dokument', 'user'
|
||||
).order_by(
|
||||
'vorgabe__dokument__nummer', '-created_at'
|
||||
)
|
||||
|
||||
# Group comments by document
|
||||
comments_by_document = {}
|
||||
for comment in all_comments_qs:
|
||||
dokument = comment.vorgabe.dokument
|
||||
if dokument not in comments_by_document:
|
||||
comments_by_document[dokument] = []
|
||||
comments_by_document[dokument].append(comment)
|
||||
|
||||
return render(request, 'standards/all_comments.html', {
|
||||
'comments_by_document': comments_by_document,
|
||||
'total_comments': all_comments_qs.count(),
|
||||
})
|
||||
|
||||
@@ -24,8 +24,8 @@ spec:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
containers:
|
||||
- name: web
|
||||
image: docker.io/adebaumann/vui:0.918
|
||||
- name: web
|
||||
image: docker.io/adebaumann/vui:0.917
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
|
||||
@@ -51,22 +51,18 @@
|
||||
<span class="hidden-xs" style="margin-left: 0;">{{ user.first_name }} {{ user.last_name }}</span>
|
||||
<span class="caret" style="margin-left: 8px;"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
||||
<li><a href="{% url 'user_comments' %}">Meine Kommentare</a></li>
|
||||
{% if user.is_staff %}
|
||||
<li><a href="{% url 'all_comments' %}">Alle Kommentare</a></li>
|
||||
{% endif %}
|
||||
<li><a href="{% url 'password_change' %}">Passwort ändern</a></li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<form method="post" action="{% url 'logout' %}" style="display: inline;">
|
||||
{% csrf_token %}
|
||||
<button type="submit" style="background: none; border: none; color: inherit; padding: 3px 20px; width: 100%; text-align: left; cursor: pointer;">
|
||||
Abmelden
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
||||
<li><a href="{% url 'password_change' %}">Passwort ändern</a></li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<form method="post" action="{% url 'logout' %}" style="display: inline;">
|
||||
{% csrf_token %}
|
||||
<button type="submit" style="background: none; border: none; color: inherit; padding: 3px 20px; width: 100%; text-align: left; cursor: pointer;">
|
||||
Abmelden
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
@@ -106,7 +102,7 @@
|
||||
<li><a href="/dokumente">Standards</a></li>
|
||||
{% if user.is_staff %}
|
||||
<li><a href="/dokumente/unvollstaendig/">Unvollständig</a></li>
|
||||
<li><a href="/autorenumgebung/">Autor</a></li>
|
||||
<li><a href="/autorenumgebung/">Autorenumgebung</a></li>
|
||||
{% endif %}
|
||||
<li><a href="/referenzen">Referenzen</a></li>
|
||||
<li><a href="/stichworte">Stichworte</a></li>
|
||||
@@ -137,7 +133,7 @@
|
||||
<a href="/dokumente/unvollstaendig/">Unvollständig</a>
|
||||
</li>
|
||||
<li class="dropdown {% if 'autorenumgebung' in request.path %}current{% endif %}">
|
||||
<a href="/autorenumgebung/">Autor</a>
|
||||
<a href="/autorenumgebung/">Autorenumgebung</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="dropdown {% if 'referenzen' in request.path %}current{% endif %}">
|
||||
@@ -219,8 +215,8 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-sm-6 text-right">
|
||||
<p class="text-muted">Version {{ version|default:"0.973" }}</p>
|
||||
</div>
|
||||
<p class="text-muted">Version {{ version|default:"0.961" }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -5,7 +5,7 @@ certifi==2025.8.3
|
||||
charset-normalizer==3.4.3
|
||||
curtsies==0.4.3
|
||||
cwcwidth==0.1.10
|
||||
Django==5.2.9
|
||||
Django==5.2.5
|
||||
django-admin-sortable2==2.2.8
|
||||
django-js-asset==3.1.2
|
||||
django-mptt==0.17.0
|
||||
@@ -30,7 +30,6 @@ pyxdg==0.28
|
||||
requests==2.32.5
|
||||
six==1.17.0
|
||||
sqlparse==0.5.3
|
||||
urllib3==2.6.0
|
||||
urllib3==2.5.0
|
||||
wcwidth==0.2.13
|
||||
bleach==6.1.0
|
||||
coverage==7.6.1
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Generate and deploy Django secret key to Kubernetes
|
||||
|
||||
NAMESPACE="vorgabenui"
|
||||
SECRET_NAME="django-secret"
|
||||
SECRET_FILE="argocd/secret.yaml"
|
||||
|
||||
# Check if secret file exists
|
||||
if [ ! -f "$SECRET_FILE" ]; then
|
||||
echo "Error: $SECRET_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate random secret key
|
||||
SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(50))")
|
||||
|
||||
# Create temporary secret file with generated key
|
||||
TEMP_SECRET_FILE=$(mktemp)
|
||||
cat "$SECRET_FILE" | sed "s/CHANGE_ME_TO_RANDOM_STRING/$SECRET_KEY/g" > "$TEMP_SECRET_FILE"
|
||||
|
||||
# Check if secret already exists
|
||||
if kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" &>/dev/null; then
|
||||
echo "Secret $SECRET_NAME already exists in namespace $NAMESPACE"
|
||||
read -p "Do you want to replace it? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted"
|
||||
rm "$TEMP_SECRET_FILE"
|
||||
exit 0
|
||||
fi
|
||||
kubectl apply -f "$TEMP_SECRET_FILE"
|
||||
echo "Secret updated successfully"
|
||||
else
|
||||
kubectl apply -f "$TEMP_SECRET_FILE"
|
||||
echo "Secret created successfully"
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm "$TEMP_SECRET_FILE"
|
||||
|
||||
echo ""
|
||||
echo "Secret deployed:"
|
||||
echo " Name: $SECRET_NAME"
|
||||
echo " Namespace: $NAMESPACE"
|
||||
echo " Key: secret-key"
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Full deployment script - bumps both container versions by 0.001 and copies database
|
||||
|
||||
DEPLOYMENT_FILE="argocd/deployment.yaml"
|
||||
DB_SOURCE="data/db.sqlite3"
|
||||
DB_DEST="data-loader/preload.sqlite3"
|
||||
|
||||
# Check if deployment file exists
|
||||
if [ ! -f "$DEPLOYMENT_FILE" ]; then
|
||||
echo "Error: $DEPLOYMENT_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if source database exists
|
||||
if [ ! -f "$DB_SOURCE" ]; then
|
||||
echo "Error: $DB_SOURCE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract current version of data-loader
|
||||
LOADER_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vgui-data-loader:[0-9]" "$DEPLOYMENT_FILE" | sed -E 's/.*:([0-9.]+)/\1/')
|
||||
|
||||
# Extract current version of main container
|
||||
MAIN_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vgui:[0-9]" "$DEPLOYMENT_FILE" | grep -v "data-loader" | sed -E 's/.*:([0-9.]+)/\1/')
|
||||
|
||||
if [ -z "$LOADER_VERSION" ] || [ -z "$MAIN_VERSION" ]; then
|
||||
echo "Error: Could not find current versions"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Calculate new versions (add 0.001), preserve leading zero
|
||||
NEW_LOADER_VERSION=$(echo "$LOADER_VERSION + 0.001" | bc | sed 's/^\./0./')
|
||||
NEW_MAIN_VERSION=$(echo "$MAIN_VERSION + 0.001" | bc | sed 's/^\./0./')
|
||||
|
||||
# Update the deployment file
|
||||
sed -i "s|image: git.baumann.gr/adebaumann/labhelper-data-loader:$LOADER_VERSION|image: git.baumann.gr/adebaumann/labhelper-data-loader:$NEW_LOADER_VERSION|" "$DEPLOYMENT_FILE"
|
||||
sed -i "s|image: git.baumann.gr/adebaumann/labhelper:$MAIN_VERSION|image: git.baumann.gr/adebaumann/labhelper:$NEW_MAIN_VERSION|" "$DEPLOYMENT_FILE"
|
||||
|
||||
# Copy database
|
||||
cp "$DB_SOURCE" "$DB_DEST"
|
||||
|
||||
echo "Full deployment prepared:"
|
||||
echo " Data loader: $LOADER_VERSION -> $NEW_LOADER_VERSION"
|
||||
echo " Main container: $MAIN_VERSION -> $NEW_MAIN_VERSION"
|
||||
echo " Database copied to $DB_DEST"
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Partial deployment script - bumps main container version by 0.001
|
||||
|
||||
DEPLOYMENT_FILE="argocd/deployment.yaml"
|
||||
|
||||
# Check if file exists
|
||||
if [ ! -f "$DEPLOYMENT_FILE" ]; then
|
||||
echo "Error: $DEPLOYMENT_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract current version of main container (labhelper, not labhelper-data-loader)
|
||||
CURRENT_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vui:[0-9]" "$DEPLOYMENT_FILE" | grep -v "data-loader" | sed -E 's/.*:([0-9.]+)/\1/')
|
||||
|
||||
if [ -z "$CURRENT_VERSION" ]; then
|
||||
echo "Error: Could not find current version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Calculate new version (add 0.001), preserve leading zero
|
||||
NEW_VERSION=$(echo "$CURRENT_VERSION + 0.001" | bc | sed 's/^\./0./')
|
||||
|
||||
# Update the deployment file (only the main container, not the data-loader)
|
||||
sed -i "s|image: git.baumann.gr/adebaumann/vui:$CURRENT_VERSION|image: git.baumann.gr/adebaumann/vui:$NEW_VERSION|" "$DEPLOYMENT_FILE"
|
||||
|
||||
echo "Partial deployment prepared:"
|
||||
echo " Main container: $CURRENT_VERSION -> $NEW_VERSION"
|
||||
Reference in New Issue
Block a user