From cc4792b7b4a4e8335898d6b16784424ab95b4c71 Mon Sep 17 00:00:00 2001 From: MoritzWeber Date: Tue, 1 Oct 2024 16:38:06 +0200 Subject: [PATCH] refactor: Apply some SonarCloud recommendations --- backend/Dockerfile | 14 +++++++------- backend/capellacollab/sessions/routes.py | 5 +---- backend/tests/sessions/test_session_environment.py | 5 ----- frontend/src/app/events/service/events.service.ts | 2 +- images/session-preparation/Dockerfile | 6 +++++- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index e91276228..c6c4760e7 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -13,14 +13,14 @@ RUN apt-get update && \ apt-get upgrade --yes && \ apt-get install --yes \ ca-certificates \ - unzip \ - libpq-dev \ curl \ + git-lfs \ + gnupg \ + libpq-dev \ python3 \ python3-pip \ python3-venv \ - gnupg \ - git-lfs \ + unzip \ && rm -rf /var/lib/apt/lists/* ARG KUBECTL_APT_REMOTE=https://pkgs.k8s.io/core:/stable:/v1.29/deb/ @@ -38,15 +38,15 @@ COPY .git_archival.txt /tmp/.git_archival.txt COPY startup.sh /opt/.startup.sh # Activate venv -RUN ln -s $(which python3.11) /usr/bin/python && \ - ln -sf $(which python3.11) /usr/bin/python3 && \ +RUN ln -s "$(which python3.11)" /usr/bin/python && \ + ln -sf "$(which python3.11)" /usr/bin/python3 && \ python -m venv /opt/.venv ENV _OLD_VIRTUAL_PATH="$PATH" ENV VIRTUAL_ENV=/opt/.venv ENV PATH="$VIRTUAL_ENV/bin:$PATH" WORKDIR /tmp/backend -RUN pip install . && chmod +x $VIRTUAL_ENV/lib/python3.11/site-packages/capellacollab/settings/modelsources/git/askpass.py +RUN pip install . && chmod +x "$VIRTUAL_ENV/lib/python3.11/site-packages/capellacollab/settings/modelsources/git/askpass.py" RUN mkdir -p /var/log/backend && \ chmod -R 777 /var/log/backend diff --git a/backend/capellacollab/sessions/routes.py b/backend/capellacollab/sessions/routes.py index 8188bc047..385a4bab3 100644 --- a/backend/capellacollab/sessions/routes.py +++ b/backend/capellacollab/sessions/routes.py @@ -468,10 +468,7 @@ def get_sessions_for_user( ), db: orm.Session = fastapi.Depends(database.get_db), ): - if ( - user != current_user - and not current_user.role != users_models.Role.ADMIN - ): + if user != current_user and current_user.role != users_models.Role.ADMIN: raise exceptions.SessionForbiddenError() return user.sessions + list( diff --git a/backend/tests/sessions/test_session_environment.py b/backend/tests/sessions/test_session_environment.py index 3009f2ad1..7a530a57a 100644 --- a/backend/tests/sessions/test_session_environment.py +++ b/backend/tests/sessions/test_session_environment.py @@ -17,11 +17,6 @@ from capellacollab.users import models as users_models -@pytest.fixture(name="mock_session_methods") -def fixture_mock_session_methods(): - pass - - class MockOperator: environment = {} diff --git a/frontend/src/app/events/service/events.service.ts b/frontend/src/app/events/service/events.service.ts index d9d984bfc..d239baea6 100644 --- a/frontend/src/app/events/service/events.service.ts +++ b/frontend/src/app/events/service/events.service.ts @@ -36,7 +36,7 @@ export class EventsService { case 'projectName': return data.project ? data.project.name : ''; case 'reason': - return data.reason || ''; + return data.reason ?? ''; default: return ''; } diff --git a/images/session-preparation/Dockerfile b/images/session-preparation/Dockerfile index a3abaace6..ceddb807e 100644 --- a/images/session-preparation/Dockerfile +++ b/images/session-preparation/Dockerfile @@ -7,7 +7,11 @@ FROM ${ALPINE_BASE_IMAGE} USER root COPY clone_repositories.py /opt/clone_repositories.py -RUN apk add --no-cache git git-lfs python3 py3-pip +RUN apk add --no-cache \ + git \ + git-lfs \ + py3-pip \ + python3 COPY git_askpass.py /etc/git_askpass.py RUN chmod 555 /etc/git_askpass.py