webdav portal filter + detail view added
This commit is contained in:
parent
280628e362
commit
51d432fd2e
156 changed files with 32494 additions and 260 deletions
|
@ -8,20 +8,28 @@ using System.Security.Policy;
|
|||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using AutoMapper;
|
||||
using log4net;
|
||||
using WebsitePanel.WebDav.Core;
|
||||
using WebsitePanel.WebDav.Core.Client;
|
||||
using WebsitePanel.WebDav.Core.Config;
|
||||
using WebsitePanel.WebDav.Core.Entities.Account.Enums;
|
||||
using WebsitePanel.WebDav.Core.Exceptions;
|
||||
using WebsitePanel.WebDav.Core.Interfaces.Managers;
|
||||
using WebsitePanel.WebDav.Core.Interfaces.Managers.Users;
|
||||
using WebsitePanel.WebDav.Core.Interfaces.Security;
|
||||
using WebsitePanel.WebDav.Core.Security.Authorization.Enums;
|
||||
using WebsitePanel.WebDav.Core.Security.Cryptography;
|
||||
using WebsitePanel.WebDav.Core.Wsp.Framework;
|
||||
using WebsitePanel.WebDavPortal.CustomAttributes;
|
||||
using WebsitePanel.WebDavPortal.Extensions;
|
||||
using WebsitePanel.WebDavPortal.FileOperations;
|
||||
using WebsitePanel.WebDavPortal.Helpers;
|
||||
using WebsitePanel.WebDavPortal.ModelBinders.DataTables;
|
||||
using WebsitePanel.WebDavPortal.Models;
|
||||
using System.Net;
|
||||
using WebsitePanel.WebDavPortal.Models.Common;
|
||||
using WebsitePanel.WebDavPortal.Models.Common.DataTable;
|
||||
using WebsitePanel.WebDavPortal.Models.Common.Enums;
|
||||
using WebsitePanel.WebDavPortal.Models.FileSystem;
|
||||
using WebsitePanel.WebDavPortal.UI;
|
||||
|
@ -39,19 +47,29 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IAccessTokenManager _tokenManager;
|
||||
private readonly IWebDavAuthorizationService _webDavAuthorizationService;
|
||||
private readonly IUserSettingsManager _userSettingsManager;
|
||||
private readonly ILog Log;
|
||||
|
||||
public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService)
|
||||
public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService, FileOpenerManager openerManager, IUserSettingsManager userSettingsManager)
|
||||
{
|
||||
_cryptography = cryptography;
|
||||
_webdavManager = webdavManager;
|
||||
_authenticationService = authenticationService;
|
||||
_tokenManager = tokenManager;
|
||||
_webDavAuthorizationService = webDavAuthorizationService;
|
||||
_userSettingsManager = userSettingsManager;
|
||||
|
||||
Log = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult ChangeViewType(FolderViewTypes viewType, string org, string pathPart = "")
|
||||
{
|
||||
_userSettingsManager.ChangeWebDavViewType(WspContext.User.AccountId, viewType);
|
||||
|
||||
return RedirectToRoute(FileSystemRouteNames.ShowContentPath, new { org, pathPart });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult ShowContent(string org, string pathPart = "")
|
||||
{
|
||||
|
@ -70,11 +88,12 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
try
|
||||
{
|
||||
IEnumerable<IHierarchyItem> children = _webdavManager.OpenFolder(pathPart);
|
||||
|
||||
var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, pathPart);
|
||||
|
||||
var model = new ModelForWebDav { Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount), UrlSuffix = pathPart, Permissions = permissions};
|
||||
var model = new ModelForWebDav
|
||||
{
|
||||
UrlSuffix = pathPart,
|
||||
Permissions =_webDavAuthorizationService.GetPermissions(WspContext.User, pathPart),
|
||||
UserSettings = _userSettingsManager.GetUserSettings(WspContext.User.AccountId)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
@ -84,42 +103,46 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
public ActionResult ShowOfficeDocument(string org, string pathPart, string owaOpenerUri)
|
||||
[ChildActionOnly]
|
||||
public ActionResult ContentList(string org, FolderViewTypes viewType, string pathPart = "")
|
||||
{
|
||||
string fileUrl = WebDavAppConfigManager.Instance.WebdavRoot+ org + "/" + pathPart.TrimStart('/');
|
||||
var accessToken = _tokenManager.CreateToken(WspContext.User, pathPart);
|
||||
|
||||
var urlPart = Url.HttpRouteUrl(OwaRouteNames.CheckFileInfo, new {accessTokenId = accessToken.Id});
|
||||
var url = new Uri(Request.Url, urlPart).ToString();
|
||||
|
||||
string wopiSrc = Server.UrlDecode(url);
|
||||
|
||||
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("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)
|
||||
try
|
||||
{
|
||||
return new RedirectToRouteResult(FileSystemRouteNames.ViewOfficeOnline, null);
|
||||
IEnumerable<IHierarchyItem> children = _webdavManager.OpenFolder(pathPart);
|
||||
|
||||
var model = new ModelForWebDav
|
||||
{
|
||||
UrlSuffix = pathPart,
|
||||
Permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, pathPart),
|
||||
UserSettings = _userSettingsManager.GetUserSettings(WspContext.User.AccountId)
|
||||
};
|
||||
|
||||
if (Request.Browser.IsMobileDevice == false && model.UserSettings.WebDavViewType == FolderViewTypes.Table)
|
||||
{
|
||||
return View("_ShowContentTable", model);
|
||||
}
|
||||
|
||||
model.Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount);
|
||||
|
||||
return View("_ShowContentBigIcons", model);
|
||||
}
|
||||
catch (UnauthorizedException e)
|
||||
{
|
||||
throw new HttpException(404, "Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart));
|
||||
|
||||
return ShowOfficeDocument(org, pathPart, owaOpener.OwaEditor);
|
||||
[HttpGet]
|
||||
public ActionResult GetContentDetails(string org, string pathPart, [ModelBinder(typeof (JqueryDataTableModelBinder))] JqueryDataTableRequest dtRequest)
|
||||
{
|
||||
var folderItems = _webdavManager.OpenFolder(pathPart);
|
||||
|
||||
var tableItems = Mapper.Map<IEnumerable<IHierarchyItem>, IEnumerable<ResourceTableItemModel>>(folderItems).ToList();
|
||||
|
||||
var dataTableResponse = DataTableHelper.ProcessRequest(tableItems, dtRequest);
|
||||
|
||||
return Json(dataTableResponse, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -146,7 +169,7 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
if (_webdavManager.IsFile(pathPart) == false)
|
||||
{
|
||||
throw new Exception(Resources.NotAFile);
|
||||
throw new Exception(Resources.UI.NotAFile);
|
||||
}
|
||||
|
||||
var fileBytes = _webdavManager.GetFileBytes(pathPart);
|
||||
|
@ -179,7 +202,7 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
if (filePathes == null)
|
||||
{
|
||||
model.AddMessage(MessageType.Error, Resources.NoFilesAreSelected);
|
||||
model.AddMessage(MessageType.Error, Resources.UI.NoFilesAreSelected);
|
||||
|
||||
return Json(model);
|
||||
}
|
||||
|
@ -200,10 +223,52 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
if (model.DeletedFiles.Any())
|
||||
{
|
||||
model.AddMessage(MessageType.Success, string.Format(Resources.ItemsWasRemovedFormat, model.DeletedFiles.Count));
|
||||
model.AddMessage(MessageType.Success, string.Format(Resources.UI.ItemsWasRemovedFormat, model.DeletedFiles.Count));
|
||||
}
|
||||
|
||||
return Json(model);
|
||||
}
|
||||
|
||||
#region Owa Actions
|
||||
|
||||
public ActionResult ShowOfficeDocument(string org, string pathPart, string owaOpenerUri)
|
||||
{
|
||||
string fileUrl = WebDavAppConfigManager.Instance.WebdavRoot + org + "/" + pathPart.TrimStart('/');
|
||||
var accessToken = _tokenManager.CreateToken(WspContext.User, pathPart);
|
||||
|
||||
var urlPart = Url.HttpRouteUrl(OwaRouteNames.CheckFileInfo, new { accessTokenId = accessToken.Id });
|
||||
var url = new Uri(Request.Url, urlPart).ToString();
|
||||
|
||||
string wopiSrc = Server.UrlDecode(url);
|
||||
|
||||
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("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);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue