From eb8c8796055e5a255923c6dd8187d25c0523ad31 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Thu, 5 Feb 2015 06:44:31 -0800 Subject: [PATCH] webdav portal owa fixes --- .../Managers/WebDavManager.cs | 2 + .../App_Start/RouteConfig.cs | 18 ++++++-- .../Controllers/Api/OwaController.cs | 4 +- .../Controllers/FileSystemController.cs | 41 +++++++++++-------- .../UI/Routes/FileSystemRouteNames.cs | 5 ++- .../Views/FileSystem/_ResoursePartial.cshtml | 2 +- 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs index 7a29d642..93d17679 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs @@ -190,6 +190,8 @@ namespace WebsitePanel.WebDav.Core.Managers public void DeleteResource(string path) { path = RemoveLeadingFromPath(path, "office365"); + path = RemoveLeadingFromPath(path, "view"); + path = RemoveLeadingFromPath(path, "edit"); path = RemoveLeadingFromPath(path, WspContext.User.OrganizationId); string folderPath = GetFileFolder(path); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs index f089cdbd..8e4c1bf8 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs @@ -45,11 +45,23 @@ namespace WebsitePanel.WebDavPortal ); routes.MapRoute( - name: FileSystemRouteNames.ShowOfficeOnlinePath, - url: "office365/{org}/{*pathPart}", - defaults: new { controller = "FileSystem", action = "ShowOfficeDocument", pathPart = UrlParameter.Optional } + name: FileSystemRouteNames.ViewOfficeOnline, + url: "office365/view/{org}/{*pathPart}", + defaults: new { controller = "FileSystem", action = "ViewOfficeDocument", pathPart = UrlParameter.Optional } ); + routes.MapRoute( + name: FileSystemRouteNames.EditOfficeOnline, + url: "office365/edit/{org}/{*pathPart}", + defaults: new { controller = "FileSystem", action = "EditOfficeDocument", pathPart = UrlParameter.Optional } + ); + + //routes.MapRoute( + // name: FileSystemRouteNames.ShowOfficeOnlinePath, + // url: "office365/{org}/{*pathPart}", + // defaults: new { controller = "FileSystem", action = "ShowOfficeDocument", pathPart = UrlParameter.Optional } + // ); + routes.MapRoute( name: FileSystemRouteNames.ShowAdditionalContent, url: "show-additional-content/{*path}", diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs index 03ab8cd7..950be3f9 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs @@ -177,8 +177,8 @@ namespace WebsitePanel.WebDavPortal.Controllers.Api var newToken = _tokenManager.CreateToken(WspContext.User,newFilePath); - var readUrlPart = Url.Route(FileSystemRouteNames.ShowOfficeOnlinePath, new { org = WspContext.User.OrganizationId, pathPart = newFilePath, fileAccess = FileAccess.Read }); - var writeUrlPart = Url.Route(FileSystemRouteNames.ShowOfficeOnlinePath, new { org = WspContext.User.OrganizationId, pathPart = newFilePath, fileAccess = FileAccess.Write }); + var readUrlPart = Url.Route(FileSystemRouteNames.ViewOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath}); + var writeUrlPart = Url.Route(FileSystemRouteNames.EditOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath }); result.HostEditUrl = new Uri(Request.RequestUri, writeUrlPart).ToString(); result.HostViewUrl = new Uri(Request.RequestUri, readUrlPart).ToString(); ; diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs index 7f3e9600..4b4cf1c2 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Mime; +using System.Security.Policy; using System.Web; using System.Web.Mvc; using System.Web.Routing; @@ -83,12 +84,8 @@ namespace WebsitePanel.WebDavPortal.Controllers } } - public ActionResult ShowOfficeDocument(string org, string pathPart = "", FileAccess? fileAccess = null) + public ActionResult ShowOfficeDocument(string org, string pathPart, string owaOpenerUri) { - var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, pathPart); - - var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart)); - string fileUrl = WebDavAppConfigManager.Instance.WebdavRoot+ org + "/" + pathPart.TrimStart('/'); var accessToken = _tokenManager.CreateToken(WspContext.User, pathPart); @@ -97,22 +94,32 @@ namespace WebsitePanel.WebDavPortal.Controllers string wopiSrc = Server.UrlDecode(url); - string owaOpenerUri = string.Empty; - - if (fileAccess == null) - { - owaOpenerUri = permissions.HasFlag(WebDavPermissions.Write) ? owaOpener.OwaEditor : owaOpener.OwaView; - } - else - { - owaOpenerUri = permissions.HasFlag(WebDavPermissions.Write) && fileAccess == FileAccess.Write ? owaOpener.OwaEditor : owaOpener.OwaView; - } - var uri = string.Format("{0}/{1}WOPISrc={2}&access_token={3}", WebDavAppConfigManager.Instance.OfficeOnline.Url, owaOpenerUri, Server.UrlEncode(wopiSrc), Server.UrlEncode(accessToken.AccessToken.ToString("N"))); string fileName = fileUrl.Split('/').Last(); - return View(new OfficeOnlineModel(uri, fileName)); + return View("ShowOfficeDocument", new OfficeOnlineModel(uri, fileName)); + } + + public ActionResult ViewOfficeDocument(string org, string pathPart) + { + var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart)); + + return ShowOfficeDocument(org, pathPart, owaOpener.OwaView); + } + + public ActionResult EditOfficeDocument(string org, string pathPart) + { + var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, pathPart); + + if (permissions.HasFlag(WebDavPermissions.Write) == false) + { + return new RedirectToRouteResult(FileSystemRouteNames.ViewOfficeOnline, null); + } + + var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart)); + + return ShowOfficeDocument(org, pathPart, owaOpener.OwaEditor); } [HttpPost] diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs index 69e435ca..78426d31 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs @@ -8,7 +8,10 @@ namespace WebsitePanel.WebDavPortal.UI.Routes public class FileSystemRouteNames { public const string ShowContentPath = "ShowContentRoute"; - public const string ShowOfficeOnlinePath = "ShowOfficeOnlineRoute"; + public const string ShowOfficeOnlinePath_ = "ShowOfficeOnlineRoute"; + public const string ViewOfficeOnline = "ViewOfficeOnlineRoute"; + public const string EditOfficeOnline = "EditOfficeOnlineRoute"; + public const string ShowAdditionalContent = "ShowAdditionalContentRoute"; public const string UploadFile = "UplaodFIleRoute"; diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml index d4085c01..855971aa 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml @@ -18,7 +18,7 @@ case FileOpenerType.OfficeOnline: isTargetBlank = true; var pathPart = Model.Href.AbsolutePath.Replace("/" + WspContext.User.OrganizationId, "").TrimStart('/'); - href = string.Concat(Url.RouteUrl(FileSystemRouteNames.ShowOfficeOnlinePath, new { org = WspContext.User.OrganizationId, pathPart = "" }), pathPart); + href = string.Concat(Url.RouteUrl(FileSystemRouteNames.EditOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = "" }), pathPart); break; default: isTargetBlank = false;