/// <summary> /// Set flag to try to browse results upon open in both the saved query and any currently open query /// </summary> /// <param name="qid"></param> void SetBrowseSavedResultsUponOpenForQuery( int qid, bool value) { if (qid <= 0) { return; } UserObject uo = UserObjectDao.Read(qid); // update any saved version of query if (uo == null || uo.Type != UserObjectType.Query) { return; } Query q = Query.Deserialize(uo.Content); q.BrowseSavedResultsUponOpen = value; uo.Content = q.Serialize(); UserObjectDao.Write(uo, uo.Id); int di = QueriesControl.Instance.GetQueryIndexByUserObjectId(qid); // update any in-memory version of query if (di < 0) { return; } q = QueriesControl.Instance.GetQuery(di); q.BrowseSavedResultsUponOpen = value; return; // todo }
/// <summary> /// Write a compound number list /// </summary> /// <returns></returns> public static int Write( CidList list, UserObject uo) { string fileName; string content = list.ToMultilineString(); uo.Type = UserObjectType.CnList; uo.Owner = Security.UserName; // assume current user if (!uo.HasDefinedParentFolder && (Lex.Eq(uo.Name, "Current") || Lex.Eq(uo.Name, "Previous") || Lex.Eq(uo.Name, "Criteria List"))) { uo.ParentFolder = UserObject.TempFolderName; uo.ParentFolderType = FolderTypeEnum.None; uo.Owner = Security.UserName; } else if (!uo.HasDefinedParentFolder) { throw new Exception("No parent folder for list"); } uo.Content = content; uo.Count = list.Count; UserObjectDao.Write(uo); return(list.Count); }
/// <summary> /// Pass drilldown along to first metacolumn in calc field for processing /// </summary> /// <param name="mt"></param> /// <param name="mc"></param> /// <param name="level"></param> /// <param name="resultId"></param> /// <returns></returns> public override Query GetDrilldownDetailQuery( MetaTable mt, MetaColumn mc, int level, string linkInfoString) { bool summary; int tableId; MetaTable.ParseMetaTableName(mt.Name, out tableId, out summary); UserObject uo = UserObjectDao.Read(tableId); if (uo == null) { return(null); } CalcField cf = CalcField.Deserialize(uo.Content); if (cf == null) { return(null); } if (cf.MetaColumn1 == null || cf.MetaColumn1.MetaTable == null) { return(null); } Query q = QueryEngine.GetDrilldownDetailQuery(cf.MetaColumn1.MetaTable, cf.MetaColumn1, level, linkInfoString); return(q); }
/// <summary> /// Get email address for a user /// </summary> /// <param name="userName"></param> /// <returns></returns> public static string GetUserEmailAddress( string userName) { string emailAddr = UserObjectDao.GetUserParameter(userName, "EmailAddress"); return(emailAddr); }
void Setup( string groupName, bool editable) { AccessControlList acl; AclItem aclItem; Text = "Users in the Group: " + groupName; Editable = editable; PermissionsList.Editable = editable; Uo = UserObjectDao.ReadHeader(UserObjectType.UserGroup, "Mobius", "", groupName); if (Uo == null) { Uo = new UserObject(); Uo.Type = UserObjectType.UserGroup; Uo.Name = groupName; Uo.Owner = "Mobius"; Uo.ParentFolder = ""; // no parent folder acl = new AccessControlList(); acl.MakePublic(SS.I.UserName); // write to creator, read to others } acl = AccessControlList.Deserialize(Uo.ACL); // content is the list of users PermissionsList.Setup(acl); return; }
/// <summary> /// Set privileges that are stored as privs in Mobius user parameters /// </summary> /// <param name="ui"></param> public static void SetUserParmPrivileges(UserInfo ui) { Dictionary <string, string> ups = UserObjectDao.GetUserParameters(ui.UserName); string prefix = "Privilege"; foreach (string uoName in ups.Keys) // store other non-ad privileges { if (!Lex.StartsWith(uoName, prefix) || // Privilege user parm? Lex.Ne(ups[uoName], "True")) { continue; // and granted? } string privName = uoName.Substring(prefix.Length); if (!PrivilegesMx.IsValidPrivilegeName(privName)) { continue; } if (Lex.Eq(privName, "Logon")) { continue; // ignore old Logon priv from database } ui.Privileges.SetPrivilege(privName, true); } if (!ups.ContainsKey("NAMEADDRESS")) // store user name and address in Mobius db if not there already { Security.CreateUser(ui); } return; }
/// <summary> /// Edit a new or existing link /// </summary> /// <param name="uo">Existing UserObject with content or null to create a new link</param> /// <returns></returns> public static UserObject Edit(UserObject uo) { if (uo == null) // prompt if not supplied { uo = UserObjectOpenDialog.ShowDialog(UserObjectType.SpotfireLink, "Edit Spotfire Link"); } if (uo == null) { return(null); } uo = UserObjectDao.Read(uo); if (uo == null) { throw new Exception("User object not found: " + uo.Id); } SpotfireViewProps sl = SpotfireViewProps.Deserialize(uo.Content); if (sl == null) { return(null); } uo = Edit(sl, uo); return(uo); }
private void OK_Click(object sender, EventArgs e) { // Save preferred project in server preferences if changed if (PreferredProjectChanged) { SS.I.PreferredProjectId = PreferredProjectId; UserObjectDao.SetUserParameter(SS.I.UserName, "PreferredProject", PreferredProjectId); SessionManager.Instance.MainContentsControl.ShowNormal(); // redisplay main tree with new selected project open } // Save default folder info in local preferences string folder = DefaultFolder.Text; if (folder.EndsWith(@"\") && !folder.EndsWith(@":\")) { folder = folder.Substring(0, folder.Length - 1); } if (!System.IO.Directory.Exists(folder)) { XtraMessageBox.Show("Folder does not exist: " + folder, UmlautMobius.String, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DefaultFolder.Focus(); return; } ClientDirs.DefaultMobiusUserDocumentsFolder = folder; Preferences.Set("DefaultExportFolder", folder); // also persist if (ZoomChanged) { Preferences.Set("TableColumnZoom", SS.I.TableColumnZoom); Preferences.Set("GraphicsColumnZoom", SS.I.GraphicsColumnZoom); } SS.I.ScrollGridByPixel = ScrollGridByPixel.Checked; // set selected value if (SS.I.ScrollGridByPixel != InitialScrollGridByPixel) { Preferences.Set("ScrollGridByPixel", SS.I.ScrollGridByPixel); } SaveLookAndFeel(); if (FindRelatedCpdsInQuickSearch.Checked != SS.I.FindRelatedCpdsInQuickSearch) { SS.I.FindRelatedCpdsInQuickSearch = !SS.I.FindRelatedCpdsInQuickSearch; Preferences.Set("FindRelatedCpdsInQuickSearch", SS.I.FindRelatedCpdsInQuickSearch); } if (RestoreWindowsAtStartup.Checked != SS.I.RestoreWindowsAtStartup) { SS.I.RestoreWindowsAtStartup = !SS.I.RestoreWindowsAtStartup; Preferences.Set("RestoreWindowsAtStartup", SS.I.RestoreWindowsAtStartup); } Hide(); // must explicitly hide since closing event is cancelled }
/// <summary> /// Build query to get summarization detail for RgroupMatrix data element /// </summary> /// <param name="mt"></param> /// <param name="mc"></param> /// <param name="resultId">act_code.compound_id</param> /// <returns></returns> public override Query GetDrilldownDetailQuery( MetaTable mt, MetaColumn mc, int level, string resultId) { QueryColumn qc; // ResultId is of the form: queryId, mtName, mcName, sn1, sn2,...snn string[] sa = resultId.Split(','); int objectId = Int32.Parse(sa[0]); UserObject uo = UserObjectDao.Read(objectId); if (uo == null) return null; // no longer there Query q = Query.Deserialize(uo.Content); q.ResultKeys = null; // clear any set of result keys if (q.LogicType == QueryLogicType.Complex) { // if complex logic then go simple (todo: fix to handle complex logic) q.ClearAllQueryColumnCriteria(); q.LogicType = QueryLogicType.And; } q.KeyCriteria = "in ("; for (int i1 = 3; i1 < sa.Length; i1++) { q.KeyCriteria += Lex.AddSingleQuotes(sa[i1]); if (i1 < sa.Length - 1) q.KeyCriteria += ","; } q.KeyCriteria += ")"; return q; }
/// <summary> /// Edit a new or existing calculated field /// </summary> /// <param name="uo">Existing UserObject with content or null to create a new CF</param> /// <returns></returns> public static UserObject Edit(UserObject uo) { if (uo == null) // prompt if not supplied { uo = UserObjectOpenDialog.ShowDialog(UserObjectType.CalcField, "Open Calculated Field"); } if (uo == null) { return(null); } uo = UserObjectDao.Read(uo); if (uo == null) { return(null); } CalcField cf = CalcField.Deserialize(uo.Content); if (cf == null) { return(null); } uo = Edit(cf, uo); return(uo); }
/// <summary> /// Create a new user entry /// </summary> /// <param name="userInfo"></param> /// <returns></returns> public static void CreateUser( UserInfo userInfo) { string txt; if (userInfo == null || Lex.IsNullOrEmpty(userInfo.UserName)) { throw new Exception("User not defined"); } // txt = UserObjectDao.GetUserParameter(userInfo.UserName,"NameAddress"); // if (txt!="") return false; txt = userInfo.FirstName + "|" + userInfo.MiddleInitial + "|" + userInfo.LastName + "|" + userInfo.EmailAddress + "|" + userInfo.Company + "|" + userInfo.Site + "|" + userInfo.Department + "|" + userInfo.UserDomainName + "|" + userInfo.UserName; UserObjectDao.SetUserParameter(userInfo.UserName, "NameAddress", txt); GrantPrivilege(userInfo.UserName, "Logon"); // authorize by default return; }
void SetupGrid(List <UserObject> alerts) { string txt, tok; DataTable dt = CreateDataTable(); foreach (UserObject uo in alerts) // fill the grid { UserObject uo2 = uo; Alert alert = Alert.GetAlertFromUserObject(uo2, false); UserObject quo = UserObjectDao.ReadHeader(alert.QueryObjId); // get query header for name if (quo == null) { continue; // associated query missing? } alert.QueryName = quo.Name; alert.LastQueryUpdate = quo.UpdateDateTime; DataRow dr = dt.NewRow(); SetDataRow(dr, alert); dt.Rows.Add(dr); } Grid.DataSource = dt; Grid.Refresh(); if (ServicesIniFile.Read("AlertHelpUrl") != "") { Help.Enabled = true; } return; }
bool Save(bool prompt) { UserObject uo2; if (!IsValidCalcField()) { return(false); } if (!GetCalcFieldForm()) { return(false); } if (prompt) { uo2 = UserObjectSaveDialog.Show("Save Calculated Field Definition", UoIn); if (uo2 == null) { return(false); } } else { uo2 = UoIn.Clone(); } if (!UserObjectUtil.UserHasWriteAccess(uo2)) { // is the user authorized to save this? MessageBoxMx.ShowError("You are not authorized to save this calculated field"); return(false); } SessionManager.DisplayStatusMessage("Saving calculated field..."); string content = CalcField.Serialize(); uo2.Content = content; //need the name of the folder to which the object will be saved MetaTreeNode targetFolder = UserObjectTree.GetValidUserObjectTypeFolder(uo2); if (targetFolder == null) { MessageBoxMx.ShowError("Failed to save your calculated field."); return(false); } UserObjectDao.Write(uo2); string tName = "CALCFIELD_" + uo2.Id.ToString(); QbUtil.UpdateMetaTableCollection(tName); MainMenuControl.UpdateMruList(tName); string title = "Edit Calculated Field - " + uo2.Name; Text = title; UoIn = uo2.Clone(); // now becomes input object SessionManager.DisplayStatusMessage(""); return(true); }
/// <summary> /// Get user info for a single user from user object table /// </summary> /// <param name="userName"></param> /// <returns></returns> public static UserInfo ReadUserInfoFromNameAddressUserObject( string userName) { UserInfo ui; if (userName == null || userName == "") { return(null); } string txt = UserObjectDao.GetUserParameter(userName, "NameAddress"); if (txt == null || txt == "") { if (IsSpecialMobiusAccount(userName)) { return(CreateDefaultMobiusAccountUserInfo(userName)); } else { return(null); } } ui = UserInfo.Deserialize(txt); if (ui.UserName == "") { ui.UserName = userName; // plug in user name in case not deserialized } return(ui); }
/// <summary> /// Edit and existing Spotfire link /// </summary> /// <param name="internalName"></param> /// <returns></returns> public static UserObject Edit(string internalName) { UserObject uo = null; if (Lex.IsDefined(internalName)) // get the user object { uo = UserObject.ParseInternalUserObjectName(internalName, ""); if (uo != null) { uo = UserObjectDao.Read(uo.Id); } if (uo == null) { throw new Exception("User object not found " + internalName); } } else { uo = null; // no arg, show open dialog } UserObject uo2 = Edit(uo); if (uo2 != null && uo2.Id > 0) { QbUtil.UpdateMetaTableCollection(uo2.InternalName); } return(uo2); }
/// <summary> /// If SavedListUo is defined just return otherwise check in default folder for ListName /// </summary> string ResolveSavedListUo() { if (SavedListUo != null) { return("CNLIST_" + SavedListUo.Id); } if (ListName.Text == "") { return(""); } UserObject uo = new UserObject(UserObjectType.CnList, SS.I.UserName, ListName.Text); UserObjectTree.AssignDefaultObjectFolder(uo, UserObjectType.CnList); SavedListUo = UserObjectDao.ReadHeader(uo); if (SavedListUo != null) { return("CNLIST_" + SavedListUo.Id); } string errMsg = "List " + ListName.Text + " does not exist"; MessageBoxMx.Show(errMsg, UmlautMobius.String, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); // return null if nonexistant list }
/// <summary> /// Read in focused UserObject /// </summary> /// <param name="ri"></param> /// <param name="dr"></param> /// <param name="ucdb"></param> /// <param name="uo"></param> /// <returns></returns> bool GetFocusedUo(out int ri, out DataRow dr, out UcdbDatabase ucdb, out UserObject uo) { dr = null; ucdb = null; uo = null; ri = GridView.FocusedRowHandle; if (ri < 0) { MessageBoxMx.ShowError("You must select the user compound database first"); return(false); } dr = DataTable.Rows[ri]; ucdb = (UcdbDatabase)dr["Ucdb"]; uo = UserObjectDao.Read(UserObjectType.UserDatabase, ucdb.OwnerUserName, ucdb.NameSpace, ucdb.Name); if (uo == null) { MessageBoxMx.ShowError("Unable to find associated user database \"UserObject\" information"); return(false); } return(true); }
/// <summary> /// Serialize & write the alert to a UserObject. /// Basic information is serialized into the Description /// column and the results of the most recent check are /// serialized into Content. /// </summary> /// <returns></returns> public int Write() { UserObject alertUserObject; if (ExistingAlert) { alertUserObject = UserObjectDao.ReadHeader(Id); //alertUserObject.UpdateDateTime = DateTime.Now; alertUserObject.Description = SerializeHeader(); alertUserObject.Content = SerializeResults(); UserObjectDao.Write(alertUserObject, alertUserObject.Id); } else { alertUserObject = new UserObject(UserObjectType.Alert) { Id = Id, Owner = Owner, Name = "Alert_" + QueryObjId }; alertUserObject.Description = SerializeHeader(); alertUserObject.Content = SerializeResults(); UserObjectDao.Write(alertUserObject); Id = alertUserObject.Id; } return(Id); }
/// <summary> /// Delete user /// </summary> /// <param name="userName"></param> public static bool DeleteUser( string userName) { try { RevokePrivilege(userName, "Logon"); } catch (Exception ex) { } return(UserObjectDao.DeleteAllUserObjects(userName)); }
/// <summary> /// See if the named list exists /// </summary> /// <param name="name"></param> /// <returns></returns> public static bool Exists( string name) { UserObject uo = UserObjectUtil.ParseInternalUserObjectName(name); uo.Type = UserObjectType.CnList; uo = UserObjectDao.ReadHeader(uo); return(uo != null); }
/// <summary> /// Save the SpotfireLink UserObject /// </summary> /// <param name="prompt"></param> /// <returns></returns> bool Save(bool prompt) { UserObject uo2; if (!IsValidSpotfireLink()) { return(false); } if (!GetSpotfireLinkForm()) { return(false); } if (prompt) { uo2 = UserObjectSaveDialog.Show("Save Spotfire link Definition", UoIn); if (uo2 == null) { return(false); } } else { uo2 = UoIn.Clone(); } uo2.Content = SpotfireViewProps.Serialize(); if (!UserObjectUtil.UserHasWriteAccess(uo2)) { // is the user authorized to save this? MessageBoxMx.ShowError("You are not authorized to save this Spotfire link"); return(false); } SessionManager.DisplayStatusMessage("Saving Spotfire link..."); //need the name of the folder to which the object will be saved MetaTreeNode targetFolder = UserObjectTree.GetValidUserObjectTypeFolder(uo2); if (targetFolder == null) { MessageBoxMx.ShowError("Failed to save your Spotfire link."); return(false); } UserObjectDao.Write(uo2); MainMenuControl.UpdateMruList(uo2.InternalName); string title = "Edit Spotfire Link - " + uo2.Name; Text = title; UoIn = uo2.Clone(); // now becomes input object SessionManager.DisplayStatusMessage(""); return(true); }
/// <summary> /// Change the owner of a UserObject /// </summary> /// <param name="args"></param> /// <returns></returns> public static string ChangeOwner( int objId, string newOwner) { newOwner = newOwner.ToUpper(); UserObject uo = UserObjectDao.ReadHeader(objId); if (uo == null) { return("User object not found: " + objId); } if (uo.Owner == newOwner) { return("This user object is already owned by " + newOwner); } if (!Security.IsAdministrator(SS.I.UserName) && Lex.Ne(uo.Owner, SS.I.UserName)) { return("You're not authorized to change the owner of this user object"); } if (!Security.CanLogon(newOwner)) { return("Not a valid userId: " + newOwner); } UserInfo ui = Security.GetUserInfo(newOwner); string msg = "Are you sure you want to transfer ownership of " + Lex.AddDoubleQuotes(uo.Name) + "\n" + "to " + ui.FullName + "?"; DialogResult dr = MessageBoxMx.Show(msg, "Change Owner", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr != DialogResult.Yes) { return(""); } UserObject uo2 = uo.Clone(); uo2.Owner = newOwner; UserObjectTree.GetValidUserObjectTypeFolder(uo2); // set valid parent folder Permissions.UpdateAclForNewOwner(uo2, uo.Owner, newOwner); // Set the ACL to give us r/w access uo2.Content = "ChangeOwner"; // indicate changing owner if (UserObjectDao.ReadHeader(uo2) != null) { return("A user object with that name already exists for the specified new user"); } UserObjectDao.UpdateHeader(uo2, false, false); if (Data.InterfaceRefs.IUserObjectIUD != null) { Data.InterfaceRefs.IUserObjectIUD.UserObjectDeleted(uo); // remove from view } string newOwnerName = SecurityUtil.GetPersonNameReversed(newOwner); return("Ownership of \"" + uo2.Name + "\" has been changed to " + newOwnerName); }
/// <summary> /// Set value for a string parameter /// </summary> /// <param name="parameter"></param> /// <param name="value"></param> public static void Set( string parameter, string value) { string key = parameter.ToUpper(); PrefDict[key] = value; // update local dict UserObjectDao.SetUserParameter(SS.I.UserName, parameter, value); }
/// <summary> /// Grant a privilege to a user /// </summary> /// <param name="userName"></param> /// <param name="privilege"></param> /// <returns></returns> public static void GrantPrivilege( string userName, string privilege) { if (!PrivilegesMx.IsValidPrivilegeName(privilege)) { throw new Exception("Not a valid privilege"); } UserObjectDao.SetUserParameter(userName, "Privilege" + Lex.CapitalizeFirstLetters(privilege), "True"); // authorize by default return; }
/// <summary> /// Create an annotation table given its metatable and user object /// </summary> /// <param name="mt"></param> /// <param name="uo"></param> public static void CreateAnnotationTable( MetaTable mt, UserObject uo) { uo.Type = UserObjectType.Annotation; // be sure type is set uo.Content = mt.Serialize(); // serialize the metatable to the user object UserObjectTree.GetValidUserObjectTypeFolder(uo); UserObjectDao.Write(uo); // write the user object MetaTableCollection.UpdateGlobally(mt); // update map with modified metatable return; }
/// <summary> /// Set user parameter enabling/disabling display of news /// </summary> /// <param name="enabled"></param> public static void SetShowNewsEnabled( bool enabled) { if (enabled) { UserObjectDao.SetUserParameter(SS.I.UserName, "ShowNews", SS.I.CurrentDate); } else { UserObjectDao.SetUserParameter(SS.I.UserName, "ShowNews", "false"); } }
/// <summary> /// Get the MQL for a saved query /// </summary> /// <param name="queryId"></param> /// <returns></returns> /// public static string GetSavedQueryMQL( int queryId, bool mobileQuery = false) { UserObject uo = UserObjectDao.Read(queryId); if (uo == null) { return(null); } Query q = Query.Deserialize(uo.Content); string mql = MqlUtil.ConvertQueryToMql(q, mobileQuery); // to mql return(mql); }
public static UserObject GetNextAlert(string processorId, string alertQueueFileName) { Mutex mutex = new Mutex(false, _mobiusAlertQueue); mutex.WaitOne(); // get exclusive access int alertId; try { StreamReader sr = new StreamReader(alertQueueFileName); string content = sr.ReadToEnd(); sr.Close(); if (Lex.IsNullOrEmpty(content)) // all done if nothing left in queue { //AlertCount = 0; return(null); } int i1 = content.IndexOf(","); if (i1 >= 0) { alertId = Int32.Parse(content.Substring(0, i1)); content = content.Substring(i1 + 1); } else { alertId = Int32.Parse(content); content = ""; } StreamWriter sw = new StreamWriter(alertQueueFileName); sw.Write(content); sw.Close(); //_remainingingAlertCount--; } catch (Exception ex) { AlertUtil.LogAlertMessage("Error accessing alert queue: " + ex.Message + processorId); return(null); } finally { mutex.ReleaseMutex(); } UserObject uo = UserObjectDao.Read(alertId); // read the alert if (uo == null) { AlertUtil.LogAlertMessage("Error reading alert " + alertId + processorId); } return(uo); }
/// <summary> /// Read a query & return with metatables embedded in the query for UserObject /// </summary> /// <param name="uo"></param> /// <returns>The requested user object or null if no matching user object is found.</returns> public static UserObject ReadQueryWithMetaTables(UserObject uo) { Query q, q2; uo = UserObjectDao.Read(uo); if (uo == null) { return(null); } // Sharing a query implicitly shares any underlying annotations, calc fields & lists. // Mark these objects as readable within the context of this query even if they are not shared. Permissions.AllowTemporaryPublicReadAccessToAllUserObjects = true; q = Query.Deserialize(uo.Content); foreach (QueryTable qt in q.Tables) { // mark any saved lists in criteria as temporarily readable since the query is readable foreach (QueryColumn qc in qt.QueryColumns) { if (qc.MetaColumn.DataType == MetaColumnType.CompoundId && Lex.Contains(qc.Criteria, "IN LIST")) { int id; string criteria = qc.MetaColumn.Name + " " + qc.Criteria; ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(criteria); if (psc == null) { continue; } psc.Value = Lex.RemoveAllQuotes(psc.Value); if (Lex.IsUndefined(psc.Value)) { continue; } if (UserObject.TryParseObjectIdFromInternalName(psc.Value, out id) && id > 0) { Permissions.TemporaryPublicReadAccessUserObjects[id] = null; } } } } Permissions.AllowTemporaryPublicReadAccessToAllUserObjects = false; uo.Content = q.Serialize(true); // serialize with metatables return(uo); }
/// <summary> /// Read a query & return with metatables embedded in the query given the object id /// </summary> /// <param name="objectId">id of item to read</param> /// <returns>The requested user object or null if no matching user object is found.</returns> public static UserObject ReadQueryWithMetaTables(int objectId) { UserObject uo = UserObjectDao.Read(objectId); if (uo == null) { return(null); } Query q = Query.Deserialize(uo.Content); uo.Content = q.Serialize(true); // serialize with metatables return(uo); }