File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 5353from kobo .apps .subsequences .utils import stream_with_extras
5454from kobo .apps .trackers .models import NLPUsageCounter
5555from kpi .constants import (
56+ PERM_ADD_SUBMISSIONS ,
5657 PERM_CHANGE_SUBMISSIONS ,
5758 PERM_DELETE_SUBMISSIONS ,
5859 PERM_PARTIAL_SUBMISSIONS ,
7778from kpi .utils .files import ExtendedContentFile
7879from kpi .utils .log import logging
7980from 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
8182from kpi .utils .xml import fromstring_preserve_root_xmlns , xml_tostring
8283from ..exceptions import AttachmentUidMismatchException , BadFormatException
8384from .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 (
Original file line number Diff line number Diff line change 2727from 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
797803class TestAssetNameSettingHandling (AssetsTestCase ):
You can’t perform that action at this time.
0 commit comments