/// <summary> /// Get the list of modules installed in the connected CRM instance, with their /// associated access control lists. /// </summary> /// <remarks>This data changes only rarely, and is consequently cached for the session. /// </remarks> /// <returns>the list of modules installed in the connected CRM instance.</returns> public static eModuleList GetModules() { if (modulesCache == null) { EnsureLoggedIn(); object data = new { @session = SuiteCRMUserSession.id }; modulesCache = SuiteCRMUserSession.RestServer.GetCrmResponse <eModuleList>("get_available_modules", data); } return(modulesCache); }
/// <summary> /// Check whether this synchroniser is allowed access to the specified CRM module, with the specified permission. /// </summary> /// <remarks> /// Note that, surprisingly, although CRM will report what permissions we have, it will not /// enforce them, so we have to do the honourable thing and not cheat. /// </remarks> /// <param name="moduleName"></param> /// <param name="permission"></param> /// <returns>true if this synchroniser is allowed access to the specified CRM module, with the specified permission.</returns> protected bool HasAccess(string moduleName, string permission) { try { eModuleList oList = clsSuiteCRMHelper.GetModules(); return(oList.modules1.FirstOrDefault(a => a.module_label == moduleName) ?.module_acls1.FirstOrDefault(b => b.action == permission) ?.access ?? false); } catch (Exception) { Log.Warn($"Cannot detect access {moduleName}/{permission}"); return(false); } }
/// <summary> /// Add the standard modules to the list view. /// </summary> private void AddStandardModules() { eModuleList allModules = clsSuiteCRMHelper.GetModules(); foreach (string moduleKey in this.standardModules.OrderBy(x => x)) { var module = allModules.items.FirstOrDefault(x => x.module_key == moduleKey); if (module != null) { this.lstViewSearchModules.Items.Add(new ListViewItem { Tag = module.module_key, Text = module.module_label }); } else { Log.Warn($"Standard modules '{moduleKey}' was not found on the CRM system"); } } }
/// <summary> /// Check whether my synchroniser is allowed access to the specified CRM module, with the specified permission. /// </summary> /// <remarks> /// Note that, surprisingly, although CRM will report what permissions we have, it will not /// enforce them, so we have to do the honourable thing and not cheat. /// </remarks> /// <param name="moduleName">The name of the CRM module being queried.</param> /// <param name="permission">The permission sought.</param> /// <returns>true if my synchroniser is allowed access to the specified CRM module, with the specified permission.</returns> public bool HasAccess(string moduleName, string permission) { bool result = false; bool?cached = HasCachedAccess(moduleName, permission); if (cached != null) { result = (bool)cached; this.log.Debug("Permissions cache hit"); } else { this.log.Debug("Permissions cache miss"); try { eModuleList oList = clsSuiteCRMHelper.GetModules(); bool canExport = oList.items.FirstOrDefault(a => a.module_label == moduleName) ?.module_acls1.FirstOrDefault(b => b.action == ExportPermissionToken) ?.access ?? false; bool canImport = oList.items.FirstOrDefault(a => a.module_label == moduleName) ?.module_acls1.FirstOrDefault(b => b.action == ImportPermissionToken) ?.access ?? false; CacheAccessPermission(moduleName, ExportPermissionToken, canExport); CacheAccessPermission(moduleName, ImportPermissionToken, canImport); Log.Debug($"Cached {this.crmImportExportPermissionsCache[moduleName]} permission for {moduleName}"); result = (permission == ImportPermissionToken && canImport) || (permission == ExportPermissionToken && canExport); } catch (Exception) { Log.Warn($"Cannot detect access {moduleName}/{permission}"); result = false; } } return(result); }
private void frmCustomModules_Load(object sender, EventArgs e) { try { clsSuiteCRMHelper.EnsureLoggedIn(Globals.ThisAddIn.SuiteCRMUserSession); if (Globals.ThisAddIn.SuiteCRMUserSession.NotLoggedIn) { MessageBox.Show("Please enter SuiteCRM details in General tab and try again", "Invalid Authentication"); base.Close(); return; } eModuleList modules = clsSuiteCRMHelper.GetModules(); this.lstViewAvailableModules.SubItemClicked += new SubItemEventHandler(this.listViewAvailableModules_SubItemClicked); if (this.settings.CustomModules != null) { StringEnumerator enumerator = this.settings.CustomModules.GetEnumerator(); while (enumerator.MoveNext()) { string[] strArray = enumerator.Current.Split(new char[] { '|' }); ListViewItem item = new ListViewItem { Text = strArray[0], Tag = strArray[1], Checked = true }; item.SubItems.Add(strArray[1]); if (strArray[0] != "None" || strArray[1] != "None") { this.lstViewAvailableModules.Items.Add(item); } } } foreach (module_data objModuleData in modules.modules1) { string str2 = objModuleData.module_key; bool flag = false; if (!this.IgnoreModules.Contains(str2)) { ListViewItem item2 = new ListViewItem { Text = str2, Tag = str2 }; item2.SubItems.Add(string.Empty); foreach (ListViewItem item3 in this.lstViewAvailableModules.Items) { if (item3.Text == str2) { flag = true; } } if (!flag) { this.lstViewAvailableModules.Items.Add(item2); } } } } catch (Exception ex) { Log.Warn("frmCustomModules_Load error", ex); base.Close(); MessageBox.Show("Please check the Internet connection", "Network Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void frmCustomModules_Load(object sender, EventArgs e) { try { string strUserID = clsSuiteCRMHelper.GetUserId(); if (strUserID == "") { Globals.ThisAddIn.SuiteCRMUserSession.Login(); } if (Globals.ThisAddIn.SuiteCRMUserSession.id == "") { MessageBox.Show("Please enter SuiteCRM details in General tab and try again", "Invalid Authentication"); base.Close(); return; } eModuleList modules = clsSuiteCRMHelper.GetModules(); this.lstViewAvailableModules.SubItemClicked += new SubItemEventHandler(this.listViewAvailableModules_SubItemClicked); if (this.settings.CustomModules != null) { StringEnumerator enumerator = this.settings.CustomModules.GetEnumerator(); while (enumerator.MoveNext()) { string[] strArray = enumerator.Current.Split(new char[] { '|' }); ListViewItem item = new ListViewItem { Text = strArray[0], Tag = strArray[1], Checked = true }; item.SubItems.Add(strArray[1]); if (strArray[0] != "None" || strArray[1] != "None") { this.lstViewAvailableModules.Items.Add(item); } } } foreach (module_data objModuleData in modules.modules1) { string str2 = objModuleData.module_key; bool flag = false; if (!this.IgnoreModules.Contains(str2)) { ListViewItem item2 = new ListViewItem { Text = str2, Tag = str2 }; item2.SubItems.Add(string.Empty); foreach (ListViewItem item3 in this.lstViewAvailableModules.Items) { if (item3.Text == str2) { flag = true; } } if (!flag) { this.lstViewAvailableModules.Items.Add(item2); } } } } catch (Exception ex) { base.Close(); MessageBox.Show("Please check the Internet connection", "Network Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); string strLog; strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n"; strLog += "frmCustomModules_Load General Exception\n"; strLog += "Message:" + ex.Message + "\n"; strLog += "Source:" + ex.Source + "\n"; strLog += "StackTrace:" + ex.StackTrace + "\n"; strLog += "Data:" + ex.Data.ToString() + "\n"; strLog += "HResult:" + ex.HResult.ToString() + "\n"; strLog += "-------------------------------------------------------------------------\n"; clsSuiteCRMHelper.WriteLog(strLog); } }