I've just started using Forena Reports and have so far managed to generate a report from querying an external database. I'd like the report to generate information specific only to the authenticated user. However, the Drupal user name does not match the user name in the external database. What does match is the email address. I can query the external database to produce the required information where mail=user@somewhere.com. Can I parameterize the Forena SQL query so that the currently authenticated user's email address, as stored in Drupal, is passed to the query?

Many thanks!

CommentFileSizeAuthor
#3 2620900-3-current-user-email.patch879 bytesmetzlerd
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ishore created an issue. See original summary.

metzlerd’s picture

Category: Support request » Feature request
Issue summary: View changes

The short answer is that forena cannot currently do this directly without some custom code. If you have a bit of time, it won't take me long to roll a patch that will accomplish this. For some reason I didn't think of this important use case. Forena has a pluggable system for current user name generation, but it's a bit tricky to configure.

In the meantime you could theoretically nest calls to your data block inside another data block. But that is something you'd want some experience in manually creating .frx files. Is that something you are comfortable with yet?

metzlerd’s picture

Well that patch was easier than I thought. it hasn't been tested, but if you'd be willing to test it, that would be most helpful.

ishore’s picture

Wow! Thanks very much. I'm still very new to Forena, and pretty new to Drupal, but I'll certainly give the patch a try and get back to you.

ishore’s picture

I have applied the patch. Apologies for the ignorance, but I can't find the answer in the documentation. How do I reference the authenticated user's email address within the SQL? I'm imagining something like:

SELECT id,title from monthly_stats WHERE mail = :current_user{mail}

metzlerd’s picture

No, there is an options in your data source configuration (where you specify database connection string, etc.) that determines what value the :current_user parameter gets for data blocks within that data source. You should be able to change it to use email there. You will still use the :current_user paraameter in your data blocks.

ishore’s picture

Works beautifully, thanks! I do have another problem in that the specified sort order is not obeyed, which may be related to ticket 2610950. I do have DataTables installed, although I haven't tried to use it yet. But it (DataTables) is producing an error message right now when I click on the Forena Data Block that I have created. I will try and fix that now. Thanks for the patch!

  • 395ab17 committed on 7.x-4.x
    Issue #2620900 - Adding email address as current user.
    
metzlerd’s picture

Status: Active » Fixed

Glad it worked. Committed.

  • 395ab17 committed on 7.x-5.x
    Issue #2620900 - Adding email address as current user.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.