def raise_odata_permissions_issues(user, domain, config): if config.is_deidentified: return not (user_can_view_deid_exports(domain, user) and user_can_view_odata_feed(domain, user)) return not (has_permission_to_view_report( user, domain, FORM_EXPORT_PERMISSION if config.type == FORM_EXPORT else CASE_EXPORT_PERMISSION) and user_can_view_odata_feed(domain, user))
def page_context(self): tile_contexts = [] for tile in _get_default_tiles(self.request): if tile.is_visible: tile_context = { 'title': tile.title, 'slug': tile.slug, 'icon': tile.icon, 'url': tile.get_url(self.request), 'help_text': tile.help_text, } if tile.paginator_class: tile_context.update({ 'has_item_list': True, }) tile_contexts.append(tile_context) from corehq.apps.export.views.utils import user_can_view_odata_feed context = { 'dashboard_tiles': tile_contexts, 'user_can_view_odata_feed': user_can_view_odata_feed(self.domain, self.request.couch_user), } context.update(get_paused_plan_context(self.request, self.domain)) return context
def dispatch(self, request_type, request, **kwargs): if not domain_has_privilege(request.domain, privileges.ODATA_FEED): raise ImmediateHttpResponse( response=HttpResponseNotFound('Feature flag not enabled.')) self.config_id = kwargs['config_id'] self.table_id = int(kwargs.get('table_id', 0)) with TimingContext() as timer: response = super(BaseODataResource, self).dispatch(request_type, request, **kwargs) # order REALLY matters for the following code. It should be called # AFTER the super's dispatch or request.couch_user will not be present if not user_can_view_odata_feed(request.domain, request.couch_user): raise ImmediateHttpResponse(response=HttpResponseNotFound( 'No permission to view feed.')) record_feed_access_in_datadog(request, self.config_id, timer.duration, response) return response
def dispatch(self, request, *args, **kwargs): if not user_can_view_odata_feed(request.domain, request.couch_user): raise Http404() return super(BaseODataView, self).dispatch(request, *args, **kwargs)
def odata_permissions_check(user, domain): return user_can_view_odata_feed(domain, user)