Skip to content

Commit dc357e6

Browse files
committed
Merge branch 'master' into release
2 parents bbbf607 + f62683b commit dc357e6

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

docker-app/qfieldcloud/core/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,19 +2414,25 @@ def for_user_and_project(self, user: User, project: Project) -> SecretQueryset:
24142414
secrets_qs = self.filter(
24152415
Q(
24162416
# organization-assigned secrets
2417-
Q(organization=organization) & Q(assigned_to__isnull=True)
2417+
Q(organization=organization)
2418+
& Q(project__isnull=True)
2419+
& Q(assigned_to__isnull=True)
24182420
)
24192421
| Q(
24202422
# user-assigned organization secrets
2421-
Q(organization=organization) & Q(assigned_to=user)
2423+
Q(organization=organization)
2424+
& Q(project__isnull=True)
2425+
& Q(assigned_to=user)
24222426
)
24232427
| Q(
24242428
# project-assigned secrets
2425-
Q(project=project) & Q(assigned_to__isnull=True)
2429+
Q(organization__isnull=True)
2430+
& Q(project=project)
2431+
& Q(assigned_to__isnull=True)
24262432
)
24272433
| Q(
24282434
# user assigned project secrets
2429-
Q(project=project) & Q(assigned_to=user)
2435+
Q(organization__isnull=True) & Q(project=project) & Q(assigned_to=user)
24302436
)
24312437
)
24322438

docker-app/qfieldcloud/core/tests/test_secret.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,29 @@ def test_check_secrets_type_priority(self):
198198

199199
self.assertEqual(secrets.count(), 1)
200200
self.assertEqual(secrets[0], s1_project_assigned)
201+
202+
def test_check_secrets_do_not_leak(self):
203+
p4 = Project.objects.create(name="p4", owner=self.u2)
204+
205+
p3_s1 = self._create_secret(name="p3_s1", project=self.p3)
206+
p4_s2 = self._create_secret(name="p4_s2", project=p4)
207+
208+
secrets = Secret.objects.for_user_and_project(self.u1, self.p3)
209+
210+
self.assertEqual(secrets.count(), 1)
211+
self.assertEqual(secrets[0], p3_s1)
212+
213+
with self.assertRaises(UserProjectRoleError):
214+
secrets = Secret.objects.for_user_and_project(self.u1, p4)
215+
216+
self.assertEqual(secrets.count(), 0)
217+
218+
with self.assertRaises(UserProjectRoleError):
219+
secrets = Secret.objects.for_user_and_project(self.u2, self.p3)
220+
221+
self.assertEqual(secrets.count(), 0)
222+
223+
secrets = Secret.objects.for_user_and_project(self.u2, p4)
224+
225+
self.assertEqual(secrets.count(), 1)
226+
self.assertEqual(secrets[0], p4_s2)

docker-app/worker_wrapper/wrapper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,14 @@ def _prepare_deltas(self, deltas: Iterable[Delta]) -> dict[str, Any]:
432432
local_to_remote_pk_deltas = Delta.objects.filter(
433433
client_id__in=delta_client_ids,
434434
last_modified_pk__isnull=False,
435-
).values("client_id", "content__localPk", "last_modified_pk")
435+
).values(
436+
"client_id", "content__localLayerId", "content__localPk", "last_modified_pk"
437+
)
436438

437439
client_pks_map = {}
438440

439441
for delta_with_modified_pk in local_to_remote_pk_deltas:
440-
key = f"{delta_with_modified_pk['client_id']}__{delta_with_modified_pk['content__localPk']}"
442+
key = f"{delta_with_modified_pk['client_id']}__{delta_with_modified_pk['content__localLayerId']}__{delta_with_modified_pk['content__localPk']}"
441443
client_pks_map[key] = delta_with_modified_pk["last_modified_pk"]
442444

443445
deltafile_contents = {

docker-qgis/qfc_worker/apply_deltas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ def get_feature(
816816
source_pk = delta["sourcePk"]
817817

818818
if client_pks:
819-
client_pk_key = f"{delta['clientId']}__{delta['localPk']}"
819+
client_pk_key = (
820+
f"{delta['clientId']}__{delta['localLayerId']}__{delta['localPk']}"
821+
)
820822
if client_pk_key in client_pks:
821823
source_pk = client_pks[client_pk_key]
822824

0 commit comments

Comments
 (0)