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); }
void Setup(UserObject uo) { Text = "Permissions for " + uo.Name; Uo = uo; if (UserObjectUtil.UserHasWriteAccess(uo)) { Editable = true; PermissionsList.Editable = true; MakePublic.Enabled = MakePrivate.Enabled = AdvancedButton.Enabled = true; } else { Editable = false; PermissionsList.Editable = false; MakePublic.Enabled = MakePrivate.Enabled = AdvancedButton.Enabled = false; } AccessControlList acl = AccessControlList.Deserialize(uo); PermissionsList.Setup(acl); return; }
/// <summary> /// See if current user can modify supplied annotation table or calc field /// </summary> /// <param name="mt"></param> /// <returns></returns> public static bool CanModifyTable( MetaTable mt) { if (mt.MetaBrokerType == MetaBrokerType.Unknown) { return(true); // Allow if no broker type (i.e. Transient Conditional Formatting control, etc) } else if (mt.MetaBrokerType == MetaBrokerType.Annotation || mt.MetaBrokerType == MetaBrokerType.CalcField) { if (mt.Code == null || mt.Code == "" || mt.Code == "0") { return(true); // assume ok if new object with no code assigned } return(UserObjectUtil.UserHasWriteAccess(SS.I.UserName, Int32.Parse(mt.Code))); // the code for the table is the object id } else if (mt.IsUserDatabaseStructureTable) { if (mt.Code == null || mt.Code == "" || mt.Code == "0") { return(true); // assume ok if new object with no code assigned } long databaseId = Int64.Parse(mt.Code); UserCmpndDbDao udbs = new UserCmpndDbDao(); return(udbs.CanModifyDatabase(databaseId, SS.I.UserName)); } else { return(false); } }
/// <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> /// 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); }
/// <summary> /// Save/SaveAs the list /// </summary> /// <param name="saveAs">SaveAs under another list name</param> /// <param name="saveAsTempList">Save as a temp list</param> /// <param name="tempListName">Temp list name to save under, prompt if null</param> /// <returns></returns> bool Save( bool saveAs, bool saveAsTempList, string tempListName) { if (!ValidateList()) { return(false); // Validate the list if requested } // Get list name if needed & check that user can modify it if (saveAs || CidList.UserObject.Id == 0) { CidList.UserObject.Id = 0; // assign new id if (saveAsTempList) { if (tempListName == null) // prompt for name { tempListName = CidListCommand.PromptForNewTempListName(); if (tempListName == null) { return(false); } } CidList.UserObject = new UserObject(UserObjectType.CnList); CidList.UserObject.ParentFolder = UserObject.TempFolderName; CidList.UserObject.Name = tempListName; CidList.UserObject.Owner = SS.I.UserName; } else // save as permanent list { UserObject existingUo = CidList.UserObject; if (CidList.UserObject.Id == 0) { existingUo = new UserObject(UserObjectType.CnList); } UserObject listUo = UserObjectSaveDialog.Show("Save As", existingUo); if (listUo == null) { return(false); } CidList.UserObject = listUo; } } if (!UserObjectUtil.UserHasWriteAccess(CidList.UserObject)) { // is the user authorized to save this list? MessageBoxMx.ShowError("You are not authorized to save this list"); return(false); } // Write out the list DisplayStatusMsg("Saving list..."); if (CidList.UserObject.HasDefinedParentFolder) { MetaTreeNode targetFolder = UserObjectTree.GetValidUserObjectTypeFolder(CidList.UserObject); if (targetFolder == null) { // shouldn't happen MessageBoxMx.ShowError("The list could not be saved because the folder it was in no longer exists. Please try SaveAs instead."); return(false); } } GetNormalizedListFromControl(CidList); if (!CidList.UserObject.IsCurrentObject) // normal list? { CidListCommand.Write(CidList); } else // special processing for current list { SessionManager.LockResultsKeys = true; // avoid possible overwrite of ResultsKeys if in single step query int rc = CidListCommand.Write(CidList); List <string> curListString = CidListCommand.ReadCurrentListLocal().ToStringList(); SessionManager.CurrentResultKeys = curListString; SessionManager.DisplayCurrentCount(); SessionManager.LockResultsKeys = false; } //string cFile = SS.I.ClientDefaultDir + @"\Previous.lst" //if (UIMisc.CanWriteFileToDefaultDir(cFile)) //{ // StreamWriter sw = new StreamWriter(cFile); // save copy to disk // sw.Write(CidList.UserObject.Content); // sw.Close(); //} int cncnt = CidList.Count; DisplayStatusMsg("List saved"); Before = CidListCtl.Text; string tok = UserObjectUtil.GetName(ListName); Text = "Edit List - [" + CidList.UserObject.Name + "]"; return(true); }