Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 6700db8

Browse files
committed
Merge branch 'nora/expire-cookies' into staging
2 parents 2a62c8a + c2a3189 commit 6700db8

File tree

8 files changed

+60
-35
lines changed

8 files changed

+60
-35
lines changed

.coveragerc

Lines changed: 0 additions & 2 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ test_env.install_cli:
205205

206206
test_env.container_prepare:
207207
apt-get -y install git build-essential netcat-traditional
208-
git config --global --add safe.directory /app || true
208+
git config --global --add safe.directory /app/apps/codecov-api || true
209209

210210
test_env.container_check_db:
211211
while ! nc -vz postgres 5432; do sleep 1; echo "waiting for postgres"; done

codecov_auth/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import logging
23
from datetime import timedelta
34
from typing import Optional, Sequence
@@ -92,11 +93,13 @@ def impersonate_owner(self, request, queryset):
9293

9394
# this cookie is read by the `ImpersonationMiddleware` and
9495
# will reset `request.current_owner` to the impersonated owner
96+
max_age = datetime.timedelta(minutes=3)
9597
response.set_cookie(
9698
"staff_user",
9799
owner.ownerid,
98100
domain=settings.COOKIES_DOMAIN,
99101
samesite=settings.COOKIE_SAME_SITE,
102+
max_age=max_age,
100103
)
101104
History.log(
102105
Owner.objects.get(ownerid=owner.ownerid),

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- redis
99
- timescale
1010
volumes:
11-
- ./:/app
11+
- ./:/app/apps/codecov-api
1212
- ./docker/test.yml:/config/codecov.yml
1313
entrypoint:
1414
- ./dev.sh

docker/Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ARG BERGLAS_VERSION=2.0.6
66
FROM us-docker.pkg.dev/berglas/berglas/berglas:$BERGLAS_VERSION as berglas
77

88
FROM $REQUIREMENTS_IMAGE as app
9-
COPY . /app
10-
WORKDIR /app
9+
COPY . /app/apps/codecov-api
10+
WORKDIR /app/apps/codecov-api
1111
RUN pip install setuptools==71.1.0
1212
RUN python manage.py collectstatic --no-input
1313

@@ -25,27 +25,27 @@ RUN pip uninstall -y typing
2525
ENV DJANGO_SETTINGS_MODULE="codecov.settings_enterprise"
2626
# Remove the settings dev and enterprise files.
2727
# These should *never* make it to enterprise.
28-
RUN rm /app/codecov/settings_dev.py && \
29-
rm /app/codecov/settings_prod.py && \
30-
rm /app/codecov/settings_test.py && \
31-
rm /app/codecov/settings_staging.py && \
32-
rm /app/dev.sh && \
33-
rm /app/migrate.sh && \
34-
rm /app/prod.sh && \
35-
rm /app/staging.sh && \
36-
rm /app/production.yml && \
37-
rm /app/development.yml
28+
RUN rm /app/apps/codecov-api/codecov/settings_dev.py && \
29+
rm /app/apps/codecov-api/codecov/settings_prod.py && \
30+
rm /app/apps/codecov-api/codecov/settings_test.py && \
31+
rm /app/apps/codecov-api/codecov/settings_staging.py && \
32+
rm /app/apps/codecov-api/dev.sh && \
33+
rm /app/apps/codecov-api/migrate.sh && \
34+
rm /app/apps/codecov-api/prod.sh && \
35+
rm /app/apps/codecov-api/staging.sh && \
36+
rm /app/apps/codecov-api/production.yml && \
37+
rm /app/apps/codecov-api/development.yml
3838
# Remove unneeded folders
39-
RUN rm -rf /app/.github
40-
RUN rm -rf /app/.circleci
39+
RUN rm -rf /app/apps/codecov-api/.github
40+
RUN rm -rf /app/apps/codecov-api/.circleci
4141
# Create the codecov user to run the container as
4242
RUN addgroup --system application \
4343
&& adduser --system codecov --ingroup application --home /home/codecov
4444
RUN mkdir -p /config && chown codecov:application /config
4545
# copy the enterprise settings module.
46-
WORKDIR /app
46+
WORKDIR /app/apps/codecov-api
4747
RUN chmod +x enterprise.sh && \
48-
chown codecov:application /app
48+
chown codecov:application /app/apps/codecov-api
4949
ARG RELEASE_VERSION
5050
ENV RUN_ENV="ENTERPRISE"
5151
ENV RELEASE_VERSION=$RELEASE_VERSION

graphql_api/types/comparison/comparison.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ def resolve_has_different_number_of_head_and_base_reports(
252252
if "comparison" not in info.context:
253253
return False
254254
comparison: Comparison = info.context["comparison"]
255-
try:
256-
comparison.validate()
257-
except Exception:
258-
return False
259255
return comparison.has_different_number_of_head_and_base_sessions
260256

261257

services/comparison.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,41 @@ def head_report(self):
728728
pass
729729
return report
730730

731+
@cached_property
732+
def head_report_without_applied_diff(self):
733+
"""
734+
This is a variant to the head_report property without having an applied diff.
735+
This is created because applying the diff calls the provider, which adds a
736+
diff_totals key to the head_report object as well as adjusting the diff_total
737+
values in each session. This variant should only be used if you are not using
738+
any diff related data, as it saves an unnecessary request to the provider otherwise.
739+
"""
740+
try:
741+
report = report_service.build_report_from_commit(self.head_commit)
742+
except minio.error.S3Error as e:
743+
if e.code == "NoSuchKey":
744+
raise MissingComparisonReport("Missing head report")
745+
else:
746+
raise e
747+
748+
return report
749+
731750
@cached_property
732751
def has_different_number_of_head_and_base_sessions(self):
733-
log.info("has_different_number_of_head_and_base_sessions - Start")
734-
head_sessions = self.head_report.sessions
735-
base_sessions = self.base_report.sessions
736-
log.info(
737-
f"has_different_number_of_head_and_base_sessions - Retrieved sessions - head {len(head_sessions)} / base {len(base_sessions)}"
738-
)
752+
"""
753+
This method checks if the head and the base have different number of sessions.
754+
It makes use of the head_report_without_applied_diff property instead of the
755+
head_report one as it doesn't need diff related data for this computation (see
756+
the description of that property above for more context).
757+
This method should be replaced with a direct call to the report_uploads table instead,
758+
but leaving the implementation the same for now for consistency.
759+
"""
760+
try:
761+
head_sessions = self.head_report_without_applied_diff.sessions
762+
base_sessions = self.base_report.sessions
763+
except Exception:
764+
return False
765+
739766
# We're treating this case as false since considering CFF's complicates the logic
740767
if self._has_cff_sessions(head_sessions) or self._has_cff_sessions(
741768
base_sessions
@@ -746,12 +773,9 @@ def has_different_number_of_head_and_base_sessions(self):
746773
# I feel this method should belong to the API Report class, but we're thinking of getting rid of that class soon
747774
# In truth, this should be in the shared.Report class
748775
def _has_cff_sessions(self, sessions) -> bool:
749-
log.info(f"_has_cff_sessions - sessions count {len(sessions)}")
750776
for session in sessions.values():
751777
if session.session_type.value == "carriedforward":
752-
log.info("_has_cff_sessions - Found carriedforward")
753778
return True
754-
log.info("_has_cff_sessions - No carriedforward")
755779
return False
756780

757781
@property

services/tests/test_comparison.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,17 @@ def test_head_and_base_reports_have_cff_sessions(
925925
fc = self.comparison.has_different_number_of_head_and_base_sessions
926926
assert fc == False
927927

928+
@patch(
929+
"services.comparison.Comparison.head_report_without_applied_diff",
930+
new_callable=PropertyMock,
931+
)
928932
def test_head_and_base_reports_have_different_number_of_reports(
929-
self, base_report_mock, head_report_mock, _
933+
self, head_report_no_diff_mock, base_report_mock, head_report_mock, _
930934
):
931935
# Only relevant files keys to the session object
932936
head_report_sessions = {"0": {"st": "uploaded"}, "1": {"st": "uploaded"}}
933937
head_report = SerializableReport(sessions=head_report_sessions)
934-
head_report_mock.return_value = head_report
938+
head_report_no_diff_mock.return_value = head_report
935939
base_report_sessions = {"0": {"st": "uploaded"}}
936940
base_report = SerializableReport(sessions=base_report_sessions)
937941
base_report_mock.return_value = base_report

0 commit comments

Comments
 (0)