Skip to content

Commit 7c49d57

Browse files
author
kobo-bot[bot]
committed
Merge branch 'release/2.025.43'
2 parents 6bfb76e + 235a699 commit 7c49d57

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

kpi/deployment_backends/openrosa_backend.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from kobo.apps.subsequences.utils import stream_with_extras
5454
from kobo.apps.trackers.models import NLPUsageCounter
5555
from kpi.constants import (
56+
PERM_ADD_SUBMISSIONS,
5657
PERM_CHANGE_SUBMISSIONS,
5758
PERM_DELETE_SUBMISSIONS,
5859
PERM_PARTIAL_SUBMISSIONS,
@@ -77,7 +78,7 @@
7778
from kpi.utils.files import ExtendedContentFile
7879
from kpi.utils.log import logging
7980
from kpi.utils.mongo_helper import MongoHelper
80-
from kpi.utils.object_permission import get_database_user
81+
from kpi.utils.object_permission import get_anonymous_user, get_database_user
8182
from kpi.utils.xml import fromstring_preserve_root_xmlns, xml_tostring
8283
from ..exceptions import AttachmentUidMismatchException, BadFormatException
8384
from .base_backend import BaseDeploymentBackend
@@ -134,8 +135,16 @@ def connect(self, active=False):
134135
self._xform = publish_xls_form(xlsx_file, self.asset.owner)
135136
self._xform.downloadable = active
136137
self._xform.kpi_asset_uid = self.asset.uid
138+
self._xform.require_auth = not self.asset.has_perm(
139+
get_anonymous_user(), PERM_ADD_SUBMISSIONS
140+
)
137141
self._xform.save(
138-
update_fields=['downloadable', 'kpi_asset_uid', 'date_modified']
142+
update_fields=[
143+
'downloadable',
144+
'kpi_asset_uid',
145+
'date_modified',
146+
'require_auth',
147+
]
139148
)
140149

141150
self.store_data(

kpi/tests/test_assets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from kpi.constants import (
2828
ASSET_TYPE_COLLECTION,
2929
ASSET_TYPE_SURVEY,
30+
PERM_ADD_SUBMISSIONS,
3031
PERM_CHANGE_ASSET,
3132
PERM_MANAGE_ASSET,
3233
PERM_VIEW_ASSET,
@@ -790,8 +791,13 @@ def test_anonymous_as_baseline_for_authenticated(self):
790791
self.asset.assign_perm(AnonymousUser(), PERM_VIEW_ASSET)
791792
# Check that both anonymous and `anotheruser` can view
792793
for user_obj in AnonymousUser(), self.anotheruser:
793-
self.assertTrue(user_obj.has_perm(
794-
PERM_VIEW_ASSET, self.asset))
794+
self.assertTrue(user_obj.has_perm(PERM_VIEW_ASSET, self.asset))
795+
796+
def test_first_deployment_allows_anonymous_access(self):
797+
asset = Asset.objects.create(asset_type=ASSET_TYPE_SURVEY, owner=self.user)
798+
asset.assign_perm(AnonymousUser(), PERM_ADD_SUBMISSIONS)
799+
asset.deploy(backend='mock', active=True)
800+
assert asset.deployment.xform.require_auth is False
795801

796802

797803
class TestAssetNameSettingHandling(AssetsTestCase):

0 commit comments

Comments
 (0)