Compare commits
35 Commits
1af50c45ff
...
feature/da
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a1df7345d | |||
| e3c5f6a9d7 | |||
| a26290fc92 | |||
| 08d94a9269 | |||
| 6f8f273344 | |||
| f96226170b | |||
| 0783033c70 | |||
| 35fbfdccec | |||
| 1196d3cdd2 | |||
| df67948efc | |||
| a78f53f58e | |||
| 2c39db104e | |||
| ad17b394a3 | |||
| 745ce4fabc | |||
| b6fbe750a2 | |||
| 89d3eec5fb | |||
| cd4783efc4 | |||
| 9efef2c5e2 | |||
| 09010a117e | |||
| 8ea0937ea4 | |||
| 5330493c85 | |||
| 9e6e9e9830 | |||
| f311050412 | |||
| 492b3c5a20 | |||
| a81b6eb9d5 | |||
| f6be6d6a02 | |||
| c8d3ef4631 | |||
| 46912cff8c | |||
| 3a89f6d871 | |||
| 048105ef27 | |||
| b579f5fb42 | |||
| db9bd92036 | |||
| 7e89ffb6f1 | |||
| dd6d0fae46 | |||
| e5202d9b2b |
@@ -211,28 +211,17 @@ jobs:
|
|||||||
echo "ERROR: Found $ctype \"$cname\" image repo is \"$new_repo\" but expected \"$expected_repo\""
|
echo "ERROR: Found $ctype \"$cname\" image repo is \"$new_repo\" but expected \"$expected_repo\""
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ -n "${old_image:-}" ]; then
|
|
||||||
old_tag="${old_image##*:}"
|
|
||||||
else
|
|
||||||
old_tag=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
registry="$(echo "$new_repo" | awk -F/ '{print $1}')"
|
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_image=$new_image"
|
||||||
echo "new_repo=$new_repo"
|
echo "new_repo=$new_repo"
|
||||||
echo "new_tag=$new_tag"
|
echo "new_tag=$new_tag"
|
||||||
echo "registry=$registry"
|
echo "registry=$registry"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$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
|
- name: Check if image exists on registry
|
||||||
if: steps.img.outputs.changed == 'true'
|
|
||||||
id: check_image
|
id: check_image
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -267,15 +256,15 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Skip if image already exists
|
- name: Skip if image already exists
|
||||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'true'
|
if: steps.check_image.outputs.exists == 'true'
|
||||||
run: echo "${{ matrix.description }} image ${{ steps.img.outputs.new_image }} already exists on registry; skipping build."
|
run: echo "${{ matrix.description }} image ${{ steps.img.outputs.new_image }} already exists on registry; skipping build."
|
||||||
|
|
||||||
- name: Set up Buildx
|
- name: Set up Buildx
|
||||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
if: steps.check_image.outputs.exists == 'false'
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to registry
|
- name: Log in to registry
|
||||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
if: steps.check_image.outputs.exists == 'false'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ steps.img.outputs.registry }}
|
registry: ${{ steps.img.outputs.registry }}
|
||||||
@@ -283,7 +272,7 @@ jobs:
|
|||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push ${{ matrix.description }} (exact tag from deployment)
|
- name: Build and push ${{ matrix.description }} (exact tag from deployment)
|
||||||
if: steps.img.outputs.changed == 'true' && steps.check_image.outputs.exists == 'false'
|
if: steps.check_image.outputs.exists == 'false'
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ${{ matrix.build_context }}
|
context: ${{ matrix.build_context }}
|
||||||
|
|||||||
67
.gitea/workflows/check_code_in_sonarqube.yaml
Normal file
67
.gitea/workflows/check_code_in_sonarqube.yaml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
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
|
||||||
15
Dockerfile
15
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.13-slim AS baustelle
|
FROM python:3.14 AS baustelle
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
@@ -7,22 +7,21 @@ RUN pip install --upgrade pip
|
|||||||
COPY requirements.txt /app/
|
COPY requirements.txt /app/
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
FROM python:3.13-slim
|
FROM python:3.14-slim
|
||||||
RUN useradd -m -r appuser && \
|
RUN useradd -m -r appuser && \
|
||||||
mkdir /app && \
|
mkdir /app && \
|
||||||
chown -R appuser /app
|
chown -R appuser /app
|
||||||
|
|
||||||
COPY --from=baustelle /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
|
COPY --from=baustelle /usr/local/lib/python3.14/site-packages/ /usr/local/lib/python3.14/site-packages/
|
||||||
COPY --from=baustelle /usr/local/bin/ /usr/local/bin/
|
COPY --from=baustelle /usr/local/bin/ /usr/local/bin/
|
||||||
RUN rm /usr/bin/tar
|
RUN rm /usr/bin/tar /usr/lib/x86_64-linux-gnu/libncur*
|
||||||
RUN rm /usr/lib/x86_64-linux-gnu/libncur*
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --chown=appuser:appuser . .
|
COPY --chown=appuser:appuser . .
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
USER appuser
|
USER appuser
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
RUN rm -rf /app/Dockerfile* \
|
RUN rm -rvf /app/Dockerfile* \
|
||||||
/app/README.md \
|
/app/README.md \
|
||||||
/app/argocd \
|
/app/argocd \
|
||||||
/app/k8s \
|
/app/k8s \
|
||||||
@@ -31,7 +30,7 @@ RUN rm -rf /app/Dockerfile* \
|
|||||||
/app/requirements.txt \
|
/app/requirements.txt \
|
||||||
/app/node_modules \
|
/app/node_modules \
|
||||||
/app/*.json \
|
/app/*.json \
|
||||||
/app/test_*.py
|
/app/test_*.py && \
|
||||||
RUN python3 manage.py collectstatic
|
python3 /app/manage.py collectstatic --noinput
|
||||||
CMD ["gunicorn","--bind","0.0.0.0:8000","--workers","3","VorgabenUI.wsgi:application"]
|
CMD ["gunicorn","--bind","0.0.0.0:8000","--workers","3","VorgabenUI.wsgi:application"]
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ Die abschnitte App enthält 33 Tests, die Modelle, Utility-Funktionen, Diagram-C
|
|||||||
|
|
||||||
## dokumente App Tests
|
## dokumente App Tests
|
||||||
|
|
||||||
Die dokumente App enthält 98 Tests und ist damit die umfassendste Test-Suite, die alle Modelle, Views, URLs und Geschäftslogik abdeckt.
|
Die dokumente App enthält 121 Tests und ist damit die umfassendste Test-Suite, die alle Modelle, Views, URLs, Geschäftslogik und Kommentarfunktionalität mit XSS-Schutz abdeckt.
|
||||||
|
|
||||||
### Modell-Tests
|
### Modell-Tests
|
||||||
|
|
||||||
@@ -131,6 +131,14 @@ Die dokumente App enthält 98 Tests und ist damit die umfassendste Test-Suite, d
|
|||||||
- **test_checklistenfrage_str**: Überprüft, dass die String-Repräsentation lange Fragen kürzt
|
- **test_checklistenfrage_str**: Überprüft, dass die String-Repräsentation lange Fragen kürzt
|
||||||
- **test_checklistenfrage_related_name**: Testet die umgekehrte Beziehung von Vorgabe
|
- **test_checklistenfrage_related_name**: Testet die umgekehrte Beziehung von Vorgabe
|
||||||
|
|
||||||
|
#### VorgabeCommentModelTest
|
||||||
|
- **test_comment_creation**: Testet die Erstellung von VorgabeComment mit Vorgabe, Benutzer und Text
|
||||||
|
- **test_comment_str**: Überprüft, dass die String-Repräsentation Benutzername und Vorgabennummer enthält
|
||||||
|
- **test_comment_related_name**: Testet die umgekehrte Beziehung von Vorgabe
|
||||||
|
- **test_comment_ordering**: Testet, dass Kommentare nach created_at absteigend sortiert sind (neueste zuerst)
|
||||||
|
- **test_comment_timestamps_auto_update**: Testet, dass sich updated_at ändert, wenn ein Kommentar geändert wird
|
||||||
|
- **test_multiple_users_can_comment**: Testet, dass mehrere Benutzer zur selben Vorgabe kommentieren können
|
||||||
|
|
||||||
### Text-Abschnitt-Tests
|
### Text-Abschnitt-Tests
|
||||||
|
|
||||||
#### DokumentTextAbschnitteTest
|
#### DokumentTextAbschnitteTest
|
||||||
@@ -217,6 +225,40 @@ Die dokumente App enthält 98 Tests und ist damit die umfassendste Test-Suite, d
|
|||||||
- **test_vorgabe_links**: Testet, dass Vorgaben zu korrekten Admin-Seiten verlinken
|
- **test_vorgabe_links**: Testet, dass Vorgaben zu korrekten Admin-Seiten verlinken
|
||||||
- **test_back_link**: Testet, dass der Zurück-Link zur Standardübersicht existiert
|
- **test_back_link**: Testet, dass der Zurück-Link zur Standardübersicht existiert
|
||||||
|
|
||||||
|
### Kommentar-Funktionalität Tests
|
||||||
|
|
||||||
|
#### GetVorgabeCommentsViewTest
|
||||||
|
- **test_get_comments_requires_login**: Testet, dass anonyme Benutzer keine Kommentare sehen können und weitergeleitet werden
|
||||||
|
- **test_regular_user_sees_only_own_comments**: Testet, dass normale Benutzer nur ihre eigenen Kommentare sehen
|
||||||
|
- **test_staff_user_sees_all_comments**: Testet, dass Staff-Benutzer alle Kommentare sehen können
|
||||||
|
- **test_get_comments_returns_404_for_nonexistent_vorgabe**: Testet 404-Antwort für nicht existierende Vorgabe
|
||||||
|
- **test_comments_are_html_escaped**: Testet HTML-Escaping zur Verhinderung von XSS-Angriffen (z.B. `<script>`-Tags)
|
||||||
|
- **test_line_breaks_preserved**: Testet, dass Zeilenumbrüche in `<br>`-Tags umgewandelt werden
|
||||||
|
- **test_security_headers_present**: Testet, dass Content-Security-Policy und X-Content-Type-Options Header gesetzt sind
|
||||||
|
|
||||||
|
#### AddVorgabeCommentViewTest
|
||||||
|
- **test_add_comment_requires_login**: Testet, dass anonyme Benutzer keine Kommentare hinzufügen können
|
||||||
|
- **test_add_comment_requires_post**: Testet, dass nur POST-Methode erlaubt ist (405 für GET)
|
||||||
|
- **test_add_comment_success**: Testet erfolgreiche Kommentarerstellung mit gültigen Daten
|
||||||
|
- **test_add_empty_comment_fails**: Testet, dass leere Kommentare mit 400-Fehler abgelehnt werden
|
||||||
|
- **test_add_whitespace_only_comment_fails**: Testet, dass Kommentare nur mit Leerzeichen abgelehnt werden
|
||||||
|
- **test_add_too_long_comment_fails**: Testet, dass Kommentare über 2000 Zeichen abgelehnt werden
|
||||||
|
- **test_add_comment_xss_script_tag_blocked**: Testet, dass Kommentare mit `<script>`-Tags blockiert werden
|
||||||
|
- **test_add_comment_xss_javascript_protocol_blocked**: Testet, dass `javascript:`-Protokoll blockiert wird
|
||||||
|
- **test_add_comment_xss_event_handlers_blocked**: Testet, dass Event-Handler (onload, onerror, onclick, onmouseover) blockiert werden
|
||||||
|
- **test_add_comment_invalid_json_fails**: Testet, dass ungültige JSON-Payloads abgelehnt werden
|
||||||
|
- **test_add_comment_nonexistent_vorgabe_fails**: Testet 404-Antwort für nicht existierende Vorgabe
|
||||||
|
- **test_add_comment_security_headers**: Testet, dass Sicherheits-Header in Antworten vorhanden sind
|
||||||
|
|
||||||
|
#### DeleteVorgabeCommentViewTest
|
||||||
|
- **test_delete_comment_requires_login**: Testet, dass anonyme Benutzer keine Kommentare löschen können
|
||||||
|
- **test_delete_comment_requires_post**: Testet, dass nur POST-Methode erlaubt ist (405 für GET)
|
||||||
|
- **test_user_can_delete_own_comment**: Testet, dass Benutzer ihre eigenen Kommentare löschen können
|
||||||
|
- **test_user_cannot_delete_other_users_comment**: Testet, dass Benutzer keine Kommentare anderer löschen können (403 Forbidden)
|
||||||
|
- **test_staff_can_delete_any_comment**: Testet, dass Staff-Benutzer jeden Kommentar löschen können
|
||||||
|
- **test_delete_nonexistent_comment_returns_404**: Testet 404-Antwort für nicht existierenden Kommentar
|
||||||
|
- **test_delete_comment_security_headers**: Testet, dass Sicherheits-Header in Antworten vorhanden sind
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## pages App Tests
|
## pages App Tests
|
||||||
@@ -333,9 +375,17 @@ Die stichworte App enthält 18 Tests, die Schlüsselwortmodelle und ihre Sortier
|
|||||||
|
|
||||||
## Test-Statistiken
|
## Test-Statistiken
|
||||||
|
|
||||||
- **Gesamt-Tests**: 207
|
- **Gesamt-Tests**: 230
|
||||||
- **abschnitte**: 33 Tests (einschließlich XSS-Prävention)
|
- **abschnitte**: 33 Tests (einschließlich XSS-Prävention)
|
||||||
- **dokumente**: 116 Tests (98 in tests.py + 9 in test_json.py + 9 JSON-Tests in Haupt-tests.py)
|
- **dokumente**: 121 Tests (einschließlich Kommentarfunktionalität mit XSS-Schutz)
|
||||||
|
- Modell-Tests: 44 Tests
|
||||||
|
- View-Tests: 7 Tests
|
||||||
|
- URL-Pattern-Tests: 4 Tests
|
||||||
|
- Sanity-Check-Tests: 16 Tests
|
||||||
|
- Management-Befehl-Tests: 2 Tests
|
||||||
|
- JSON-Export-Tests: 9 Tests
|
||||||
|
- Unvollständige-Vorgaben-Tests: 15 Tests
|
||||||
|
- Kommentar-Tests: 24 Tests (6 Modell + 18 View-Tests)
|
||||||
- **pages**: 4 Tests
|
- **pages**: 4 Tests
|
||||||
- **referenzen**: 18 Tests
|
- **referenzen**: 18 Tests
|
||||||
- **rollen**: 18 Tests
|
- **rollen**: 18 Tests
|
||||||
@@ -349,7 +399,17 @@ Die stichworte App enthält 18 Tests, die Schlüsselwortmodelle und ihre Sortier
|
|||||||
4. **Utility-Funktionen**: Textverarbeitung, Caching, Formatierung
|
4. **Utility-Funktionen**: Textverarbeitung, Caching, Formatierung
|
||||||
5. **Management-Befehle**: CLI-Schnittstelle und Ausgabeverarbeitung
|
5. **Management-Befehle**: CLI-Schnittstelle und Ausgabeverarbeitung
|
||||||
6. **Integration**: App-übergreifende Funktionalität und Datenfluss
|
6. **Integration**: App-übergreifende Funktionalität und Datenfluss
|
||||||
7. **Sicherheit**: XSS-Prävention durch HTML-Bereinigung beim Rendern von Inhalten
|
7. **Sicherheit**:
|
||||||
|
- XSS-Prävention durch HTML-Bereinigung beim Rendern von Inhalten
|
||||||
|
- XSS-Angriffsverhinderung im Kommentarsystem (Script-Tags, javascript:-Protokoll, Event-Handler)
|
||||||
|
- Eingabevalidierung und -bereinigung
|
||||||
|
- Autorisierungsprüfungen (Staff vs. normale Benutzer)
|
||||||
|
- Sicherheits-Header (Content-Security-Policy, X-Content-Type-Options)
|
||||||
|
8. **Kommentar-Funktionalität**:
|
||||||
|
- CRUD-Operationen (Create, Read, Delete)
|
||||||
|
- Benutzerberechtigungen und -besitz
|
||||||
|
- HTML-Escaping und Erhalt von Zeilenumbrüchen
|
||||||
|
- Verhinderung mehrerer XSS-Angriffsvektoren
|
||||||
|
|
||||||
## Ausführen der Tests
|
## Ausführen der Tests
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ The abschnitte app contains 33 tests covering models, utility functions, diagram
|
|||||||
|
|
||||||
## dokumente App Tests
|
## dokumente App Tests
|
||||||
|
|
||||||
The dokumente app contains 98 tests, making it the most comprehensive test suite, covering all models, views, URLs, and business logic.
|
The dokumente app contains 121 tests, making it the most comprehensive test suite, covering all models, views, URLs, business logic, and comment functionality with XSS protection.
|
||||||
|
|
||||||
### Model Tests
|
### Model Tests
|
||||||
|
|
||||||
@@ -131,6 +131,14 @@ The dokumente app contains 98 tests, making it the most comprehensive test suite
|
|||||||
- **test_checklistenfrage_str**: Verifies string representation truncates long questions
|
- **test_checklistenfrage_str**: Verifies string representation truncates long questions
|
||||||
- **test_checklistenfrage_related_name**: Tests the reverse relationship from Vorgabe
|
- **test_checklistenfrage_related_name**: Tests the reverse relationship from Vorgabe
|
||||||
|
|
||||||
|
#### VorgabeCommentModelTest
|
||||||
|
- **test_comment_creation**: Tests VorgabeComment creation with vorgabe, user, and text
|
||||||
|
- **test_comment_str**: Verifies string representation includes username and Vorgabennummer
|
||||||
|
- **test_comment_related_name**: Tests the reverse relationship from Vorgabe
|
||||||
|
- **test_comment_ordering**: Tests comments are ordered by created_at descending (newest first)
|
||||||
|
- **test_comment_timestamps_auto_update**: Tests that updated_at changes when comment is modified
|
||||||
|
- **test_multiple_users_can_comment**: Tests multiple users can comment on same Vorgabe
|
||||||
|
|
||||||
### Text Abschnitt Tests
|
### Text Abschnitt Tests
|
||||||
|
|
||||||
#### DokumentTextAbschnitteTest
|
#### DokumentTextAbschnitteTest
|
||||||
@@ -217,6 +225,40 @@ The dokumente app contains 98 tests, making it the most comprehensive test suite
|
|||||||
- **test_vorgabe_links**: Tests Vorgaben link to correct admin pages
|
- **test_vorgabe_links**: Tests Vorgaben link to correct admin pages
|
||||||
- **test_back_link**: Tests back link to standard list exists
|
- **test_back_link**: Tests back link to standard list exists
|
||||||
|
|
||||||
|
### Comment Functionality Tests
|
||||||
|
|
||||||
|
#### GetVorgabeCommentsViewTest
|
||||||
|
- **test_get_comments_requires_login**: Tests anonymous users cannot view comments and are redirected
|
||||||
|
- **test_regular_user_sees_only_own_comments**: Tests regular users only see their own comments
|
||||||
|
- **test_staff_user_sees_all_comments**: Tests staff users can see all comments
|
||||||
|
- **test_get_comments_returns_404_for_nonexistent_vorgabe**: Tests 404 response for non-existent Vorgabe
|
||||||
|
- **test_comments_are_html_escaped**: Tests HTML escaping prevents XSS attacks (e.g., `<script>` tags)
|
||||||
|
- **test_line_breaks_preserved**: Tests line breaks are converted to `<br>` tags
|
||||||
|
- **test_security_headers_present**: Tests Content-Security-Policy and X-Content-Type-Options headers are set
|
||||||
|
|
||||||
|
#### AddVorgabeCommentViewTest
|
||||||
|
- **test_add_comment_requires_login**: Tests anonymous users cannot add comments
|
||||||
|
- **test_add_comment_requires_post**: Tests only POST method is allowed (405 for GET)
|
||||||
|
- **test_add_comment_success**: Tests successful comment creation with valid data
|
||||||
|
- **test_add_empty_comment_fails**: Tests empty comments are rejected with 400 error
|
||||||
|
- **test_add_whitespace_only_comment_fails**: Tests whitespace-only comments are rejected
|
||||||
|
- **test_add_too_long_comment_fails**: Tests comments exceeding 2000 characters are rejected
|
||||||
|
- **test_add_comment_xss_script_tag_blocked**: Tests comments with `<script>` tags are blocked
|
||||||
|
- **test_add_comment_xss_javascript_protocol_blocked**: Tests `javascript:` protocol is blocked
|
||||||
|
- **test_add_comment_xss_event_handlers_blocked**: Tests event handlers (onload, onerror, onclick, onmouseover) are blocked
|
||||||
|
- **test_add_comment_invalid_json_fails**: Tests invalid JSON payloads are rejected
|
||||||
|
- **test_add_comment_nonexistent_vorgabe_fails**: Tests 404 response for non-existent Vorgabe
|
||||||
|
- **test_add_comment_security_headers**: Tests security headers are present in responses
|
||||||
|
|
||||||
|
#### DeleteVorgabeCommentViewTest
|
||||||
|
- **test_delete_comment_requires_login**: Tests anonymous users cannot delete comments
|
||||||
|
- **test_delete_comment_requires_post**: Tests only POST method is allowed (405 for GET)
|
||||||
|
- **test_user_can_delete_own_comment**: Tests users can delete their own comments
|
||||||
|
- **test_user_cannot_delete_other_users_comment**: Tests users cannot delete others' comments (403 Forbidden)
|
||||||
|
- **test_staff_can_delete_any_comment**: Tests staff users can delete any comment
|
||||||
|
- **test_delete_nonexistent_comment_returns_404**: Tests 404 response for non-existent comment
|
||||||
|
- **test_delete_comment_security_headers**: Tests security headers are present in responses
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## pages App Tests
|
## pages App Tests
|
||||||
@@ -333,9 +375,17 @@ The stichworte app contains 18 tests covering keyword models and their ordering.
|
|||||||
|
|
||||||
## Test Statistics
|
## Test Statistics
|
||||||
|
|
||||||
- **Total Tests**: 207
|
- **Total Tests**: 230
|
||||||
- **abschnitte**: 33 tests (including XSS prevention)
|
- **abschnitte**: 33 tests (including XSS prevention)
|
||||||
- **dokumente**: 116 tests (98 in tests.py + 9 in test_json.py + 9 JSON tests in main tests.py)
|
- **dokumente**: 121 tests (including comment functionality with XSS protection)
|
||||||
|
- Model tests: 44 tests
|
||||||
|
- View tests: 7 tests
|
||||||
|
- URL pattern tests: 4 tests
|
||||||
|
- Sanity check tests: 16 tests
|
||||||
|
- Management command tests: 2 tests
|
||||||
|
- JSON export tests: 9 tests
|
||||||
|
- Incomplete Vorgaben tests: 15 tests
|
||||||
|
- Comment tests: 24 tests (6 model + 18 view tests)
|
||||||
- **pages**: 4 tests
|
- **pages**: 4 tests
|
||||||
- **referenzen**: 18 tests
|
- **referenzen**: 18 tests
|
||||||
- **rollen**: 18 tests
|
- **rollen**: 18 tests
|
||||||
@@ -349,7 +399,17 @@ The stichworte app contains 18 tests covering keyword models and their ordering.
|
|||||||
4. **Utility Functions**: Text processing, caching, formatting
|
4. **Utility Functions**: Text processing, caching, formatting
|
||||||
5. **Management Commands**: CLI interface and output handling
|
5. **Management Commands**: CLI interface and output handling
|
||||||
6. **Integration**: Cross-app functionality and data flow
|
6. **Integration**: Cross-app functionality and data flow
|
||||||
7. **Security**: XSS prevention through HTML sanitization in content rendering
|
7. **Security**:
|
||||||
|
- XSS prevention through HTML sanitization in content rendering
|
||||||
|
- XSS attack prevention in comment system (script tags, javascript: protocol, event handlers)
|
||||||
|
- Input validation and sanitization
|
||||||
|
- Authorization checks (staff vs. regular users)
|
||||||
|
- Security headers (Content-Security-Policy, X-Content-Type-Options)
|
||||||
|
8. **Comment Functionality**:
|
||||||
|
- CRUD operations (Create, Read, Delete)
|
||||||
|
- User permissions and ownership
|
||||||
|
- HTML escaping and line break preservation
|
||||||
|
- Multiple XSS attack vector prevention
|
||||||
|
|
||||||
## Running the Tests
|
## Running the Tests
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
SECRET_KEY = os.environ.get("SECRET_KEY")
|
SECRET_KEY = os.environ.get("SECRET_KEY")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# 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(",")
|
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS","127.0.0.1").split(",")
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ USE_TZ = True
|
|||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
#STATIC_ROOT="/home/adebaumann/VorgabenUI/staticfiles/"
|
#STATIC_ROOT="/home/adebaumann/VorgabenUI/staticfiles/"
|
||||||
STATIC_ROOT="/app/staticfiles/"
|
STATIC_ROOT="staticfiles/"
|
||||||
STATICFILES_DIRS= (
|
STATICFILES_DIRS= (
|
||||||
os.path.join(BASE_DIR,"static"),
|
os.path.join(BASE_DIR,"static"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ spec:
|
|||||||
fsGroupChangePolicy: "OnRootMismatch"
|
fsGroupChangePolicy: "OnRootMismatch"
|
||||||
initContainers:
|
initContainers:
|
||||||
- name: loader
|
- name: loader
|
||||||
image: git.baumann.gr/adebaumann/vui-data-loader:0.9
|
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" ]
|
command: [ "sh","-c","cp -n preload/preload.sqlite3 /data/db.sqlite3; chown -R 999:999 /data; ls -la /data; sleep 10; exit 0" ]
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: data
|
- name: data
|
||||||
mountPath: /data
|
mountPath: /data
|
||||||
containers:
|
containers:
|
||||||
- name: web
|
- name: web
|
||||||
image: git.baumann.gr/adebaumann/vui:0.960
|
image: git.baumann.gr/adebaumann/vui:0.968
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
Binary file not shown.
BIN
data/db.sqlite3
BIN
data/db.sqlite3
Binary file not shown.
@@ -293,6 +293,6 @@ class VorgabeAdmin(NestedModelAdmin):
|
|||||||
|
|
||||||
admin.site.register(Checklistenfrage)
|
admin.site.register(Checklistenfrage)
|
||||||
admin.site.register(Dokumententyp)
|
admin.site.register(Dokumententyp)
|
||||||
#admin.site.register(Person)
|
admin.site.register(VorgabeComment)
|
||||||
|
|
||||||
#admin.site.register(Changelog)
|
#admin.site.register(Changelog)
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Generated by Django 5.2.5 on 2025-11-27 22:02
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dokumente', '0009_alter_vorgabe_options_vorgabe_order'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VorgabenTable',
|
||||||
|
fields=[
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Vorgabe (Tabellenansicht)',
|
||||||
|
'verbose_name_plural': 'Vorgaben (Tabellenansicht)',
|
||||||
|
'proxy': True,
|
||||||
|
'indexes': [],
|
||||||
|
'constraints': [],
|
||||||
|
},
|
||||||
|
bases=('dokumente.vorgabe',),
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='person',
|
||||||
|
options={'ordering': ['name'], 'verbose_name_plural': 'Personen'},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VorgabeComment',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('text', models.TextField()),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
('vorgabe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='dokumente.vorgabe')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Vorgabe-Kommentar',
|
||||||
|
'verbose_name_plural': 'Vorgabe-Kommentare',
|
||||||
|
'ordering': ['-created_at'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from mptt.models import MPTTModel, TreeForeignKey
|
from mptt.models import MPTTModel, TreeForeignKey
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from abschnitte.models import Textabschnitt
|
from abschnitte.models import Textabschnitt
|
||||||
from stichworte.models import Stichwort
|
from stichworte.models import Stichwort
|
||||||
from referenzen.models import Referenz
|
from referenzen.models import Referenz
|
||||||
@@ -53,6 +54,34 @@ class Dokument(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.nummer} – {self.name}"
|
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:
|
class Meta:
|
||||||
verbose_name_plural="Dokumente"
|
verbose_name_plural="Dokumente"
|
||||||
verbose_name="Dokument"
|
verbose_name="Dokument"
|
||||||
@@ -261,3 +290,19 @@ class Changelog(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural="Changelog"
|
verbose_name_plural="Changelog"
|
||||||
verbose_name="Changelog-Eintrag"
|
verbose_name="Changelog-Eintrag"
|
||||||
|
|
||||||
|
|
||||||
|
class VorgabeComment(models.Model):
|
||||||
|
vorgabe = models.ForeignKey(Vorgabe, on_delete=models.CASCADE, related_name='comments')
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
text = models.TextField()
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Vorgabe-Kommentar"
|
||||||
|
verbose_name_plural = "Vorgabe-Kommentare"
|
||||||
|
ordering = ['-created_at']
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Kommentar von {self.user.username} zu {self.vorgabe.Vorgabennummer()}"
|
||||||
|
|||||||
67
dokumente/templates/standards/all_comments.html
Normal file
67
dokumente/templates/standards/all_comments.html
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
{% 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 %}
|
||||||
@@ -105,13 +105,13 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="alert alert-success" role="alert">
|
<div class="alert alert-success" role="alert">
|
||||||
<h4 class="alert-heading">
|
<h4 class="alert-heading">
|
||||||
<i class="fas fa-check-circle"></i> Alle Vorgaben sind vollständig!
|
<span class="emoji-icon">✅</span> Alle Vorgaben sind vollständig!
|
||||||
</h4>
|
</h4>
|
||||||
<p>Alle Vorgaben haben Referenzen, Stichworte, Text und Checklistenfragen.</p>
|
<p>Alle Vorgaben haben Referenzen, Stichworte, Text und Checklistenfragen.</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p class="mb-0">
|
<p class="mb-0">
|
||||||
<a href="{% url 'standard_list' %}" class="btn btn-primary">
|
<a href="{% url 'standard_list' %}" class="btn btn-primary">
|
||||||
<i class="fas fa-list"></i> Zurück zur Übersicht
|
<span class="emoji-icon">📋</span> Zurück zur Übersicht
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,7 +119,7 @@
|
|||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<a href="{% url 'standard_list' %}" class="btn btn-secondary">
|
<a href="{% url 'standard_list' %}" class="btn btn-secondary">
|
||||||
<i class="fas fa-arrow-left"></i> Zurück zur Übersicht
|
<span class="emoji-icon">←</span> Zurück zur Übersicht
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,25 @@
|
|||||||
<strong>Historische Version vom {{ standard.check_date }}</strong>
|
<strong>Historische Version vom {{ standard.check_date }}</strong>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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 -->
|
<!-- Einleitung -->
|
||||||
{% if standard.einleitung_html %}
|
{% if standard.einleitung_html %}
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
@@ -145,6 +164,20 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Comment Button -->
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<div class="mt-3 text-right">
|
||||||
|
<button class="btn btn-sm btn-outline-primary comment-btn"
|
||||||
|
data-vorgabe-id="{{ vorgabe.id }}"
|
||||||
|
data-vorgabe-nummer="{{ vorgabe.Vorgabennummer }}">
|
||||||
|
<span class="emoji-icon">💬</span> Kommentare
|
||||||
|
{% if vorgabe.comment_count > 0 %}
|
||||||
|
<span class="comment-count">{{ vorgabe.comment_count }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -176,4 +209,210 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Comment Modal -->
|
||||||
|
<div class="modal fade" id="commentModal" tabindex="-1" role="dialog" aria-labelledby="commentModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="commentModalLabel">Kommentare für <span id="modalVorgabeNummer"></span></h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div id="commentsContainer">
|
||||||
|
<!-- Comments will be loaded here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Comment Form -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<h6>Neuen Kommentar hinzufügen:</h6>
|
||||||
|
<textarea id="newCommentText" class="form-control" rows="3" placeholder="Ihr Kommentar..."></textarea>
|
||||||
|
<button id="addCommentBtn" class="btn btn-primary btn-sm mt-2">Kommentar hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- JavaScript for Comments -->
|
||||||
|
<script>
|
||||||
|
// Content Security Policy for comment system
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Prevent inline script execution in dynamically loaded content
|
||||||
|
const commentsContainer = document.getElementById('commentsContainer');
|
||||||
|
if (commentsContainer) {
|
||||||
|
// Use DOMPurify-like approach - only allow safe HTML
|
||||||
|
const allowedTags = ['br', 'small', 'div', 'span', 'button'];
|
||||||
|
const allowedAttributes = ['class', 'data-comment-id', 'aria-hidden'];
|
||||||
|
|
||||||
|
// Monitor for any script injection attempts
|
||||||
|
const observer = new MutationObserver(function(mutations) {
|
||||||
|
mutations.forEach(function(mutation) {
|
||||||
|
mutation.addedNodes.forEach(function(node) {
|
||||||
|
if (node.nodeType === 1) { // Element node
|
||||||
|
const tagName = node.tagName.toLowerCase();
|
||||||
|
if (tagName === 'script') {
|
||||||
|
console.warn('Script injection attempt blocked');
|
||||||
|
node.parentNode.removeChild(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(commentsContainer, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
let currentVorgabeId = null;
|
||||||
|
let currentVorgabeNummer = null;
|
||||||
|
|
||||||
|
// Comment button click handler
|
||||||
|
document.querySelectorAll('.comment-btn').forEach(btn => {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
currentVorgabeId = this.dataset.vorgabeId;
|
||||||
|
currentVorgabeNummer = this.dataset.vorgabeNummer;
|
||||||
|
|
||||||
|
document.getElementById('modalVorgabeNummer').textContent = currentVorgabeNummer;
|
||||||
|
document.getElementById('newCommentText').value = '';
|
||||||
|
|
||||||
|
loadComments();
|
||||||
|
$('#commentModal').modal('show');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load comments function
|
||||||
|
function loadComments() {
|
||||||
|
fetch(`/dokumente/comments/${currentVorgabeId}/`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
renderComments(data.comments);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error loading comments:', error);
|
||||||
|
document.getElementById('commentsContainer').innerHTML =
|
||||||
|
'<div class="alert alert-danger">Fehler beim Laden der Kommentare</div>';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render comments function
|
||||||
|
function renderComments(comments) {
|
||||||
|
const container = document.getElementById('commentsContainer');
|
||||||
|
|
||||||
|
if (comments.length === 0) {
|
||||||
|
container.innerHTML = '<p class="text-muted">Noch keine Kommentare vorhanden.</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let html = '';
|
||||||
|
comments.forEach(comment => {
|
||||||
|
const canDelete = comment.is_own || {% if user.is_authenticated %}'{{ user.is_staff|yesno:"true,false" }}'{% else %}'false'{% endif %} === 'true';
|
||||||
|
html += `
|
||||||
|
<div class="comment-item border-bottom pb-2 mb-2">
|
||||||
|
<div class="d-flex justify-content-between align-items-start">
|
||||||
|
<div class="flex-grow-1">
|
||||||
|
<strong>${comment.user}</strong>
|
||||||
|
<small class="text-muted">(${comment.created_at})</small>
|
||||||
|
${comment.updated_at !== comment.created_at ? `<small class="text-muted">(bearbeitet: ${comment.updated_at})</small>` : ''}
|
||||||
|
<div class="mt-1">${comment.text}</div>
|
||||||
|
</div>
|
||||||
|
${canDelete ? `
|
||||||
|
<button class="btn btn-sm btn-outline-danger ml-2 delete-comment-btn" data-comment-id="${comment.id}">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
// Add delete handlers
|
||||||
|
document.querySelectorAll('.delete-comment-btn').forEach(btn => {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
if (confirm('Möchten Sie diesen Kommentar wirklich löschen?')) {
|
||||||
|
deleteComment(this.dataset.commentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add comment function
|
||||||
|
document.getElementById('addCommentBtn').addEventListener('click', function() {
|
||||||
|
const text = document.getElementById('newCommentText').value.trim();
|
||||||
|
|
||||||
|
if (!text) {
|
||||||
|
alert('Bitte geben Sie einen Kommentar ein.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`/dokumente/comments/${currentVorgabeId}/add/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': getCookie('csrftoken')
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ text: text })
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
document.getElementById('newCommentText').value = '';
|
||||||
|
loadComments();
|
||||||
|
} else {
|
||||||
|
alert('Fehler: ' + (data.error || 'Unbekannter Fehler'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error adding comment:', error);
|
||||||
|
alert('Fehler beim Hinzufügen des Kommentars');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete comment function
|
||||||
|
function deleteComment(commentId) {
|
||||||
|
fetch(`/dokumente/comments/delete/${commentId}/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRFToken': getCookie('csrftoken')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
loadComments();
|
||||||
|
} else {
|
||||||
|
alert('Fehler: ' + (data.error || 'Unbekannter Fehler'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error deleting comment:', error);
|
||||||
|
alert('Fehler beim Löschen des Kommentars');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// CSRF token helper
|
||||||
|
function getCookie(name) {
|
||||||
|
let cookieValue = null;
|
||||||
|
if (document.cookie && document.cookie !== '') {
|
||||||
|
const cookies = document.cookie.split(';');
|
||||||
|
for (let i = 0; i < cookies.length; i++) {
|
||||||
|
const cookie = cookies[i].trim();
|
||||||
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||||
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cookieValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
66
dokumente/templates/standards/user_comments.html
Normal file
66
dokumente/templates/standards/user_comments.html
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{% 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 %}
|
||||||
1332
dokumente/tests.py
1332
dokumente/tests.py
File diff suppressed because it is too large
Load Diff
@@ -4,10 +4,15 @@ from . import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.standard_list, name='standard_list'),
|
path('', views.standard_list, name='standard_list'),
|
||||||
path('unvollstaendig/', views.incomplete_vorgaben, name='incomplete_vorgaben'),
|
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>/', views.standard_detail, name='standard_detail'),
|
||||||
path('<str:nummer>/history/<str:check_date>/', views.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>/history/', views.standard_detail, {"check_date":"today"}, name='standard_history'),
|
||||||
path('<str:nummer>/checkliste/', views.standard_checkliste, name='standard_checkliste'),
|
path('<str:nummer>/checkliste/', views.standard_checkliste, name='standard_checkliste'),
|
||||||
path('<str:nummer>/json/', views.standard_json, name='standard_json')
|
path('<str:nummer>/json/', views.standard_json, name='standard_json'),
|
||||||
|
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'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ from django.shortcuts import render, get_object_or_404
|
|||||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
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 json
|
||||||
from .models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Checklistenfrage
|
from .models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Checklistenfrage, VorgabeComment
|
||||||
from abschnitte.utils import render_textabschnitte
|
from abschnitte.utils import render_textabschnitte
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
@@ -45,6 +49,15 @@ def standard_detail(request, nummer,check_date=""):
|
|||||||
referenz_items.append(r.Path())
|
referenz_items.append(r.Path())
|
||||||
vorgabe.referenzpfade = referenz_items
|
vorgabe.referenzpfade = referenz_items
|
||||||
|
|
||||||
|
# Add comment count
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
if request.user.is_staff:
|
||||||
|
vorgabe.comment_count = vorgabe.comments.count()
|
||||||
|
else:
|
||||||
|
vorgabe.comment_count = vorgabe.comments.filter(user=request.user).count()
|
||||||
|
else:
|
||||||
|
vorgabe.comment_count = 0
|
||||||
|
|
||||||
return render(request, 'standards/standard_detail.html', {
|
return render(request, 'standards/standard_detail.html', {
|
||||||
'standard': standard,
|
'standard': standard,
|
||||||
'vorgaben': vorgaben,
|
'vorgaben': vorgaben,
|
||||||
@@ -237,3 +250,173 @@ def standard_json(request, nummer):
|
|||||||
|
|
||||||
# Return JSON response
|
# Return JSON response
|
||||||
return JsonResponse(doc_data, json_dumps_params={'indent': 2, 'ensure_ascii': False}, encoder=DjangoJSONEncoder)
|
return JsonResponse(doc_data, json_dumps_params={'indent': 2, 'ensure_ascii': False}, encoder=DjangoJSONEncoder)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def get_vorgabe_comments(request, vorgabe_id):
|
||||||
|
"""Get comments for a specific Vorgabe"""
|
||||||
|
vorgabe = get_object_or_404(Vorgabe, id=vorgabe_id)
|
||||||
|
|
||||||
|
if request.user.is_staff:
|
||||||
|
# Staff can see all comments
|
||||||
|
comments = vorgabe.comments.all().select_related('user').order_by('created_at')
|
||||||
|
else:
|
||||||
|
# Regular users can only see their own comments
|
||||||
|
comments = vorgabe.comments.filter(user=request.user).select_related('user').order_by('created_at')
|
||||||
|
|
||||||
|
comments_data = []
|
||||||
|
for comment in comments:
|
||||||
|
# Escape HTML but preserve line breaks
|
||||||
|
escaped_text = escape(comment.text).replace('\n', '<br>')
|
||||||
|
comments_data.append({
|
||||||
|
'id': comment.id,
|
||||||
|
'text': escaped_text,
|
||||||
|
'user': escape(comment.user.first_name+" "+comment.user.last_name),
|
||||||
|
'created_at': comment.created_at.strftime('%d.%m.%Y %H:%M'),
|
||||||
|
'updated_at': comment.updated_at.strftime('%d.%m.%Y %H:%M'),
|
||||||
|
'is_own': comment.user == request.user
|
||||||
|
})
|
||||||
|
|
||||||
|
response = JsonResponse({'comments': comments_data})
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@require_POST
|
||||||
|
@login_required
|
||||||
|
def add_vorgabe_comment(request, vorgabe_id):
|
||||||
|
"""Add a new comment to a Vorgabe"""
|
||||||
|
vorgabe = get_object_or_404(Vorgabe, id=vorgabe_id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
text = data.get('text', '').strip()
|
||||||
|
|
||||||
|
# Validate input
|
||||||
|
if not text:
|
||||||
|
return JsonResponse({'error': 'Kommentar darf nicht leer sein'}, status=400)
|
||||||
|
|
||||||
|
if len(text) > 2000: # Reasonable length limit
|
||||||
|
return JsonResponse({'error': 'Kommentar ist zu lang (max 2000 Zeichen)'}, status=400)
|
||||||
|
|
||||||
|
# Additional XSS prevention - check for dangerous patterns
|
||||||
|
dangerous_patterns = ['<script', 'javascript:', 'onload=', 'onerror=', 'onclick=', 'onmouseover=']
|
||||||
|
text_lower = text.lower()
|
||||||
|
for pattern in dangerous_patterns:
|
||||||
|
if pattern in text_lower:
|
||||||
|
return JsonResponse({'error': 'Kommentar enthält ungültige Zeichen'}, status=400)
|
||||||
|
|
||||||
|
comment = VorgabeComment.objects.create(
|
||||||
|
vorgabe=vorgabe,
|
||||||
|
user=request.user,
|
||||||
|
text=text
|
||||||
|
)
|
||||||
|
|
||||||
|
# Escape HTML but preserve line breaks
|
||||||
|
escaped_text = escape(comment.text).replace('\n', '<br>')
|
||||||
|
response = JsonResponse({
|
||||||
|
'success': True,
|
||||||
|
'comment': {
|
||||||
|
'id': comment.id,
|
||||||
|
'text': escaped_text,
|
||||||
|
'user': escape(comment.user.username),
|
||||||
|
'created_at': comment.created_at.strftime('%d.%m.%Y %H:%M'),
|
||||||
|
'updated_at': comment.updated_at.strftime('%d.%m.%Y %H:%M'),
|
||||||
|
'is_own': True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
response = JsonResponse({'error': 'Ungültige Daten'}, status=400)
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
response = JsonResponse({'error': 'Serverfehler'}, status=500)
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@require_POST
|
||||||
|
@login_required
|
||||||
|
def delete_vorgabe_comment(request, comment_id):
|
||||||
|
"""Delete a comment (only own comments or staff can delete)"""
|
||||||
|
comment = get_object_or_404(VorgabeComment, id=comment_id)
|
||||||
|
|
||||||
|
# Check if user can delete this comment
|
||||||
|
if comment.user != request.user and not request.user.is_staff:
|
||||||
|
response = JsonResponse({'error': 'Keine Berechtigung zum Löschen dieses Kommentars'}, status=403)
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
|
||||||
|
try:
|
||||||
|
comment.delete()
|
||||||
|
response = JsonResponse({'success': True})
|
||||||
|
response['Content-Security-Policy'] = "default-src 'self'"
|
||||||
|
response['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
response = JsonResponse({'error': 'Serverfehler'}, status=500)
|
||||||
|
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
|
- name: data
|
||||||
mountPath: /data
|
mountPath: /data
|
||||||
containers:
|
containers:
|
||||||
- name: web
|
- name: web
|
||||||
image: docker.io/adebaumann/vui:0.917
|
image: docker.io/adebaumann/vui:0.918
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
@@ -51,18 +51,22 @@
|
|||||||
<span class="hidden-xs" style="margin-left: 0;">{{ user.first_name }} {{ user.last_name }}</span>
|
<span class="hidden-xs" style="margin-left: 0;">{{ user.first_name }} {{ user.last_name }}</span>
|
||||||
<span class="caret" style="margin-left: 8px;"></span>
|
<span class="caret" style="margin-left: 8px;"></span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
||||||
<li><a href="{% url 'password_change' %}">Passwort ändern</a></li>
|
<li><a href="{% url 'user_comments' %}">Meine Kommentare</a></li>
|
||||||
<li class="divider"></li>
|
{% if user.is_staff %}
|
||||||
<li>
|
<li><a href="{% url 'all_comments' %}">Alle Kommentare</a></li>
|
||||||
<form method="post" action="{% url 'logout' %}" style="display: inline;">
|
{% endif %}
|
||||||
{% csrf_token %}
|
<li><a href="{% url 'password_change' %}">Passwort ändern</a></li>
|
||||||
<button type="submit" style="background: none; border: none; color: inherit; padding: 3px 20px; width: 100%; text-align: left; cursor: pointer;">
|
<li class="divider"></li>
|
||||||
Abmelden
|
<li>
|
||||||
</button>
|
<form method="post" action="{% url 'logout' %}" style="display: inline;">
|
||||||
</form>
|
{% csrf_token %}
|
||||||
</li>
|
<button type="submit" style="background: none; border: none; color: inherit; padding: 3px 20px; width: 100%; text-align: left; cursor: pointer;">
|
||||||
</ul>
|
Abmelden
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -102,7 +106,7 @@
|
|||||||
<li><a href="/dokumente">Standards</a></li>
|
<li><a href="/dokumente">Standards</a></li>
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<li><a href="/dokumente/unvollstaendig/">Unvollständig</a></li>
|
<li><a href="/dokumente/unvollstaendig/">Unvollständig</a></li>
|
||||||
<li><a href="/autorenumgebung/">Autorenumgebung</a></li>
|
<li><a href="/autorenumgebung/">Autor</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li><a href="/referenzen">Referenzen</a></li>
|
<li><a href="/referenzen">Referenzen</a></li>
|
||||||
<li><a href="/stichworte">Stichworte</a></li>
|
<li><a href="/stichworte">Stichworte</a></li>
|
||||||
@@ -133,7 +137,7 @@
|
|||||||
<a href="/dokumente/unvollstaendig/">Unvollständig</a>
|
<a href="/dokumente/unvollstaendig/">Unvollständig</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="dropdown {% if 'autorenumgebung' in request.path %}current{% endif %}">
|
<li class="dropdown {% if 'autorenumgebung' in request.path %}current{% endif %}">
|
||||||
<a href="/autorenumgebung/">Autorenumgebung</a>
|
<a href="/autorenumgebung/">Autor</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="dropdown {% if 'referenzen' in request.path %}current{% endif %}">
|
<li class="dropdown {% if 'referenzen' in request.path %}current{% endif %}">
|
||||||
@@ -215,8 +219,8 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6 text-right">
|
<div class="col-sm-6 text-right">
|
||||||
<p class="text-muted">Version {{ version|default:"0.958" }}</p>
|
<p class="text-muted">Version {{ version|default:"0.968" }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.2.5 on 2025-11-27 22:02
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('referenzen', '0002_alter_referenz_table_alter_referenzerklaerung_table'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='referenzerklaerung',
|
||||||
|
options={'verbose_name': 'Erklärung', 'verbose_name_plural': 'Erklärungen'},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -5,7 +5,7 @@ certifi==2025.8.3
|
|||||||
charset-normalizer==3.4.3
|
charset-normalizer==3.4.3
|
||||||
curtsies==0.4.3
|
curtsies==0.4.3
|
||||||
cwcwidth==0.1.10
|
cwcwidth==0.1.10
|
||||||
Django==5.2.5
|
Django==5.2.8
|
||||||
django-admin-sortable2==2.2.8
|
django-admin-sortable2==2.2.8
|
||||||
django-js-asset==3.1.2
|
django-js-asset==3.1.2
|
||||||
django-mptt==0.17.0
|
django-mptt==0.17.0
|
||||||
@@ -33,3 +33,4 @@ sqlparse==0.5.3
|
|||||||
urllib3==2.5.0
|
urllib3==2.5.0
|
||||||
wcwidth==0.2.13
|
wcwidth==0.2.13
|
||||||
bleach==6.1.0
|
bleach==6.1.0
|
||||||
|
coverage==7.6.1
|
||||||
|
|||||||
@@ -12,3 +12,92 @@
|
|||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Comment System Styles */
|
||||||
|
.comment-btn {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-btn .comment-count {
|
||||||
|
position: absolute;
|
||||||
|
top: -8px;
|
||||||
|
right: -8px;
|
||||||
|
background-color: #dc3545;
|
||||||
|
color: white;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
font-size: 11px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-item {
|
||||||
|
max-width: 100%;
|
||||||
|
word-wrap: break-word;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-item .text-muted {
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#commentModal .modal-body {
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#commentsContainer {
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-comment-btn {
|
||||||
|
opacity: 0.7;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-comment-btn:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-comment-btn {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 1;
|
||||||
|
color: #721c24;
|
||||||
|
border: 1px solid #f5c6cb;
|
||||||
|
border-radius: 4px;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-comment-btn:hover {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: #f8d7da;
|
||||||
|
border-color: #f5c6cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Icon styling for emoji replacements */
|
||||||
|
.emoji-icon {
|
||||||
|
font-size: 1.1em;
|
||||||
|
margin-right: 0.3em;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive adjustments */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.comment-item .d-flex {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-comment-btn {
|
||||||
|
margin-left: 0 !important;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.2.5 on 2025-11-27 22:02
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('stichworte', '0002_stichworterklaerung_order'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='stichworterklaerung',
|
||||||
|
options={'verbose_name': 'Erklärung', 'verbose_name_plural': 'Erklärungen'},
|
||||||
|
),
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user