diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs index acebf9ac..94f7348f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs @@ -59,7 +59,10 @@ namespace WebsitePanel.WebDav.Core { get { - string displayName = _href.AbsoluteUri.Replace(_baseUri.AbsoluteUri, ""); + var href = HttpUtility.UrlDecode(_href.AbsoluteUri); + var baseUri = HttpUtility.UrlDecode(_baseUri.AbsoluteUri); + + string displayName = href.Replace(baseUri, ""); displayName = Regex.Replace(displayName, "\\/$", ""); Match displayNameMatch = Regex.Match(displayName, "([\\/]+)$"); if (displayNameMatch.Success) diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs index c7b92062..65491262 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs @@ -1,5 +1,6 @@ using System.Web.Mvc; using System.Web.Routing; +using WebsitePanel.WebDavPortal.UI.Routes; namespace WebsitePanel.WebDavPortal { @@ -9,6 +10,22 @@ namespace WebsitePanel.WebDavPortal { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + #region Account + + routes.MapRoute( + name: AccountRouteNames.Logout, + url: "account/logout", + defaults: new { controller = "Account", action = "Logout" } + ); + + routes.MapRoute( + name: AccountRouteNames.Login, + url: "account/login", + defaults: new { controller = "Account", action = "Login" } + ); + + #endregion + routes.MapRoute( name: "Office365DocumentRoute", url: "office365/{org}/{*pathPart}", @@ -16,7 +33,7 @@ namespace WebsitePanel.WebDavPortal ); routes.MapRoute( - name: "FilePathRoute", + name: FileSystemRouteNames.FilePath, url: "{org}/{*pathPart}", defaults: new { controller = "FileSystem", action = "ShowContent", pathPart = UrlParameter.Optional }, constraints: new { org = new WebsitePanel.WebDavPortal.Constraints.OrganizationRouteConstraint() } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Config/Entities/ElementsRendering.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Config/Entities/ElementsRendering.cs index 04a1105d..c5703a8a 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Config/Entities/ElementsRendering.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Config/Entities/ElementsRendering.cs @@ -1,14 +1,19 @@ -namespace WebsitePanel.WebDavPortal.Config.Entities +using System.Collections.Generic; +using System.Linq; + +namespace WebsitePanel.WebDavPortal.Config.Entities { public class ElementsRendering : AbstractConfigCollection { public int DefaultCount { get; private set; } public int AddElementsCount { get; private set; } + public List ElementsToIgnore { get; private set; } public ElementsRendering() { DefaultCount = ConfigSection.ElementsRendering.DefaultCount; AddElementsCount = ConfigSection.ElementsRendering.AddElementsCount; + ElementsToIgnore = ConfigSection.ElementsRendering.ElementsToIgnore.Split(',').ToList(); } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Constraints/OrganizationRouteConstraint.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Constraints/OrganizationRouteConstraint.cs index 95e95750..65165a0c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Constraints/OrganizationRouteConstraint.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Constraints/OrganizationRouteConstraint.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Web; +using System.Web.Mvc; using System.Web.Routing; using WebsitePanel.WebDavPortal.Config; using WebsitePanel.WebDavPortal.DependencyInjection; @@ -16,6 +17,8 @@ namespace WebsitePanel.WebDavPortal.Constraints public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { + var webdavManager = DependencyResolver.Current.GetService(); + object value; if (!values.TryGetValue(parameterName, out value)) return false; @@ -30,9 +33,7 @@ namespace WebsitePanel.WebDavPortal.Constraints if (httpContext.Session == null) return false; - IKernel kernel = new StandardKernel(new WebDavExplorerAppModule()); - var webDavManager = kernel.Get(); - if (webDavManager != null && str == webDavManager.OrganizationName) + if (webdavManager != null && str == webdavManager.OrganizationName) { actualOrgName = str; return true; diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css index 20e5c6b1..2389aea4 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css @@ -32,4 +32,17 @@ textarea { color: red; font-weight: bold; padding-top: 5px; - } \ No newline at end of file + } + +#username { + display:inline-block; +} + +#logout { + font-size: 1.2em; + color: #9d9d9d; +} + +#logout :hover { + color: white; +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs index 242cd617..a6d39fd8 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs @@ -22,18 +22,27 @@ using WebsitePanel.WebDavPortal.Models; using System.Collections.Generic; using WebsitePanel.Providers.OS; using WebDAV; +using WebsitePanel.WebDavPortal.UI.Routes; namespace WebsitePanel.WebDavPortal.Controllers { public class AccountController : Controller { - private readonly IKernel _kernel = new StandardKernel(new NinjectSettings {AllowNullInjection = true}, new WebDavExplorerAppModule()); + private readonly AccountModel _accountModel; + private readonly IWebDavManager _webdavManager; + private readonly ICryptography _cryptography; + + public AccountController(AccountModel accountModel, IWebDavManager webdavManager, ICryptography cryptography) + { + _accountModel = accountModel; + _webdavManager = webdavManager; + _cryptography = cryptography; + } [HttpGet] public ActionResult Login() { - object isAuthentication = _kernel.Get(); - if (isAuthentication != null) + if (_accountModel != null) return RedirectToAction("ShowContent", "FileSystem"); return View(); } @@ -50,32 +59,53 @@ namespace WebsitePanel.WebDavPortal.Controllers if (isAuthenticated) { Session[WebDavAppConfigManager.Instance.SessionKeys.ItemId] = exchangeAccount.ItemId; - + + model.Groups = ES.Services.Organizations.GetSecurityGroupsByMember(exchangeAccount.ItemId, exchangeAccount.AccountId); + model.DisplayName = exchangeAccount.DisplayName; + + WebDavManager manager = null; + try { Session[WebDavAppConfigManager.Instance.SessionKeys.AccountInfo] = model; - Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = new WebDavManager(new NetworkCredential(model.Login, model.Password, WebDavAppConfigManager.Instance.UserDomain), exchangeAccount.ItemId); + + manager = new WebDavManager(new NetworkCredential(model.Login, model.Password, WebDavAppConfigManager.Instance.UserDomain), exchangeAccount.ItemId); + + Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = manager; } catch (ConnectToWebDavServerException exception) { return View(new AccountModel { LdapError = exception.Message }); } - return RedirectToAction("ShowContent", "FileSystem", new { org = _kernel.Get().OrganizationName }); + + return RedirectToAction("ShowContent", "FileSystem", new { org = manager.OrganizationName }); } return View(new AccountModel { LdapError = "The user name or password is incorrect" }); } + [HttpGet] + public ActionResult Logout() + { + Session[WebDavAppConfigManager.Instance.SessionKeys.AccountInfo] = null; + + return RedirectToRoute(AccountRouteNames.Login); + } + private void AutheticationToServicesUsingWebsitePanelUser() { - var crypto = _kernel.Get(); var websitePanelLogin = WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Login; - var websitePanelPassword = crypto.Decrypt(WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Password); + var websitePanelPassword = _cryptography.Decrypt(WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Password); + var authTicket = new FormsAuthenticationTicket(1, websitePanelLogin, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), FormsAuthentication.SlidingExpiration, websitePanelPassword + Environment.NewLine); var encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); + if (FormsAuthentication.SlidingExpiration) + { authCookie.Expires = authTicket.Expiration; + } + Response.Cookies.Add(authCookie); } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs index c8d77ab4..81a54ce1 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs @@ -22,26 +22,31 @@ namespace WebsitePanel.WebDavPortal.Controllers [LdapAuthorization] public class FileSystemController : Controller { - private readonly IKernel _kernel = new StandardKernel(new WebDavExplorerAppModule()); + private readonly IWebDavManager _webdavManager; + + public FileSystemController(IWebDavManager webdavManager) + { + _webdavManager = webdavManager; + } [HttpGet] public ActionResult ShowContent(string org, string pathPart = "") { - var webDavManager = new StandardKernel(new WebDavExplorerAppModule()).Get(); - if (org != webDavManager.OrganizationName) + if (org != _webdavManager.OrganizationName) return new HttpStatusCodeResult(HttpStatusCode.NoContent); string fileName = pathPart.Split('/').Last(); - if (webDavManager.IsFile(fileName)) + if (_webdavManager.IsFile(fileName)) { - var fileBytes = webDavManager.GetFileBytes(fileName); + var fileBytes = _webdavManager.GetFileBytes(fileName); return File(fileBytes, MediaTypeNames.Application.Octet, fileName); } try { - webDavManager.OpenFolder(pathPart); - IEnumerable children = webDavManager.GetChildren(); + _webdavManager.OpenFolder(pathPart); + IEnumerable children = _webdavManager.GetChildren().Where(x => !WebDavAppConfigManager.Instance.ElementsRendering.ElementsToIgnore.Contains(x.DisplayName.Trim('/'))); + var model = new ModelForWebDav { Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount), UrlSuffix = pathPart }; Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] = WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount; @@ -55,8 +60,7 @@ namespace WebsitePanel.WebDavPortal.Controllers public ActionResult ShowOfficeDocument(string org, string pathPart = "") { - var webDavManager = _kernel.Get(); - string fileUrl = webDavManager.RootPath.TrimEnd('/') + "/" + pathPart.TrimStart('/'); + string fileUrl = _webdavManager.RootPath.TrimEnd('/') + "/" + pathPart.TrimStart('/'); var uri = new Uri(WebDavAppConfigManager.Instance.OfficeOnline.Url).AddParameter("src", fileUrl).ToString(); return View(new OfficeOnlineModel(uri, new Uri(fileUrl).Segments.Last())); @@ -68,9 +72,11 @@ namespace WebsitePanel.WebDavPortal.Controllers if (Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] != null) { var renderedElementsCount = (int)Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount]; - var webDavManager = _kernel.Get(); - IEnumerable children = webDavManager.GetChildren(); + + IEnumerable children = _webdavManager.GetChildren(); + var result = children.Skip(renderedElementsCount).Take(WebDavAppConfigManager.Instance.ElementsRendering.AddElementsCount); + Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] = renderedElementsCount + WebDavAppConfigManager.Instance.ElementsRendering.AddElementsCount; return PartialView("_ResourseCollectionPartial", result); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/CustomAttributes/LdapAuthorizationAttribute.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/CustomAttributes/LdapAuthorizationAttribute.cs index 3d51c373..69d87efc 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/CustomAttributes/LdapAuthorizationAttribute.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/CustomAttributes/LdapAuthorizationAttribute.cs @@ -4,6 +4,7 @@ using System.Web.Routing; using Ninject; using WebsitePanel.WebDavPortal.DependencyInjection; using WebsitePanel.WebDavPortal.Models; +using WebsitePanel.WebDavPortal.UI.Routes; namespace WebsitePanel.WebDavPortal.CustomAttributes { @@ -11,16 +12,19 @@ namespace WebsitePanel.WebDavPortal.CustomAttributes { protected override bool AuthorizeCore(HttpContextBase httpContext) { - IKernel kernel = new StandardKernel(new NinjectSettings { AllowNullInjection = true }, new WebDavExplorerAppModule()); - var accountInfo = kernel.Get(); + var accountInfo = DependencyResolver.Current.GetService(); + if (accountInfo == null) + { return false; + } + return true; } protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { - filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Login" })); + filterContext.Result = new RedirectToRouteResult(AccountRouteNames.Login, null); } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/NinjectDependecyResolver.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/NinjectDependecyResolver.cs new file mode 100644 index 00000000..480cb19e --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/NinjectDependecyResolver.cs @@ -0,0 +1,35 @@ +using Ninject; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace WebsitePanel.WebDavPortal.DependencyInjection +{ + public class NinjectDependecyResolver : IDependencyResolver + { + IKernel kernal; + + public NinjectDependecyResolver() + { + kernal = new StandardKernel(new NinjectSettings { AllowNullInjection = true }); + AddBindings(); + } + + public object GetService(Type serviceType) + { + return kernal.TryGet(serviceType); + } + + public IEnumerable GetServices(Type serviceType) + { + return kernal.GetAll(serviceType); + } + + private void AddBindings() + { + PortalDependencies.Configure(kernal); + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs new file mode 100644 index 00000000..be866fab --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs @@ -0,0 +1,23 @@ +using Ninject; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.SessionState; +using WebsitePanel.WebDavPortal.Cryptography; +using WebsitePanel.WebDavPortal.DependencyInjection.Providers; +using WebsitePanel.WebDavPortal.Models; + +namespace WebsitePanel.WebDavPortal.DependencyInjection +{ + public class PortalDependencies + { + public static void Configure(IKernel kernerl) + { + kernerl.Bind().ToProvider(); + kernerl.Bind().ToProvider(); + kernerl.Bind().ToProvider(); + kernerl.Bind().To(); + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/AccountInfoProvider.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/AccountInfoProvider.cs similarity index 64% rename from WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/AccountInfoProvider.cs rename to WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/AccountInfoProvider.cs index 1781b8bb..6a2f8dc0 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/AccountInfoProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/AccountInfoProvider.cs @@ -4,7 +4,7 @@ using Ninject.Activation; using WebsitePanel.WebDavPortal.Config; using WebsitePanel.WebDavPortal.Models; -namespace WebsitePanel.WebDavPortal.DependencyInjection +namespace WebsitePanel.WebDavPortal.DependencyInjection.Providers { public class AccountInfoProvider : Provider { @@ -12,7 +12,13 @@ namespace WebsitePanel.WebDavPortal.DependencyInjection { var session = context.Kernel.Get(); - var accountInfo = session[WebDavAppConfigManager.Instance.SessionKeys.AccountInfo] as AccountModel; + AccountModel accountInfo = null; + + if (session != null) + { + accountInfo = session[WebDavAppConfigManager.Instance.SessionKeys.AccountInfo] as AccountModel; + } + return accountInfo; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/HttpSessionStateProvider.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/HttpSessionStateProvider.cs new file mode 100644 index 00000000..738312bf --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/HttpSessionStateProvider.cs @@ -0,0 +1,17 @@ +using Ninject.Activation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.SessionState; + +namespace WebsitePanel.WebDavPortal.DependencyInjection.Providers +{ + public class HttpSessionStateProvider : Provider + { + protected override HttpSessionState CreateInstance(IContext context) + { + return HttpContext.Current.Session; + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavManagerProvider.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/WebDavManagerProvider.cs similarity index 64% rename from WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavManagerProvider.cs rename to WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/WebDavManagerProvider.cs index 7dd6df04..b52d83a3 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavManagerProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/Providers/WebDavManagerProvider.cs @@ -4,7 +4,7 @@ using Ninject.Activation; using WebsitePanel.WebDavPortal.Config; using WebsitePanel.WebDavPortal.Models; -namespace WebsitePanel.WebDavPortal.DependencyInjection +namespace WebsitePanel.WebDavPortal.DependencyInjection.Providers { public class WebDavManagerProvider : Provider { @@ -12,7 +12,13 @@ namespace WebsitePanel.WebDavPortal.DependencyInjection { var session = context.Kernel.Get(); - var webDavManager = session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] as WebDavManager; + WebDavManager webDavManager = null; + + if (session != null) + { + webDavManager = session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] as WebDavManager; + } + return webDavManager; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavExplorerAppModule.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavExplorerAppModule.cs deleted file mode 100644 index 0029f886..00000000 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/WebDavExplorerAppModule.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Web; -using System.Web.SessionState; -using Ninject.Modules; -using WebsitePanel.WebDavPortal.Cryptography; -using WebsitePanel.WebDavPortal.Models; - -namespace WebsitePanel.WebDavPortal.DependencyInjection -{ - public class WebDavExplorerAppModule : NinjectModule - { - public override void Load() - { - Bind().ToConstant(HttpContext.Current.Session); - Bind().ToProvider(); - Bind().ToProvider(); - Bind().To(); - } - } -} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Global.asax.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Global.asax.cs index 69fb92f6..e56e596a 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Global.asax.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Global.asax.cs @@ -4,6 +4,7 @@ using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using WebsitePanel.WebDavPortal.Controllers; +using WebsitePanel.WebDavPortal.DependencyInjection; namespace WebsitePanel.WebDavPortal { @@ -15,6 +16,10 @@ namespace WebsitePanel.WebDavPortal FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); + + DependencyResolver.SetResolver(new NinjectDependecyResolver()); + + log4net.Config.XmlConfigurator.Configure(); } protected void Application_Error(object sender, EventArgs e) diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs index 72956e73..b5b778d1 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs @@ -1,4 +1,6 @@ -using System.ComponentModel.DataAnnotations; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using WebsitePanel.Providers.HostedSolution; namespace WebsitePanel.WebDavPortal.Models { @@ -21,6 +23,10 @@ namespace WebsitePanel.WebDavPortal.Models } } + public string DisplayName { get; set; } + + public IEnumerable Groups { get; set; } + public string LdapError { get; set; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/WebDavManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/WebDavManager.cs index 05f578d8..c021050b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/WebDavManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/WebDavManager.cs @@ -11,12 +11,18 @@ using WebsitePanel.Portal; using WebsitePanel.Providers.OS; using Ninject; using WebsitePanel.WebDavPortal.DependencyInjection; +using System.Web.Mvc; +using log4net; namespace WebsitePanel.WebDavPortal.Models { public class WebDavManager : IWebDavManager { private readonly WebDavSession _webDavSession = new WebDavSession(); + + private readonly AccountModel _accountModel; + private readonly ILog Log; + private IList _rootFolders; private int _itemId; private IFolder _currentFolder; @@ -36,11 +42,12 @@ namespace WebsitePanel.WebDavPortal.Models public WebDavManager(NetworkCredential credential, int itemId) { + _accountModel = DependencyResolver.Current.GetService(); + Log = LogManager.GetLogger(this.GetType()); + _webDavSession.Credentials = credential; _itemId = itemId; - IKernel _kernel = new StandardKernel(new NinjectSettings { AllowNullInjection = true }, new WebDavExplorerAppModule()); - var accountModel = _kernel.Get(); - _rootFolders = ConnectToWebDavServer(accountModel.UserName); + _rootFolders = ConnectToWebDavServer(_accountModel); if (_rootFolders.Any()) { @@ -126,14 +133,24 @@ namespace WebsitePanel.WebDavPortal.Models } } - private IList ConnectToWebDavServer(string userName) + private IList ConnectToWebDavServer(AccountModel user) { var rootFolders = new List(); + foreach (var folder in ES.Services.EnterpriseStorage.GetEnterpriseFolders(_itemId)) { var permissions = ES.Services.EnterpriseStorage.GetEnterpriseFolderPermissions(_itemId, folder.Name); - if (permissions.Any(x => x.DisplayName == userName)) - rootFolders.Add(folder); + + foreach (var permission in permissions) + { + if ((!permission.IsGroup + && (permission.DisplayName == user.UserName || permission.DisplayName == user.DisplayName)) + || (permission.IsGroup && user.Groups.Any(x=> x.DisplayName == permission.DisplayName))) + { + rootFolders.Add(folder); + break; + } + } } return rootFolders; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/uploadingData2.js b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/uploadingData2.js index 42c5384c..7988b483 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/uploadingData2.js +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/uploadingData2.js @@ -24,6 +24,8 @@ function GetResources() { GetResources(); oldResourcesDivHeight = $('#resourcesDiv').height(); }; + + recalculateResourseHeight(); } }); }; diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/AccountRouteNames.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/AccountRouteNames.cs new file mode 100644 index 00000000..035fde95 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/AccountRouteNames.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace WebsitePanel.WebDavPortal.UI.Routes +{ + public class AccountRouteNames + { + public const string Logout = "AccountLogout"; + public const string Login = "AccountLogin"; + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs new file mode 100644 index 00000000..80d0d67d --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace WebsitePanel.WebDavPortal.UI.Routes +{ + public class FileSystemRouteNames + { + public const string FilePath = "FilePathRoute"; + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml index dbd14ec9..0d7d6f9f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml @@ -2,7 +2,7 @@ @using Ninject @model WebsitePanel.WebDavPortal.Models.ModelForWebDav @{ - var webDavManager = (new StandardKernel(new WebsitePanel.WebDavPortal.DependencyInjection.WebDavExplorerAppModule())).Get(); + var webDavManager = DependencyResolver.Current.GetService(); ViewBag.Title = (string.IsNullOrEmpty(Model.UrlSuffix) ? webDavManager.OrganizationName : Model.UrlSuffix); } @Scripts.Render("~/bundles/jquery") diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml index 8e6a0663..1bd9cf33 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml @@ -18,8 +18,7 @@ break; default: isTargetBlank = false; - IKernel _kernel = new StandardKernel(new WebsitePanel.WebDavPortal.DependencyInjection.WebDavExplorerAppModule()); - var webDavManager = _kernel.Get(); + var webDavManager = DependencyResolver.Current.GetService(); href = Model.Href.AbsolutePath; break; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml index 6162ed3a..d07565d5 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml @@ -2,6 +2,12 @@ @using WebsitePanel.WebDavPortal.Config @using WebsitePanel.WebDavPortal.DependencyInjection @using WebsitePanel.WebDavPortal.Models +@using WebsitePanel.WebDavPortal.UI.Routes; + +@{ + var account = DependencyResolver.Current.GetService(); +} + @@ -20,17 +26,16 @@ - @Html.ActionLink(WebDavAppConfigManager.Instance.ApplicationName, "Login", "Account", new { area = "" }, new { @class = "navbar-brand" }) + @Html.RouteLink(WebDavAppConfigManager.Instance.ApplicationName, FileSystemRouteNames.FilePath, new { pathPart = string.Empty }, new { @class = "navbar-brand" }) diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config index 8fdb594d..3acfef9f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config @@ -1,12 +1,27 @@ - + -
+
+
+ + + + + + + + + + + + + + @@ -24,7 +39,7 @@ - + diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebConfigSections/ElementsRenderingElement.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebConfigSections/ElementsRenderingElement.cs index 996d4a30..a5a9a6ce 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebConfigSections/ElementsRenderingElement.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebConfigSections/ElementsRenderingElement.cs @@ -6,6 +6,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections { private const string DefaultCountKey = "defaultCount"; private const string AddElementsCountKey = "addElementsCount"; + private const string ElementsToIgnoreKey = "elementsToIgnoreKey"; [ConfigurationProperty(DefaultCountKey, IsKey = true, IsRequired = true, DefaultValue = 30)] public int DefaultCount @@ -20,5 +21,12 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections get { return (int)this[AddElementsCountKey]; } set { this[AddElementsCountKey] = value; } } + + [ConfigurationProperty(ElementsToIgnoreKey, IsKey = true, IsRequired = true, DefaultValue = "")] + public string ElementsToIgnore + { + get { return (string)this[ElementsToIgnoreKey]; } + set { this[ElementsToIgnoreKey] = value; } + } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebsitePanel.WebDavPortal.csproj b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebsitePanel.WebDavPortal.csproj index 5b2ea9ec..369a9e7b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebsitePanel.WebDavPortal.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/WebsitePanel.WebDavPortal.csproj @@ -48,6 +48,9 @@ False ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll + + ..\packages\log4net.2.0.0\lib\net40-full\log4net.dll + ..\..\Lib\Microsoft.Web.Services3.dll @@ -158,9 +161,11 @@ - - - + + + + + @@ -179,6 +184,8 @@ + + @@ -289,6 +296,7 @@ GlobalResourceProxyGenerator Resource.errors.designer.cs + Designer diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/packages.config b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/packages.config index 5c38485f..e9fed748 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/packages.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/packages.config @@ -4,6 +4,7 @@ +