public ActionResult SWIAddDashboard(string[] guids) { writeDebug("SWIAddDashboard"); try { checkSWIAuthentication(); if (!CheckAuthentication()) { return(Content(_loginContent)); } if (!WebUser.ManageDashboards) { throw new Exception("No right to add dashboards"); } if (guids != null) { foreach (var guid in guids) { WebUser.Profile.Dashboards.Add(guid); } WebUser.SaveProfile(); } return(Json(new object { })); } catch (Exception ex) { return(HandleSWIException(ex)); } }
public ActionResult SWIRemoveDashboard(string guid) { writeDebug("SWIRemoveDashboard"); try { checkSWIAuthentication(); if (!CheckAuthentication()) { return(Content(_loginContent)); } if (!WebUser.ManageDashboards) { throw new Exception("No right to remove dashboard"); } if (WebUser.Profile.Dashboards.Contains(guid)) { WebUser.Profile.Dashboards.Remove(guid); WebUser.SaveProfile(); } return(Json(new object { })); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Rename a sub-folder in the repository. /// </summary> public ActionResult SWIRenameFolder(string source, string destination) { writeDebug("SWIRenameFolder"); try { SWIFolder folderSource = getFolder(source); SWIFolder folderDest = getFolder(destination); if (folderSource.manage != 2 || folderDest.manage != 2) { throw new Exception("Error: no right to rename this folder"); } if (!Directory.Exists(Path.GetDirectoryName(folderDest.GetFullPath()))) { throw new Exception("Error: create the parent directory first"); } Directory.Move(folderSource.GetFullPath(), folderDest.GetFullPath()); Audit.LogAudit(AuditType.FolderRename, WebUser, folderSource.GetFullPath(), string.Format("Rename to '{0}'", folderDest.GetFullPath())); checkRecentFiles(); WebUser.SaveProfile(); return(Json(new object { }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Set the culture for the logged user. /// </summary> public ActionResult SWISetUserProfile(string culture) { writeDebug("SWISetUserProfile"); try { checkSWIAuthentication(); if (string.IsNullOrEmpty(culture)) { throw new Exception("Error: culture must be supplied"); } if (culture != Repository.CultureInfo.EnglishName) { if (!Repository.SetCultureInfo(culture)) { throw new Exception("Invalid culture name:" + culture); } setCookie(SealCultureCookieName, culture); WebUser.Profile.Culture = culture; } WebUser.SaveProfile(); return(Json(new { })); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Execute a report and returns the report html display result content (e.g. html with prompted restrictions). Check API of Seal Web Interface for more information. /// </summary> public ActionResult SWExecuteReport(string path, string viewGUID, string outputGUID, bool?fromMenu) { writeDebug("SWExecuteReport"); try { if (!CheckAuthentication()) { return(Content(_loginContent)); } Report report = null; Repository repository = null; SWIFolder folder = getParentFolder(path); if (folder.right == 0) { throw new Exception("Error: no right on this folder"); } if (!string.IsNullOrEmpty(outputGUID) && (FolderRight)folder.right == FolderRight.Execute) { throw new Exception("Error: no right to execute output on this folder"); } var file = getFileDetail(path); if (file.right == 0) { throw new Exception("Error: no right on this report or file"); } if (!string.IsNullOrEmpty(outputGUID) && (FolderRight)file.right == FolderRight.Execute) { throw new Exception("Error: no right to execute output on this report"); } string filePath = getFullPath(path); if (!System.IO.File.Exists(filePath)) { throw new Exception("Error: report or file does not exist"); } repository = Repository.CreateFast(); report = Report.LoadFromFile(filePath, repository); report.OnlyBody = (fromMenu != null && fromMenu.Value); var execution = initReportExecution(report, viewGUID, outputGUID, false); execution.RenderHTMLDisplayForViewer(); WebUser.Profile.SetRecentReports(path, report, viewGUID, outputGUID); WebUser.SaveProfile(); if (fromMenu != null && fromMenu.Value) { return(Json(System.IO.File.ReadAllText(report.HTMLDisplayFilePath))); } return(getFileResult(report.HTMLDisplayFilePath, report)); } catch (Exception ex) { return(HandleException(ex)); } }
/// <summary> /// Delete files or reports from the repository. /// </summary> public ActionResult SWIDeleteFiles(string paths) { writeDebug("SWIDeleteFiles"); try { checkSWIAuthentication(); if (string.IsNullOrEmpty(paths)) { throw new Exception("Error: paths must be supplied"); } foreach (var path in paths.Split('\n')) { if (!string.IsNullOrEmpty(path)) { SWIFolder folder = getParentFolder(path); if ((FolderRight)folder.right != FolderRight.Edit) { throw new Exception("Error: no right to edit in this folder"); } var file = getFileDetail(path); if ((FolderRight)file.right != FolderRight.Edit) { throw new Exception("Error: no right to edit this report or file"); } string fullPath = getFullPath(path); if (FileHelper.IsSealReportFile(fullPath) && FileHelper.ReportHasSchedule(fullPath)) { //Delete schedules... var report = Report.LoadFromFile(fullPath, Repository, false); report.Schedules.Clear(); report.SynchronizeTasks(); } FileHelper.DeleteSealFile(fullPath); Audit.LogAudit(AuditType.FileDelete, WebUser, path); checkRecentFiles(); WebUser.SaveProfile(); } } return(Json(new object { }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Set the culture for the logged user. /// </summary> public ActionResult SWISetUserProfile(string culture, string onStartup, string startupReport, string startupReportName) { writeDebug("SWISetUserProfile"); try { checkSWIAuthentication(); if (!WebUser.DefaultGroup.EditProfile) { throw new Exception("No right to change the profile"); } if (string.IsNullOrEmpty(culture)) { WebUser.Profile.Culture = ""; if (!string.IsNullOrEmpty(WebUser.DefaultGroup.Culture)) { Repository.SetCultureInfo(WebUser.DefaultGroup.Culture); } else { Repository.SetCultureInfo(Repository.Instance.CultureInfo.EnglishName); } } else { if (!Repository.SetCultureInfo(culture)) { throw new Exception("Invalid culture name:" + culture); } WebUser.Profile.Culture = culture; } var onStartupVal = StartupOptions.Default; if (Enum.TryParse(onStartup, out onStartupVal)) { WebUser.Profile.OnStartup = onStartupVal; WebUser.Profile.StartUpReport = startupReport; WebUser.Profile.StartupReportName = startupReportName; } WebUser.SaveProfile(); return(Json(new { }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(HandleSWIException(ex)); } }
public ActionResult SWISwapDashboardOrder(string guid1, string guid2) { writeDebug("SWISwapDashboardOrder"); try { checkSWIAuthentication(); if (!WebUser.ManageDashboards) { throw new Exception("No right to swap dashboard"); } if (WebUser.Profile.Dashboards.Contains(guid1) && WebUser.Profile.Dashboards.Contains(guid2)) { var newDashboards = new List <string>(); foreach (var guid in WebUser.Profile.Dashboards) { if (guid == guid1) { newDashboards.Add(guid2); } else if (guid == guid2) { newDashboards.Add(guid1); } else { newDashboards.Add(guid); } } WebUser.Profile.Dashboards = newDashboards; WebUser.SaveProfile(); } return(Json(new object { })); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Set the culture for the logged user. /// </summary> public ActionResult SWISetUserProfile(string culture, string onStartup, string startupReport, string startupReportName) { writeDebug("SWISetUserProfile"); try { checkSWIAuthentication(); if (!WebUser.DefaultGroup.EditProfile) { throw new Exception("Error: no right to change profile"); } if (string.IsNullOrEmpty(culture)) { throw new Exception("Error: culture must be supplied"); } if (culture != Repository.CultureInfo.EnglishName) { if (!Repository.SetCultureInfo(culture)) { throw new Exception("Invalid culture name:" + culture); } WebUser.Profile.Culture = culture; } var onStartupVal = StartupOptions.Default; if (Enum.TryParse(onStartup, out onStartupVal)) { WebUser.Profile.OnStartup = onStartupVal; WebUser.Profile.StartUpReport = startupReport; WebUser.Profile.StartupReportName = startupReportName; } WebUser.SaveProfile(); return(Json(new { })); } catch (Exception ex) { return(HandleSWIException(ex)); } }
/// <summary> /// Move a file or a report in the repository. /// </summary> public ActionResult SWIMoveFile(string source, string destination, bool copy) { writeDebug("SWIMoveFile"); try { SWIFolder folderSource = getParentFolder(source); if (folderSource.right == 0) { throw new Exception("Error: no right on this folder"); } if (!copy && (FolderRight)folderSource.right != FolderRight.Edit) { throw new Exception("Error: no edit right on this folder"); } var file = getFileDetail(source); if (file.right == 0) { throw new Exception("Error: no right on this report or file"); } if (!copy && (FolderRight)file.right != FolderRight.Edit) { throw new Exception("Error: no right to edit this report or file"); } SWIFolder folderDest = getParentFolder(destination); if ((FolderRight)folderDest.right != FolderRight.Edit) { throw new Exception("Error: no right to edit on the destination folder"); } string sourcePath = getFullPath(source); string destinationPath = getFullPath(destination); if (!System.IO.File.Exists(sourcePath)) { throw new Exception("Error: source path is incorrect"); } if (folderDest.files && FileHelper.IsSealReportFile(sourcePath)) { throw new Exception(Translate("Warning: only files (and not reports) can be copied to this folder.")); } if (System.IO.File.Exists(destinationPath) && copy) { destinationPath = FileHelper.GetUniqueFileName(Path.GetDirectoryName(destinationPath), Path.GetFileNameWithoutExtension(destinationPath) + " - Copy" + Path.GetExtension(destinationPath), Path.GetExtension(destinationPath)); } bool hasSchedule = (FileHelper.IsSealReportFile(sourcePath) && FileHelper.ReportHasSchedule(sourcePath)); FileHelper.MoveSealFile(sourcePath, destinationPath, copy); if (copy) { Audit.LogAudit(AuditType.FileCopy, WebUser, sourcePath, string.Format("Copy to '{0}'", destinationPath)); } else { Audit.LogAudit(AuditType.FileMove, WebUser, sourcePath, string.Format("Move to '{0}'", destinationPath)); } if (hasSchedule) { //Re-init schedules... var report = Report.LoadFromFile(destinationPath, Repository, false); if (copy) { //remove schedules report.InitGUIDAndSchedules(); report.SaveToFile(); } report.SchedulesWithCurrentUser = false; report.SynchronizeTasks(); } checkRecentFiles(); WebUser.SaveProfile(); return(Json(new object { }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(HandleSWIException(ex)); } }