1 (edited by namwebs 18-11-2022 11:29:50)

Topic: How to allow filtering for both logged-in and anonymous users

Hi,

I'm trying to get something right in an Indicia report (page category=reporting; page type=reporting page (customisable)).

A logged-in user sees the Filter Bar but an anonymous user doesn't. Based on a previous question this seems to be expected behaviour: https://forums.nbn.org.uk/viewtopic.php?id=7024 where Jim said

I can see this is the intended behaviour from client_helpers/prebuilt_forms/dynamic_report_explorer.php get_control_standardparams().

I want to restrict the report's map and grid to records that have not been rejected or are dubious.

If I specify a parameter such as @quality=!D in the Form Structure of the User Interface under [standard_params], it correctly filters out dubious and rejected records for logged in users. For the logged-in user the filter states 'Quality. Exclude not accepted records' and changing this to e.g. 'All records' makes rejected records appear as I would expect. Great. However for the anonymous user the report loads with all records visible, even rejected/dubious ones, and there is no filter bar so they cannot interogate the records based on status.

I tried another approach (from https://indicia-docs.readthedocs.io/en/ … ing.html). Instead of specifying a parameter in the form structure I added it in the report's xml files by adding a condition to the query like this:

and quality_check('#quality#', o.record_status, o.certainty)=true

and a parameter like this:

<param name="quality" display="Data quality" datatype="lookup" default='!D'
         description="Quality level required of data to be included in the map."
         lookup_values="V:Data must be verified,C:Data must be verified or certain,
        L:Data must be at least likely,!D:Include anything not dubious or rejected,
        !R:Include anything not rejected" />

Running that report as a logged-in user restricts records as it should but changing the Quality option in the filter bar e.g. to 'All records' does not make rejected records appear. Running it as an anonymous user shows the records filtered correctly.

So - how can I get this to work for both logged-in and anonymous users correctly so that records are always initially restricted but can be queried using the filter bar. (Or - is there a way to make the filter bar available to anonymous users?)

Thanks for any advice.

2

Re: How to allow filtering for both logged-in and anonymous users

The filter bar does disable itself if you are not logged in, as it contains code that needs a login, such as saving filters. So, unless we hack your code, maybe the standard filter bar is not the way to go.

Does your report have the standard_params attribute on the query element in the XML file? It might be that this is turning on the default standard parameters behaviour to only show non-rejected records which is then clashing with your quality parameter. So maybe you need to remove this attribute from the report to disable the standard parameters and just use the manually added parameters like the quality one you added?

John

John van Breda
Biodiverse IT

3

Re: How to allow filtering for both logged-in and anonymous users

Hi John,

Thanks for your reply.

If I take out the standard_params attribute on the query element in the XML file the report ignores URL parameters (e.g. filter-taxon_meaning_list=1370&dynamic-taxon_meaning_list=1370) and shows shows records for all species.

I'm wondering if an option would be to have different reports for logged in and anonymous users. Reports for logged in users could show records of all quality categories which they can filter with the filter bar; those for anonymous users would just exclude dubious/rejected records in the xml query. Seems a bit cumbersome though. Alternatively, is there a way to put a condition in the xml query to test if logged in or not? Or in the Form Structure of the User Interface?

thanks, Alice

4

Re: How to allow filtering for both logged-in and anonymous users

Hi Alice

A few options:

1. In the settings for a control on the form structure, you can set an option called @permission to the name of a permission, to turn it on and off depending on if you are logged in. Note that people with admin rights will see everything if you do this though.

2. You can set a parameter in the report preset parameters, @currentUser={profile_indicia_user_id} and check that in the report XML file's SQL query. I think you need to treat it as a string and test for '' to detect users that aren't logged in.

3. The filter for taxon_meaning_list is one of the standard parameters, which is why your report no longer filters if you remove the standard_params attribute. You could always add your own parameter to the XML file with the same name, if this is the only parameter you need to support.

Hope that helps
John

John van Breda
Biodiverse IT