Example #1
0
def get_dashboard_template_context(domain, couch_user):
    context = {}
    context['location_hierarchy'] = location_hierarchy_config(domain)
    context['user_location_id'] = couch_user.get_location_id(domain)
    context['all_user_location_id'] = list(
        couch_user.get_sql_locations(domain).location_ids())
    try:
        context['user_location_type'] = couch_user.get_sql_location(
            domain).location_type_name
    except AttributeError:
        context['user_location_type'] = ''
    context['state_level_access'] = 'state' in set([
        loc.location_type.code for loc in couch_user.get_sql_locations(domain)
    ])
    context['have_access_to_features'] = icds_pre_release_features(couch_user)
    context['show_mobile_apk'] = ICDS_DASHBOARD_SHOW_MOBILE_APK.enabled(
        couch_user.username, namespace=NAMESPACE_USER)
    context['have_access_to_all_locations'] = couch_user.has_permission(
        domain, 'access_all_locations')

    if context['have_access_to_all_locations']:
        context['user_location_id'] = None

    if couch_user.is_web_user():
        context['is_web_user'] = True

    context['nav_metadata'] = _get_nav_metadatada()
    return context
Example #2
0
 def filter_context(self):
     api_root = self.api_root
     user = self.request.couch_user
     loc_id = self.request.GET.get('location_id')
     if not loc_id:
         domain_membership = user.get_domain_membership(self.domain)
         if domain_membership:
             loc_id = domain_membership.location_id
     return {
         'api_root':
         api_root,
         'control_name':
         self.label,  # todo: cleanup, don't follow this structure
         'control_slug':
         self.slug,  # todo: cleanup, don't follow this structure
         'auto_drill':
         self.auto_drill,
         'loc_id':
         loc_id,
         'locations':
         self.load_locations_json(loc_id),
         'make_optional':
         self.make_optional,
         'hierarchy':
         self.location_hierarchy_config,
         'path':
         self.request.path,
         'have_access_to_icds_dashboard_features':
         icds_pre_release_features(user)
     }
Example #3
0
def prepare_issnip_monthly_register_reports(domain, awcs, pdf_format, month,
                                            year, couch_user):
    selected_date = date(year, month, 1)
    report_context = {
        'reports': [],
        'user_have_access_to_features': icds_pre_release_features(couch_user),
    }

    pdf_files = []

    report_data = ISSNIPMonthlyReport(
        config={
            'awc_id': awcs,
            'month': selected_date,
            'domain': domain
        },
        icds_feature_flag=icds_pre_release_features(couch_user)).to_pdf_format

    if pdf_format == 'one':
        report_context['reports'] = report_data
        cache_key = create_pdf_file(report_context)
    else:
        for data in report_data:
            report_context['reports'] = [data]
            pdf_hash = create_pdf_file(report_context)
            pdf_files.append({
                'uuid': pdf_hash,
                'location_name': data['awc_name']
            })
        cache_key = zip_folder(pdf_files)

    params = {'domain': domain, 'uuid': cache_key, 'format': pdf_format}

    return {
        'domain':
        domain,
        'uuid':
        cache_key,
        'format':
        pdf_format,
        'link':
        reverse('icds_download_pdf',
                params=params,
                absolute=True,
                kwargs={'domain': domain})
    }
Example #4
0
def get_dashboard_template_context(domain, couch_user):
    context = {}
    context['location_hierarchy'] = location_hierarchy_config(domain)
    context['user_location_id'] = couch_user.get_location_id(domain)
    context['all_user_location_id'] = list(
        couch_user.get_sql_locations(domain).location_ids())
    try:
        context['user_location_type'] = couch_user.get_sql_location(
            domain).location_type_name
    except AttributeError:
        context['user_location_type'] = ''
    context['state_level_access'] = 'state' in set([
        loc.location_type.code for loc in couch_user.get_sql_locations(domain)
    ])
    context['have_access_to_features'] = icds_pre_release_features(couch_user)
    context['show_mobile_apk'] = ICDS_DASHBOARD_SHOW_MOBILE_APK.enabled(
        couch_user.username, namespace=NAMESPACE_USER)
    context['have_access_to_all_locations'] = couch_user.has_permission(
        domain, 'access_all_locations')

    if context['have_access_to_all_locations']:
        context['user_location_id'] = None

    if couch_user.is_web_user():
        context['is_web_user'] = True

    beta = icds_pre_release_features(couch_user)

    context['nav_metadata'] = _get_nav_metadatada()
    context['sdd_metadata'] = _get_sdd_metadata()
    context['nav_menu_items'] = _get_nav_menu_items(beta)
    context['fact_sheet_sections'] = _get_factsheet_sections()
    context['MAPBOX_ACCESS_TOKEN'] = settings.MAPBOX_ACCESS_TOKEN
    context['support_email'] = settings.SUPPORT_EMAIL

    if couch_user.is_commcare_user() and _has_helpdesk_role(
            domain, couch_user):
        build_id = get_latest_issue_tracker_build_id()
        context['report_an_issue_url'] = webapps_module(
            domain=domain,
            app_id=build_id,
            module_id=0,
        )

    return context
Example #5
0
def prepare_issnip_monthly_register_reports(domain, awcs, pdf_format, month, year, couch_user):
    selected_date = date(year, month, 1)
    report_context = {
        'reports': [],
        'user_have_access_to_features': icds_pre_release_features(couch_user),
    }

    pdf_files = {}

    report_data = ISSNIPMonthlyReport(config={
        'awc_id': awcs,
        'month': selected_date,
        'domain': domain
    }, icds_feature_flag=icds_pre_release_features(couch_user)).to_pdf_format

    if pdf_format == 'one':
        report_context['reports'] = report_data
        cache_key = create_pdf_file(report_context)
    else:
        for data in report_data:
            report_context['reports'] = [data]
            pdf_hash = create_pdf_file(report_context)
            pdf_files.update({
                pdf_hash: data['awc_name']
            })
        cache_key = zip_folder(pdf_files)

    params = {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format
    }

    return {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format,
        'link': reverse('icds_download_pdf', params=params, absolute=True, kwargs={'domain': domain})
    }
Example #6
0
    def _inner(request, domain, *args, **kwargs):
        def call_view():
            return view_fn(request, domain, *args, **kwargs)

        if icds_pre_release_features(request.couch_user):
            loc_id = request.GET.get('location_id')

            def return_no_location_access_response():
                return HttpResponse(
                    'No access to the location {} for the logged in user'.
                    format(loc_id),
                    status=403)

            if not loc_id and not request.couch_user.has_permission(
                    domain, 'access_all_locations'):
                return return_no_location_access_response()
            if loc_id and not user_can_access_location_id(
                    domain, request.couch_user, loc_id):
                return return_no_location_access_response()
        return call_view()
Example #7
0
def get_dashboard_template_context(domain, couch_user):
    context = {}
    context['location_hierarchy'] = location_hierarchy_config(domain)
    context['user_location_id'] = couch_user.get_location_id(domain)
    context['all_user_location_id'] = list(
        couch_user.get_sql_locations(domain).location_ids())
    context['state_level_access'] = 'state' in set([
        loc.location_type.code for loc in couch_user.get_sql_locations(domain)
    ])
    context['have_access_to_features'] = icds_pre_release_features(couch_user)
    context['have_access_to_all_locations'] = couch_user.has_permission(
        domain, 'access_all_locations')

    if context['have_access_to_all_locations']:
        context['user_location_id'] = None

    if couch_user.is_web_user():
        context['is_web_user'] = True

    return context