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> /// 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); }
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; }
/// <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> /// 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> /// 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); }
private void OpenQuery_Click(object sender, EventArgs e) { int row, queryId; row = V.GetFocusedDataSourceRowIndex(); if (row < 0) { return; } queryId = (int)DataTable.Rows[row]["QueryId"]; UserObject quo = UserObjectDao.ReadHeader(queryId); string path = quo.InternalName; QbUtil.OpenQuery(path, true, false, false); DialogResult = DialogResult.OK; // close dialog }
static UserObject ParseAndReadUserObject(string tok) { int i1 = tok.IndexOf("_"); // parse the <Type>_<ObjectId> string if (i1 < 0) { throw new Exception("Invalid input"); } int id = Int32.Parse(tok.Substring(i1 + 1)); UserObject uo = UserObjectDao.ReadHeader(id); if (uo == null) { MessageBoxMx.ShowError("UserObject " + tok + " not found"); } return(uo); }
/// <summary> /// Return the header information for any existing alert for this user for the specified query /// </summary> /// <param name="queryId"></param> /// <returns></returns> public static Alert GetAlertByQueryId( int queryId) { if (queryId <= 0) { return(null); } UserObject auo = UserObjectDao.ReadHeader(UserObjectType.Alert, SS.I.UserName, "", "Alert_" + queryId); if (auo == null) { return(null); } Alert alert = DeserializeHeader(auo); return(alert); }
/// <summary> /// See if the current user can modify the supplied object /// </summary> /// <param name="objectId"></param> /// <returns></returns> public static bool UserHasWriteAccess( string userName, int objectId) { if (objectId <= 0) { return(true); // new unsaved object } if (objectId == LastUserHasWriteAccessId) { return(LastUserHasWriteAccessResult); } UserObject uo = UserObjectDao.ReadHeader(objectId); LastUserHasWriteAccessId = objectId; LastUserHasWriteAccessResult = UserObjectUtil.UserHasWriteAccess(uo); return(LastUserHasWriteAccessResult); }
//public UserObjectUtil() //{ //} /// <summary> /// Right-click commands on objects in a tree /// </summary> /// <param name="command">Command to execute</param> /// <param name="userObjectName">Name of user object to operate on</param> /// <param name="ctc">ContentsTreeControl to update</param> public static bool ProcessCommonRightClickObjectMenuCommands( string command, MetaTreeNode mtn, ContentsTreeControl ctc) { UserObject uo; UserObjectType objType; int id; string userObjectName = mtn.Target; UserObject.ParseObjectTypeAndIdFromInternalName(userObjectName, out objType, out id); uo = UserObjectDao.ReadHeader(id); if (uo == null) { MessageBoxMx.ShowError(userObjectName + " not found"); return(false); } UserObject[] uoArray = new UserObject[] { uo }; return(ProcessCommonRightClickObjectMenuCommands(command, mtn, uoArray, ctc)); }
/// <summary> /// Fast insert/update of a single row including creation of the AnnotationDao object, transaction and header update /// </summary> /// <param name="vo"></param> /// <returns></returns> public static long InsertUpdateRowAndUserObjectHeader(AnnotationVo vo) { bool newRow = vo.rslt_id <= 0; AnnotationDao dao = new AnnotationDao(); dao.BeginTransaction(); long rsltId = dao.InsertUpdateRow(vo); dao.Commit(); dao.Dispose(); UserObject uo = UserObjectDao.ReadHeader(vo.mthd_vrsn_id); if (uo != null) { uo.UpdateDateTime = DateTime.Now; if (newRow) { uo.Count++; } UserObjectDao.UpdateHeader(uo); } return(rsltId); }
/// <summary> /// Convert complex criteria to labeled form suitable for editing in complex criteria editor /// </summary> /// <param name="q"></param> /// <param name="structures">Dictionary of structure names & connection tables</param> public static LabeledCriteria ConvertComplexCriteriaToEditable( Query q, bool includeEditButtons) { bool insertBreaks = false; if (q.ComplexCriteria.IndexOf("\n") < 0) { insertBreaks = true; } Dictionary <string, string> tAliasMap = GetAliasMap(q); if (tAliasMap != null && !includeEditButtons) { // fixup aliases properly first using editable criteria ConvertComplexCriteriaToEditable(q, true); tAliasMap = null; } Lex lex = new Lex(); lex.SetDelimiters(" , ; ( ) < = > <= >= <> != !> !<"); string criteria = q.ComplexCriteria; lex.OpenString(criteria); StringBuilder sb = new StringBuilder(); PositionedToken lastTok = null; List <PositionedToken> tokens = new List <PositionedToken>(); // list of tokens seen LabeledCriteria lc = new LabeledCriteria(); lc.Structures = new Dictionary <string, string>(); while (true) { PositionedToken tok = lex.GetPositionedToken(); if (tok == null) { break; } tokens.Add(tok); if (lastTok != null) { // include same white space between tokens int wsBeg = lastTok.Position + lastTok.Text.Length; sb.Append(criteria.Substring(wsBeg, tok.Position - wsBeg)); } QueryColumn qc = MqlUtil.GetQueryColumn(tok.Text, q); // see if token is column ref if (qc != null) { //query column, map to labeled columns string label = GetUniqueColumnLabel(qc); QueryTable qt = qc.QueryTable; string tName, cName; MqlUtil.ParseColumnIdentifier(tok.Text, out tName, out cName); if (tName != null && tName != "") // any table name supplied? { if (tAliasMap != null && tAliasMap.ContainsKey(tName.ToUpper())) { tName = tAliasMap[tName.ToUpper()]; } label = tName + "." + label; } sb.Append(Lex.Dq(label)); } else { // not a query column reference string tokText = tok.Text; string txt = Lex.RemoveSingleQuotes(tokText).ToUpper(); if (UserObject.IsCompoundIdListName(txt)) { string listName = null; int objectId = int.Parse(txt.Substring(7)); UserObject uo = UserObjectDao.ReadHeader(objectId); if (uo != null) { listName = uo.InternalName; } else { listName = "Unknown"; } tokText = Lex.AddSingleQuotes(listName); } if (tokens.Count >= 5) { // see if this is a chime string string sFuncCand = tokens[tokens.Count - 5].Text.ToLower(); if ((Lex.Eq(sFuncCand, "SSS") || Lex.Eq(sFuncCand, "FSS") || Lex.Eq(sFuncCand, "MolSim")) && tokText.StartsWith("'") && tokText.EndsWith("'")) // single-quoted chime? { string sAlias = "S" + (lc.Structures.Count + 1).ToString(); lc.Structures[sAlias] = Lex.RemoveSingleQuotes(tokText); // save structure in dictionary if (includeEditButtons) { tokText = "[Edit Structure " + sAlias + "]"; // use alias in labeled query } else { tokText = Lex.AddSingleQuotes(sAlias); } } } if ((Lex.Eq(tokText, "And") || Lex.Eq(tokText, "Or")) && tokens.Count >= 3 && !Lex.Eq(tokens[tokens.Count - 3].Text, "Between") && insertBreaks) { sb.Append("\n"); // start new line for each and/or } sb.Append(tokText); // not query column identifier } lastTok = tok; } sb.Append(" "); // include final space so additional text is black, also to get correct font lc.Text = sb.ToString(); // If a table alias changes then update aliases & complex criteria but only if going // to editable text since ConvertEditableCriteriaToComplex fails otherwise. if (tAliasMap != null) { for (int qti = 0; qti < q.Tables.Count; qti++) { // set new table aliases QueryTable qt = q.Tables[qti]; string alias = "T" + (qti + 1).ToString(); qt.Alias = alias; } ConvertEditableCriteriaToComplex(lc, q, null); // update q.ComplexCriteria also } return(lc); }
/// <summary> /// Examine a text reference to a cnList & try to resolve to an existing cnList /// </summary> /// <param name="tok"></param> /// <returns></returns> public static UserObject ResolveCidListReference( string tok) { UserObject uo, uo2; tok = Lex.RemoveAllQuotes(tok).ToUpper(); // remove any quotes // New form: <objectType>_<objectId> if (UserObject.IsCompoundIdListName(tok)) { try { int objectId = int.Parse(tok.Substring(7)); if (objectId == 0) // current list { uo = new UserObject(UserObjectType.CnList, Security.UserName, "Current"); } else { uo = UserObjectDao.ReadHeader(objectId); // other list } return(uo); } catch (Exception ex) { return(null); } } // May be older form of identifier // 1. Current // 2. Owner.Folder.Name // 3. Folder.Name // 4. Name else { if (Lex.Eq(tok, "Current")) // if "current" then fully qualify { tok = UserObject.TempFolderNameQualified + tok; } if (tok.Contains(".") || tok.Contains("_")) { uo = UserObject.ParseInternalUserObjectName(tok, Security.UserName); } else // if simple unqualified name try default folder for user { uo = new UserObject(); uo.Name = tok; uo.Owner = Security.UserName; string preferredProject = UserObjectDao.GetUserParameter(Security.UserName, "PreferredProject"); if (Lex.IsNullOrEmpty(preferredProject)) { return(null); } uo.ParentFolder = preferredProject; } uo.Type = UserObjectType.CnList; UserObject listUo = UserObjectDao.ReadHeader(uo); if (listUo != null) { return(listUo); } // See if there is a "Lists" folder one level down that contains this uo2 = new UserObject(); uo2.Type = UserObjectType.Folder; uo2.Owner = uo.Owner; uo2.ParentFolder = uo.ParentFolder; uo2.Name = "Lists"; uo2 = UserObjectDao.ReadHeader(uo2); if (uo2 == null) { return(null); } uo.ParentFolder = "FOLDER_" + uo2.Id.ToString(); listUo = UserObjectDao.ReadHeader(uo); return(listUo); } }
/// <summary> /// Right-click commands on objects in a tree /// </summary> /// <param name="command">The command to process</param> /// <param name="mtn">MetaTreeNode</param> /// <param name="uo">Any associated user object</param> /// <param name="ctc">ContentsTreeControl</param> /// <returns></returns> public static bool ProcessCommonRightClickObjectMenuCommands( string command, MetaTreeNode mtn, UserObject[] uoArray, ContentsTreeControl ctc) { UserObject uo2; string txt; UserObject uo = null; if (uoArray != null && uoArray.Length == 1) { uo = uoArray[0]; } //if (mtn == null) //{ // MessageBoxMx.ShowError("Operation is not allowed for this Database Contents node."); // return true; //} if (Lex.Eq(command, "Cut")) { CopyCutDelete(command, uoArray, ctc, true, true); } else if (Lex.Eq(command, "Copy")) { CopyCutDelete(command, uoArray, ctc, true, false); } else if (Lex.Eq(command, "Paste")) { try { txt = Clipboard.GetText(); //uo2 = UserObject.Deserialize(txt); uoArray = Deserialize(txt); if (uoArray == null) { throw new Exception("Not a UserObject"); } //if (uo2 == null) throw new Exception("Not a UserObject"); } catch (Exception ex) { MessageBoxMx.ShowError("The clipboard does not contain a recognized user objects"); return(true); } foreach (var userObject in uoArray) { Progress.Show("Pasting " + userObject.Name + "...", UmlautMobius.String, false); Permissions.UpdateAclForNewOwner(userObject, userObject.Owner, SS.I.UserName); // fixup the ACL for the new owner userObject.Owner = SS.I.UserName; userObject.ParentFolder = mtn.Name; mtn = UserObjectTree.GetValidUserObjectTypeFolder(userObject); for (int ci = 0; ; ci++) // find a name that's not used { UserObject uo3 = UserObjectDao.ReadHeader(userObject); if (uo3 == null) { break; } if (ci == 0) { userObject.Name = "Copy of " + userObject.Name; } else if (ci == 1) { userObject.Name = Lex.Replace(userObject.Name, "Copy of ", "Copy (2) of "); } else { userObject.Name = Lex.Replace(userObject.Name, "Copy (" + ci + ") of ", "Copy (" + (ci + 1) + ") of "); } } UserObject userObjectFinal = null; if (UserObjectDao.ReadHeader(userObject.Id) != null) // create a deep clone if orignal object exists { userObjectFinal = DeepClone(userObject); } if (userObjectFinal == null) { userObjectFinal = userObject; } UserObjectDao.Write(userObjectFinal, userObjectFinal.Id); // write using the current id Progress.Hide(); } //if (ctc != null) // need to update form directly? // UserObjectTree.RefreshSubtreeInTreeControl(uo2, ctc); } else if (Lex.Eq(command, "Delete")) { CopyCutDelete(command, uoArray, ctc, false, true); } else if (Lex.Eq(command, "Rename")) { if (!UserHasWriteAccess(uo)) { MessageBoxMx.ShowError("You are not authorized to rename " + uo.Name); return(true); } string newName = InputBoxMx.Show("Enter the new name for " + uo.Name, "Rename", uo.Name); if (newName == null || newName == "" || newName == uo.Name) { return(true); } if (!IsValidUserObjectName(newName)) { MessageBoxMx.ShowError("The name " + newName + " is not valid."); return(true); } uo2 = uo.Clone(); uo2.Name = newName; uo2.Id = 0; // clear Id so not looked up by id if (!Lex.Eq(newName, uo.Name) && UserObjectDao.ReadHeader(uo2) != null) { MessageBoxMx.ShowError(newName + " already exists."); return(true); } uo2.Id = uo.Id; UserObjectDao.UpdateHeader(uo2); if (ctc != null) { UserObjectTree.UpdateObjectInTreeControl(uo, uo2, ctc); } } else if (Lex.Eq(command, "MakePublic") || Lex.Eq(command, "MakePrivate")) { UserObjectAccess newAccess; MetaTreeNode objFolder; if (!UserHasWriteAccess(uo)) { MessageBoxMx.ShowError("You are not authorized to make " + uo.Name + ((Lex.Eq(command, "MakePublic")) ? " public" : " private")); return(true); } if (Lex.Eq(command, "MakePublic")) { if (uo.ParentFolder == "DEFAULT_FOLDER") { MessageBoxMx.ShowError("Items in the Default Folder cannot be made public"); return(true); } else { //check the folder id parentage to ensure that the current folder isn't a subfolder of the default folder if (UserObjectTree.FolderNodes.ContainsKey(uo.ParentFolder)) { objFolder = UserObjectTree.FolderNodes[uo.ParentFolder]; while (objFolder != null) { if (objFolder.Target == "DEFAULT_FOLDER") { MessageBoxMx.ShowError("Items in the Default Folder cannot be made public"); return(true); } objFolder = objFolder.Parent; } } else { throw new Exception("Failed to recognize the folder that this object is in!"); } } newAccess = UserObjectAccess.Public; } else { //user folders cannot be made private if they contain public children if (uo.Type == UserObjectType.Folder) { objFolder = UserObjectTree.BuildNode(uo); if (UserObjectTree.FolderNodes.ContainsKey(objFolder.Target)) { objFolder = UserObjectTree.FolderNodes[objFolder.Target]; for (int i = 0; i < objFolder.Nodes.Count; i++) { MetaTreeNode currentChild = (MetaTreeNode)objFolder.Nodes[i]; } } } newAccess = UserObjectAccess.Private; } uo2 = UserObjectDao.Read(uo); if (uo2 == null) { return(true); } if (uo2.AccessLevel == newAccess) { return(true); // no change } uo2.AccessLevel = newAccess; UserObjectDao.UpdateHeader(uo2); if (ctc != null) // need to update form directly? { UserObjectTree.RefreshSubtreeInTreeControl(uo2, ctc); } return(true); } else if (Lex.Eq(command, "ChangeOwner")) { string newOwner = InputBoxMx.Show("Enter the user name of the person to transfer ownership of " + Lex.AddDoubleQuotes(uo.Name) + " to:", "Change Owner", ""); if (Lex.IsNullOrEmpty(newOwner)) { return(true); } string result = UserObjectUtil.ChangeOwner(uo.Id, newOwner); if (!Lex.IsNullOrEmpty(result)) { MessageBoxMx.Show(result); } return(true); } else if (Lex.Eq(command, "Permissions")) // set object permissions { PermissionsDialog.Show(uo); return(true); } else if (Lex.Eq(command, "ViewSource")) { uo = UserObjectDao.Read(uo); if (uo == null) { return(true); } string ext = ".txt"; // default extension if (uo.Type == UserObjectType.Query || uo.Type == UserObjectType.Annotation) { ext = ".xml"; } string cFile = ClientDirs.TempDir + @"\Source" + ext; StreamWriter sw = new StreamWriter(cFile); sw.Write(uo.Content); sw.Close(); SystemUtil.StartProcess(cFile); // show it } else { return(false); // command not recognized } return(true); // command recognized and processed }
private void SaveButton_Click(object sender, EventArgs e) { if (ObjectName.Text.Trim() == "") { MessageBoxMx.ShowError("You must supply a name"); ObjectName.Focus(); return; } if (ProjectName.Text.Trim() == "") { ProjectTarget.Text = ""; if (Lex.Ne(ObjectName.Text.Trim(), "Current")) // blank project not allowed unless saving current { MessageBoxMx.ShowError("You must supply a folder name"); ProjectName.Focus(); return; } } string txt = ProjectTarget.Text; if (txt.ToLower().IndexOf("project ") == 0 && txt.Length > 8) { txt = txt.Substring(8); } else if (txt.ToLower().IndexOf("folder ") == 0 && txt.Length > 7) { txt = txt.Substring(7).ToUpper(); } else if (txt.ToLower().IndexOf("submenu ") == 0 && txt.Length > 8) { txt = txt.Substring(8).ToUpper(); } MetaTreeNode mtn = MetaTree.GetNode(txt); if (mtn == null && UserObjectTree.FolderNodes.ContainsKey(txt)) { mtn = UserObjectTree.FolderNodes[txt]; } UserObject uo2 = new UserObject(Uo.Type); uo2.Owner = SS.I.UserName; // we will be the new owner uo2.Description = Uo.Description; // copy any description uo2.Name = ObjectName.Text; uo2.AccessLevel = Uo.AccessLevel; uo2.ACL = Uo.ACL; //reassigning the folder id to the object type folder happens in the "Save" if (mtn != null) { uo2.ParentFolder = mtn.Target.ToUpper(); uo2.ParentFolderType = mtn.GetUserObjectFolderType(); } UserObject uo3 = UserObjectDao.ReadHeader(uo2); // see if already exists if (uo3 != null) { string objectTypeName = UserObject.GetTypeLabel(Uo.Type); DialogResult dr = MessageBoxMx.Show( objectTypeName + " " + uo2.Name + " already exists. Do you want to replace it?", UmlautMobius.String, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.No) { return; } else if (dr == DialogResult.Cancel) { DialogResult = DialogResult.Cancel; return; } else { uo2.Id = uo3.Id; // keep the id when overwriting } } Uo = uo2; // info on object to save DialogResult = DialogResult.OK; return; }
/// <summary> /// Edit an alert /// </summary> /// <param name="objectId">AlertId or QueryId to edit alert for</param> /// <param name="alert">New alert content</param> /// <returns>-1 if alert deleted, 0 if edit cancelled, alertId if successfully edited</returns> public static int Edit( int objectId, out Alert alert) { alert = null; int alertId = 0; UserObject auo = null; // alert user object UserObject quo = null; if (objectId > 0) // read existing alert/query header { UserObject uo = UserObjectDao.ReadHeader(objectId); if (uo == null) { throw new Exception("UserObject not found " + objectId.ToString()); } if (uo.Type == UserObjectType.Alert) // editing existing alert { auo = uo; alertId = objectId; alert = Alert.GetAlertFromUserObject(auo, false); quo = UserObjectDao.ReadHeader(alert.QueryObjId); alert.QueryName = quo.Name; alert.LastQueryUpdate = quo.UpdateDateTime; } else if (uo.Type == UserObjectType.Query) // edit any alert associated with existing query { quo = uo; alert = Alert.GetAlertByQueryId(uo.Id); if (alert != null) { alertId = alert.Id; alert.QueryName = quo.Name; alert.LastQueryUpdate = quo.UpdateDateTime; } } else { throw new Exception("UserObject not alert or query " + objectId.ToString()); } } if (alertId == 0) // create basic new alert object { alert = new Alert(quo); } if (Instance == null) { Instance = new AlertProperties(); } Instance.Setup(alert, quo); DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm); if (dr == DialogResult.Abort) // alert deleted { alert = null; return(-1); } else if (dr == DialogResult.Cancel) { return(0); // edit cancelled } else { return(Instance.Alert.Id); // successfully created/edited, return the userobject id } }
/// <summary> /// Validate the selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OK_Click(object sender, EventArgs e) { UserObjectType type; int id; if (ObjectName.Text == "") { MessageBoxMx.Show("A name must be supplied", UmlautMobius.String, MessageBoxButtons.OK); return; } if (SelectedNode != null) // selected from tree { UserObject.ParseObjectTypeAndIdFromInternalName(SelectedNode.Target, out type, out id); OpenUoInfo = UserObjectDao.ReadHeader(id); DialogResult = DialogResult.OK; return; } else // name typed in, determine the location { MetaTreeNode folderNode = ContentsTreeWithSearch.ContentsTreeCtl.FocusedMetaTreeNode; bool foundFolder = false; while (folderNode != null) { if (folderNode.IsFolderType) { foundFolder = true; break; } folderNode = folderNode.Parent; // move up in tree } if (!foundFolder) { // could not determine where to look for the object MessageBoxMx.Show("You must select the folder in which " + ObjectName.Text + " is to be found!", "Which Folder?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DialogResult = DialogResult.None; return; } else { // have a folder, look for entered name string folderTarget = folderNode.Target; if (!UserObjectTree.FolderNodes.ContainsKey(folderTarget)) { MessageBoxMx.ShowError("Unexpected error - Failed to find folder: " + folderTarget); return; } MetaTreeNode mtn = UserObjectTree.FolderNodes[folderTarget]; MetaTreeNodeType mtnType = UserObjectTree.UserObjectTypeToMetaTreeNodeType(UoType); mtn = UserObjectTree.GetNodeByLabel(mtn, mtnType, ObjectName.Text); if (mtn != null) { UserObject.ParseObjectTypeAndIdFromInternalName(mtn.Target, out type, out id); OpenUoInfo = UserObjectDao.ReadHeader(id); DialogResult = DialogResult.OK; } else { string msg = ObjectName.Text + "\n" + "File not found.\n" + "Please verify that the correct name was given."; MessageBoxMx.Show(msg, Instance.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DialogResult = DialogResult.None; return; } } } }
/// <summary> /// Be sure that the specified internal object matches the read permissions of the supplied user object /// </summary> /// <param name="uoId"></param> /// <param name="acl"></param> /// <param name="internalObjectNameToMatch"></param> /// <returns></returns> public static bool AssignMatchingReadAccess( int uoId, AccessControlList acl, string internalObjectNameToMatch) { AccessControlList acl2; UserObjectType uoType; int uoId2; if (!acl.IsShared) { return(false); // source object not shared } string objName = internalObjectNameToMatch; if (!UserObject.ParseObjectTypeAndIdFromInternalName(objName, out uoType, out uoId2)) { DebugLog.Message("Can't parse object name: " + objName); return(false); } UserObject uo2 = UserObjectDao.ReadHeader(uoId2); if (uo2 == null) { DebugLog.Message("Can't read object: " + internalObjectNameToMatch + ", " + uoId2); return(false); } acl2 = AccessControlList.Deserialize(uo2); if (acl.IsPublic) { if (acl2.IsPublic) { return(false); } } // check if list of readers matches bool modified = false; foreach (AclItem item in acl.Items) { if (!item.ReadIsAllowed) { continue; } PermissionEnum permissions = acl2.GetUserPermissions(item.AssignedTo); // get permissions for corresponding user/group for obj2 if (!Permissions.ReadIsAllowed(permissions)) // add read if doesn't have { if (item.IsPublic) { acl2.AddPublicReadItem(); } else { acl2.AddReadUserItem(item.AssignedTo); } modified = true; } } if (modified) // update in db if modified { DebugLog.Message("AssignMatchingReadAccess: " + uoId + ", " + objName); // debug acl2.Serialize(uo2); UserObjectDao.UpdateHeader(uo2, false, false); return(true); } else { return(false); } }
/// <summary> /// Read current list object header /// </summary> /// <returns></returns> public static UserObject ReadCurrentListHeader() { return(UserObjectDao.ReadHeader(UserObjectType.CnList, SS.I.UserName, UserObject.TempFolderName, "Current")); }