/// <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> /// 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> /// Save the changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OkButton_Click(object sender, EventArgs e) { if (!Editable) { DialogResult = DialogResult.OK; return; } AccessControlList acl = PermissionsList.GetAcl(); acl.AddReadWriteUserItem(SS.I.UserName); // be sure owner is included if (acl.IsPrivate) { Uo.AccessLevel = UserObjectAccess.Private; Uo.ACL = ""; } else if (acl.IsPublic) { Uo.AccessLevel = UserObjectAccess.Public; Uo.ACL = ""; } else { Uo.AccessLevel = UserObjectAccess.ACL; Uo.ACL = acl.Serialize(); } if (Uo.Id > 0) // update header if object exists already { UserObjectDao.UpdateHeader(Uo, false, true); } DialogResult = DialogResult.OK; 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> /// 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 }