50a2e81d669ad631fdcab08922de01d8794f89ef
Integration/User-Types.md
| ... | ... | @@ -0,0 +1,157 @@ |
| 1 | +#Section 4 - User Types |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Introduction |
|
| 6 | + |
|
| 7 | +The following example shows an example of security that combines report level and data level restrictions. |
|
| 8 | + |
|
| 9 | +##Code Sample |
|
| 10 | + |
|
| 11 | +```csharp |
|
| 12 | + [Serializable] |
|
| 13 | + public class CustomAdHocConfig : DatabaseAdHocConfig |
|
| 14 | + { |
|
| 15 | + public static void InitializeReporting() |
|
| 16 | + { |
|
| 17 | + |
|
| 18 | + if (AdHocContext.Initialized) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + //Your Licence Key |
|
| 23 | + AdHocSettings.LicenseKey = "Enter Key"; |
|
| 24 | + //Datasource of the DB where the Data sources are stored |
|
| 25 | + AdHocSettings.SqlServerConnectionString = @"DBconnectionString;"; |
|
| 26 | + |
|
| 27 | + AdHocSettings.AdHocConfig = new CustomAdHocConfig(); |
|
| 28 | + AdHocSettings.GenerateThumbnails = true; |
|
| 29 | + AdHocSettings.ShowSimpleModeViewer = true; |
|
| 30 | + AdHocSettings.IdentifiersRegex = "^.*[iI][Dd]$"; |
|
| 31 | + AdHocSettings.TabsCssUrl = "/Resources/css/tabs.css"; |
|
| 32 | + AdHocSettings.ReportCssUrl = "../Resources/css/Report.css"; |
|
| 33 | + AdHocSettings.ShowBetweenDateCalendar = true; |
|
| 34 | + AdHocSettings.ReportViewer = "ReportViewer"; |
|
| 35 | + AdHocSettings.InstantReport = "InstantReport"; |
|
| 36 | + AdHocSettings.ReportDesignerUrl = "ReportDesigner"; |
|
| 37 | + AdHocSettings.ReportList = "ReportList"; |
|
| 38 | + AdHocSettings.SettingsPageUrl = "Settings"; |
|
| 39 | + AdHocSettings.ParentSettingsUrl = "Settings"; |
|
| 40 | + AdHocSettings.ResponseServer = "rs.aspx"; |
|
| 41 | + AdHocSettings.ReportsPath = Path.Combine(HttpContext.Current.Server.MapPath("~/"), "Reports"); |
|
| 42 | + AdHocSettings.ChartingEngine = ChartingEngine.HtmlChart; |
|
| 43 | + AdHocSettings.ShowModifiedReportMessage = false; |
|
| 44 | + AdHocSettings.DashboardViewer = "Dash"; |
|
| 45 | + AdHocSettings.DashboardDesignerUrl = "Dash"; |
|
| 46 | + AdHocSettings.DashboardDateSliderMode = DashboardDateSliderMode.None; |
|
| 47 | + AdHocSettings.ShowJoinDropDown = true; |
|
| 48 | + AdHocSettings.InstantReport = "InstantReportNew"; |
|
| 49 | + //EOPDF uses a DLL that converts HTML |
|
| 50 | + //AdHocSettings.PdfPrintMode = PdfMode.EOPDF; |
|
| 51 | + //PhantomJS PDF uses an EXE on the web server that produces the export |
|
| 52 | + AdHocSettings.PdfPrintMode = PdfMode.PhantomJs; |
|
| 53 | + |
|
| 54 | + //Get cookie values from a cookie named Authentication |
|
| 55 | + //This assumes there are only 3 values separated by a | |
|
| 56 | + //Assuming the first value is username and second is tenant setting it below |
|
| 57 | + if(Request.Cookies["Authentication"] != null) |
|
| 58 | + { |
|
| 59 | + string authVals = Request.Cookies["Authentication"].Value; |
|
| 60 | + string[] cookieVals = authVals.Split(new char[] {'|'}); |
|
| 61 | + AdHocSettings.CurrentUserName = cookieVals[0]; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + //Pull new Datasource from DB based on user name |
|
| 65 | + //Remember to add <%@ Import Namespace="System.Data" %> to your imports |
|
| 66 | + DataSet dsDataSource = AdHocContext.Driver.GetDataSet(AdHocContext.Driver.CreateCommand(string.Format("SELECT agDSN,agSqlServer,XenID FROM Agencies WHERE agID = {0}", AdHocSettings.CurrentUserName))); |
|
| 67 | + |
|
| 68 | + string[] dbResults = new string[ds.Tables[0].Rows.Count]; |
|
| 69 | + |
|
| 70 | + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) |
|
| 71 | + results[i] = ds.Tables[0].Rows[i][0].ToString(); |
|
| 72 | + |
|
| 73 | + AdHocSettings.SqlServerConnectionString = "Put Together Connection String"; |
|
| 74 | + |
|
| 75 | + //Get and set role from cookie value |
|
| 76 | + //Assuming insight is the second value of the cookie |
|
| 77 | + AdHocSettings.CurrentUserRoles = new string[] { cookieVals[1] }; |
|
| 78 | + //Set the number of available drop downs for roles in the misc tab of the designer |
|
| 79 | + //+1 is for the default value of Everyone |
|
| 80 | + AdHocSettings.NumSharedDropdowns = AdHocSettings.CurrentUserRoles.Length + 1; |
|
| 81 | + //Set the value of the drop downs in the misc tab for roles |
|
| 82 | + AdHocSettings.SharedWithValues = AdHocSettings.CurrentUserRoles; |
|
| 83 | + |
|
| 84 | + //Please note that for new Izenda Reference Implementations |
|
| 85 | + //the default mode for AdHocSettings.CurrentUserIsAdmin is set to TRUE |
|
| 86 | + //You must set it to FALSE for share-with values to take effect |
|
| 87 | + |
|
| 88 | + //Determine user type permissions (in this I'm assuming it's inside of the roles we pulled earlier) |
|
| 89 | + if (AdHocSettings.CurrentUserRoles.Contains<string>("Admin")) |
|
| 90 | + { |
|
| 91 | + //The following settings allows the user to ignore share with values |
|
| 92 | + AdHocSettings.CurrentUserIsAdmin = true; |
|
| 93 | + //Determines if the settings page shortcut icon "wrench" should be shown |
|
| 94 | + AdHocSettings.ShowSettingsButton = true; |
|
| 95 | + //Determins if the new drop down, edit and save as functions are available |
|
| 96 | + AdHocSettings.ShowDesignLinks = true; |
|
| 97 | + //Setting tenant to global so that reports created can be accessed by others |
|
| 98 | + //And easily identified to copy to other servers/databases |
|
| 99 | + AdHocSettings.CurrentUserTenantId = "_global_"; |
|
| 100 | + |
|
| 101 | + //Set which datasources the user can view |
|
| 102 | + //In this case we are pulling all tables, views and procedures |
|
| 103 | + DataSet ds = AdHocContext.Driver.GetDataSet(AdHocContext.Driver.CreateCommand("select * from sys.objects where type in ('U','P','V')")); |
|
| 104 | + string[] shownTables = new string[ds.Tables[0].Rows.Count]; |
|
| 105 | + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) |
|
| 106 | + shownTables[i] = ds.Tables[0].Rows[i][0].ToString(); |
|
| 107 | + |
|
| 108 | + AdHocSettings.VisibleDataSources = shownTables; |
|
| 109 | + } |
|
| 110 | + else if (AdHocSettings.CurrentUserRoles.Contains<string>("Essentials")) { |
|
| 111 | + AdHocSettings.CurrentUserIsAdmin = false; |
|
| 112 | + AdHocSettings.ShowSettingsButton = false; |
|
| 113 | + AdHocSettings.ShowDesignLinks = false; |
|
| 114 | + //Setting tenant based on third cookie value |
|
| 115 | + AdHocSettings.CurrentUserTenantId = cookieVals[2]; |
|
| 116 | + |
|
| 117 | + //Set which datasources the user can view |
|
| 118 | + //In this case we are setting a static list |
|
| 119 | + |
|
| 120 | + AdHocSettings.VisibleDataSources = new string[] {"Orders","Shippers","Invoices"}; |
|
| 121 | + } |
|
| 122 | + else if (AdHocSettings.CurrentUserRoles.Contains<string>("Pro")) { |
|
| 123 | + AdHocSettings.CurrentUserIsAdmin = false; |
|
| 124 | + AdHocSettings.ShowSettingsButton = false; |
|
| 125 | + AdHocSettings.ShowDesignLinks = false; |
|
| 126 | + AdHocSettings.CurrentUserTenantId = cookieVals[2]; |
|
| 127 | + |
|
| 128 | + //Set which datasources the user can view |
|
| 129 | + //In this case we are pulling only Views |
|
| 130 | + DataSet ds = AdHocContext.Driver.GetDataSet(AdHocContext.Driver.CreateCommand("select * from sys.objects where type in ('V')")); |
|
| 131 | + string[] shownTables = new string[ds.Tables[0].Rows.Count]; |
|
| 132 | + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) |
|
| 133 | + shownTables[i] = ds.Tables[0].Rows[i][0].ToString(); |
|
| 134 | + |
|
| 135 | + AdHocSettings.VisibleDataSources = shownTables; |
|
| 136 | + } |
|
| 137 | + else if (AdHocSettings.CurrentUserRoles.Contains<string>("Elite")) { |
|
| 138 | + AdHocSettings.CurrentUserIsAdmin = false; |
|
| 139 | + AdHocSettings.ShowSettingsButton = false; |
|
| 140 | + AdHocSettings.ShowDesignLinks = false; |
|
| 141 | + AdHocSettings.CurrentUserTenantId = cookieVals[2]; |
|
| 142 | + |
|
| 143 | + //Set which datasources the user can view |
|
| 144 | + //In this case we are pulling all tables, views and procedures |
|
| 145 | + DataSet ds = AdHocContext.Driver.GetDataSet(AdHocContext.Driver.CreateCommand("select * from sys.objects where type in ('U','P','V')")); |
|
| 146 | + string[] shownTables = new string[ds.Tables[0].Rows.Count]; |
|
| 147 | + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) |
|
| 148 | + shownTables[i] = ds.Tables[0].Rows[i][0].ToString(); |
|
| 149 | + |
|
| 150 | + AdHocSettings.VisibleDataSources = shownTables; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + AdHocContext.Initialized = true; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | +} |
|
| 157 | +``` |
|
| ... | ... | \ No newline at end of file |