66a749fceba17121e39931aa36334c9c2cb97033
FAQ/Questions/Applying-Security-to-Scheduled-Reports.md
| ... | ... | @@ -11,12 +11,13 @@ This code sample shows how to apply security for the owner of the report when it |
| 11 | 11 | ```csharp |
| 12 | 12 | public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet) |
| 13 | 13 | { |
| 14 | - bool scheduler = AdHocSettings.CurrentUserName.Equals("DefaultAdministrator"); |
|
| 15 | - if (scheduler) |
|
| 14 | + bool scheduler = AdHocSettings.CurrentUserName.Equals(AdHocSettings.DefaultUserName); //For the scheduler, the CurrentUserName will be the DefaultUserName as no user has logged in using the normal process. |
|
| 15 | + if (scheduler && reportSet.SendEmailAs != SchedulerOutput.SchedulerOutputType.Link.ToString()) //Do not need to perform this step if the report is sent as a link |
|
| 16 | 16 | { |
| 17 | - Filter f = new Filter("TenantID"); |
|
| 18 | - f.Value = LookupTenantIDFromUser(reportSet.UserName); //Write your own implementation of this method |
|
| 19 | - reportSet.Filters.AddHidden(f); |
|
| 17 | + AdHocSettings.TenantField = "TenantID"; //CurrentUserTenantId is already set from running run_scheduled_reports with tenants=tenant1,tenant2,etc... and TenantField uses CurrentUserTenantId as its value. |
|
| 18 | + Filter f = new Filter("Field_Derived_From_User"); |
|
| 19 | + f.Value = LookupDerivedTenantValue(reportSet.UserName); //Write your own implementation of this method. This will get the value for the field that should be derived from your user (the report owner) inside the tenant being run. |
|
| 20 | + reportSet.Filters.AddHidden(f); //add the temporary hidden filter. Normally this would be done during initialization. But since we didn't know the user's login information at initialization then we have to improvise. |
|
| 20 | 21 | } |
| 21 | 22 | } //end method |
| 22 | 23 | ``` |
| ... | ... | @@ -25,11 +26,12 @@ public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet) |
| 25 | 26 | |
| 26 | 27 | ```visualbasic |
| 27 | 28 | Public Overrides Sub PreExecuteReportSet(ByVal reportSet As Izenda.AdHoc.ReportSet) |
| 28 | - Dim scheduler As Boolean = AdHocSettings.CurrentUserName.Equals("DefaultAdministrator") |
|
| 29 | - If scheduler Then |
|
| 30 | - Dim f As Filter = New Filter("TenantID") |
|
| 31 | - f.Value = LookupTenantIDFromUser(reportSet.UserName) 'Write your own implementation of this method |
|
| 32 | - reportSet.Filters.AddHidden(f) |
|
| 29 | + Dim scheduler As Boolean <> AdHocSettings.CurrentUserName.Equals(AdHocSettings.DefaultUserName) 'For the scheduler, the CurrentUserName will be the DefaultUserName as no user has logged in using the normal process. |
|
| 30 | + If scheduler AndAlso reportSet.SendEmailAs = SchedulerOutput.SchedulerOutputType.Link.ToString() Then 'Do not need to perform this step if the report is sent as a link |
|
| 31 | + AdHocSettings.TenantField = "TenantID" 'CurrentUserTenantId is already set from running run_scheduled_reports with tenants=tenant1,tenant2,etc... and TenantField uses CurrentUserTenantId as its value. |
|
| 32 | + Dim f As Filter = New Filter("Field_Derived_From_User") |
|
| 33 | + f.Value = LookupDerivedTenantValue(reportSet.UserName) 'Write your own implementation of this method. This will get the value for the field that should be derived from your user (the report owner) inside the tenant being run. |
|
| 34 | + reportSet.Filters.AddHidden(f) 'add the temporary hidden filter. Normally this would be done during initialization. But since we didn't know the user's login information at initialization then we have to improvise. |
|
| 33 | 35 | End If |
| 34 | 36 | End Sub 'end method |
| 35 | 37 | ``` |
| ... | ... | @@ -42,4 +44,4 @@ The Email Scheduler in the reporting system does not have a way to provide authe |
| 42 | 44 | |
| 43 | 45 | ##Per-user Security On Scheduled Reports |
| 44 | 46 | |
| 45 | -Scheduled reports only supports per-user security using the Link format. Scheduled attachments will not apply hidden filters normally, but you can apply security through [[PreExecuteReportSet()|/FAQ/PreExecuteReportSet]] based on the security of the report owner. If per-user security is required, the Link format will require the user to login before seeing the report. |
|
| ... | ... | \ No newline at end of file |
| 0 | +Scheduled reports only natively supports per-user security using the Link format. Reports scheduled as attachments will not apply hidden filters normally unless using custom code as above based on the security of the report owner. If per-user security is required and writing custom code to handle attached reports is too messy, the Link format will require the user to login before seeing the report, thus applying security as normal. |
|
| ... | ... | \ No newline at end of file |