public ModuleAdminViewModel(Node node, Section section, ICuyahogaContext cuyahogaContext, T moduleData) { this.Node = node; this.Section = section; this.CuyahogaContext = cuyahogaContext; this.ModuleData = moduleData; }
public SearchResultCollection FindContent(string queryText, IList <string> categoryNames, int pageIndex, int pageSize) { // Check queryText for invalid fields if (queryText.Contains("viewroleid:")) { throw new SearchException("Don't try to mess with security!"); } ICuyahogaContext cuyahogaContext = this._cuyahogaContextProvider.GetContext(); User currentUser = cuyahogaContext.CurrentUser; IList <Role> roles; if (currentUser != null) { roles = currentUser.Roles; } else { // Assume anonymous access, get all roles that have only anonymous access. roles = this._userDao.GetAllRolesBySite(cuyahogaContext.CurrentSite).Where(role => role.IsAnonymousRole).ToList(); } IList <int> roleIds = roles.Select(role => role.Id).ToList(); IndexQuery query = new IndexQuery(GetIndexDirectory()); try { return(query.Find(queryText, categoryNames, pageIndex, pageSize, roleIds)); } catch (ParseException ex) { Logger.Error(string.Format("Invalid query: {0}", queryText), ex); throw new SearchException("Invalid search query", ex); } }
/// <summary> /// Creates a new instance of the <see cref="DirectoryViewData"/> class. /// </summary> /// <param name="cuyahogaContext"></param> /// <param name="path"></param> /// <param name="rootPath"></param> /// <param name="subDirectories"></param> /// <param name="files"></param> public DirectoryViewData(ICuyahogaContext cuyahogaContext, string path, string rootPath, IList<DirectoryInfo> subDirectories, IList<FileInfo> files) { var user = cuyahogaContext.CurrentUser; CanCreateDirectory = user.HasRight(Rights.CreateDirectory); CanCopy = user.HasRight(Rights.CopyFiles); CanMove = user.HasRight(Rights.MoveFiles); CanDelete = user.HasRight(Rights.DeleteFiles); Path = path; RootPath = rootPath; SubDirectories = subDirectories ?? new List<DirectoryInfo>(); Files = files ?? new List<FileInfo>(); BuildTrail(); }
/// <summary> /// Add 'who did what and when' while saving the content item to the database. /// </summary> /// <param name="entity"></param> /// <returns></returns> public override T Save(T entity) { ICuyahogaContext cuyahogaContext = this._cuyahogaContextProvider.GetContext(); if (entity.IsNew) { entity.CreatedAt = DateTime.Now; entity.CreatedBy = cuyahogaContext.CurrentUser; } entity.ModifiedAt = DateTime.Now; entity.ModifiedBy = cuyahogaContext.CurrentUser; return(base.Save(entity)); }
/// <summary> /// Creates a new instance of the <see cref="DirectoryViewData"/> class. /// </summary> /// <param name="cuyahogaContext"></param> /// <param name="path"></param> /// <param name="rootPath"></param> /// <param name="subDirectories"></param> /// <param name="files"></param> public DirectoryViewData(ICuyahogaContext cuyahogaContext, string path, string rootPath, IList <DirectoryInfo> subDirectories, IList <FileInfo> files) { var user = cuyahogaContext.CurrentUser; CanCreateDirectory = user.HasRight(Rights.CreateDirectory); CanCopy = user.HasRight(Rights.CopyFiles); CanMove = user.HasRight(Rights.MoveFiles); CanDelete = user.HasRight(Rights.DeleteFiles); Path = path; RootPath = rootPath; SubDirectories = subDirectories ?? new List <DirectoryInfo>(); Files = files ?? new List <FileInfo>(); BuildTrail(); }
protected override void OnInit(EventArgs e) { // Set the CuyahogaContext ICuyahogaContext cuyahogaContext = Container.Resolve <ICuyahogaContext>(); if (User.Identity.IsAuthenticated && this.User is CuyahogaUser) { cuyahogaContext.SetUser((CuyahogaUser)this.User); } ISiteService siteService = Container.Resolve <ISiteService>(); try { string siteUrl = UrlUtil.GetSiteUrl(); Site currentSite = siteService.GetSiteBySiteUrl(siteUrl); cuyahogaContext.SetSite(currentSite, siteUrl); cuyahogaContext.PhysicalSiteDataDirectory = Server.MapPath(currentSite.SiteDataDirectory); } catch (Exception ex) { logger.Error("An unexpected error occured while setting the current site context.", ex); } base.OnInit(e); }
/// <summary> /// Creates a new instance of the <see cref="RolesFilter"></see> class. /// </summary> /// <param name="userService"></param> /// <param name="cuyahogaContext"></param> public RolesFilter(IUserService userService, ICuyahogaContext cuyahogaContext) { _userService = userService; _cuyahogaContext = cuyahogaContext; }
/// <summary> /// Load the content and the template as early as possible, so everything is in place before /// modules handle their own ASP.NET lifecycle events. /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { base.OnInit(e); // Set context this._currentContext = Container.Resolve <ICuyahogaContext>(); // Load the current site string currentSiteUrl = UrlUtil.GetSiteUrl(); if (this.CurrentSite == null) { throw new SiteNullException("No site found at " + currentSiteUrl); } // Check if we're browsing via an alias. If so get the optional entry node. Node entryNode = null; if (currentSiteUrl != this.CurrentSite.SiteUrl.ToLower()) { SiteAlias siteAlias = this._siteService.GetSiteAliasByUrl(currentSiteUrl); if (siteAlias != null) { entryNode = siteAlias.EntryNode; } } // Load the active node // Query the cache by SectionId, ShortDescription and NodeId. if (Context.Request.QueryString["SectionId"] != null) { try { this._activeSection = this._sectionService.GetSectionById(Int32.Parse(Context.Request.QueryString["SectionId"])); this._activeNode = this._activeSection.Node; } catch { throw new SectionNullException("Section not found: " + Context.Request.QueryString["SectionId"]); } } else if (Context.Request.QueryString["ShortDescription"] != null) { this._activeNode = this._nodeService.GetNodeByShortDescriptionAndSite(Context.Request.QueryString["ShortDescription"], this.CurrentSite); } else if (Context.Request.QueryString["NodeId"] != null) { this._activeNode = this._nodeService.GetNodeById(Int32.Parse(Context.Request.QueryString["NodeId"])); } else if (entryNode != null) { this._activeNode = entryNode; } else { // Can't load a particular node, so the root node has to be the active node // Maybe we have culture information stored in a cookie, so we might need a different // root Node. string currentCulture = this.CurrentSite.DefaultCulture; if (Context.Request.Cookies["CuyahogaCulture"] != null) { currentCulture = Context.Request.Cookies["CuyahogaCulture"].Value; } this._activeNode = this._nodeService.GetRootNodeByCultureAndSite(currentCulture, this.CurrentSite); } // Raise an exception when there is no Node found. It will be handled by the global error handler // and translated into a proper 404. if (this._activeNode == null) { throw new NodeNullException(String.Format(@"No node found with the following parameters: NodeId: {0}, ShortDescription: {1}, SectionId: {2}" , Context.Request.QueryString["NodeId"] , Context.Request.QueryString["ShortDescription"] , Context.Request.QueryString["SectionId"])); } this._rootNode = this._activeNode.NodePath[0]; // Set culture // TODO: fix this because ASP.NET pages are not guaranteed to run in 1 thread (how?). Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); // Check node-level security if (!this._activeNode.ViewAllowed(this.User.Identity)) { throw new AccessForbiddenException("You are not allowed to view this page."); } // Check if the active node is a link. If so, redirect to the link if (this._activeNode.IsExternalLink) { Response.Redirect(this._activeNode.LinkUrl); } else { if (this._shouldLoadContent) { LoadContent(); LoadMenus(); } } // Check if the current user has access to the manager. If so, add manager toolbar to the template. if (this._templateControl != null && CuyahogaContext.Current.CurrentUser != null) { if (CuyahogaContext.Current.CurrentUser.HasRight(Rights.AccessAdmin)) { this._templateControl.Form.Controls.AddAt(0, LoadControl("~/Controls/ManagerToolbar.ascx")); } if (CuyahogaContext.Current.CurrentUser.CanEdit(this.ActiveNode)) { this._templateControl.Form.Controls.Add(LoadControl("~/Controls/InlineEditing.ascx")); } } }
/// <summary> /// Load the content and the template as early as possible, so everything is in place before /// modules handle their own ASP.NET lifecycle events. /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { base.OnInit(e); // Set context this._currentContext = Container.Resolve<ICuyahogaContext>(); // Load the current site string currentSiteUrl = UrlUtil.GetSiteUrl(); if (this.CurrentSite == null) { throw new SiteNullException("No site found at " + currentSiteUrl); } // Check if we're browsing via an alias. If so get the optional entry node. Node entryNode = null; if (currentSiteUrl != this.CurrentSite.SiteUrl.ToLower()) { SiteAlias siteAlias = this._siteService.GetSiteAliasByUrl(currentSiteUrl); if (siteAlias != null) { entryNode = siteAlias.EntryNode; } } // Load the active node // Query the cache by SectionId, ShortDescription and NodeId. if (Context.Request.QueryString["SectionId"] != null) { try { this._activeSection = this._sectionService.GetSectionById(Int32.Parse(Context.Request.QueryString["SectionId"])); this._activeNode = this._activeSection.Node; } catch { throw new SectionNullException("Section not found: " + Context.Request.QueryString["SectionId"]); } } else if (Context.Request.QueryString["ShortDescription"] != null) { this._activeNode = this._nodeService.GetNodeByShortDescriptionAndSite(Context.Request.QueryString["ShortDescription"], this.CurrentSite); } else if (Context.Request.QueryString["NodeId"] != null) { this._activeNode = this._nodeService.GetNodeById(Int32.Parse(Context.Request.QueryString["NodeId"])); } else if (entryNode != null) { this._activeNode = entryNode; } else { // Can't load a particular node, so the root node has to be the active node // Maybe we have culture information stored in a cookie, so we might need a different // root Node. string currentCulture = this.CurrentSite.DefaultCulture; if (Context.Request.Cookies["CuyahogaCulture"] != null) { currentCulture = Context.Request.Cookies["CuyahogaCulture"].Value; } this._activeNode = this._nodeService.GetRootNodeByCultureAndSite(currentCulture, this.CurrentSite); } // Raise an exception when there is no Node found. It will be handled by the global error handler // and translated into a proper 404. if (this._activeNode == null) { throw new NodeNullException(String.Format(@"No node found with the following parameters: NodeId: {0}, ShortDescription: {1}, SectionId: {2}" , Context.Request.QueryString["NodeId"] , Context.Request.QueryString["ShortDescription"] , Context.Request.QueryString["SectionId"])); } this._rootNode = this._activeNode.NodePath[0]; // Set culture // TODO: fix this because ASP.NET pages are not guaranteed to run in 1 thread (how?). Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); // Check node-level security if (! this._activeNode.ViewAllowed(this.User.Identity)) { throw new AccessForbiddenException("You are not allowed to view this page."); } // Check if the active node is a link. If so, redirect to the link if (this._activeNode.IsExternalLink) { Response.Redirect(this._activeNode.LinkUrl); } else { if (this._shouldLoadContent) { LoadContent(); LoadMenus(); } } // Check if the current user has access to the manager. If so, add manager toolbar to the template. if (this._templateControl != null && CuyahogaContext.Current.CurrentUser != null) { if (CuyahogaContext.Current.CurrentUser.HasRight(Rights.AccessAdmin)) { this._templateControl.Form.Controls.AddAt(0, LoadControl("~/Controls/ManagerToolbar.ascx")); } if (CuyahogaContext.Current.CurrentUser.CanEdit(this.ActiveNode)) { this._templateControl.Form.Controls.Add(LoadControl("~/Controls/InlineEditing.ascx")); } } }
/// <summary> /// Creates a new instance of the <see cref="SiteFilter"></see> class. /// </summary> /// <param name="siteService"></param> /// <param name="cuyahogaContext"></param> public SiteFilter(ISiteService siteService, ICuyahogaContext cuyahogaContext) { _siteService = siteService; _cuyahogaContext = cuyahogaContext; }
/// <summary> /// Creates a new instance of the <see cref="RolesFilter"></see> class. /// </summary> /// <param name="userService"></param> /// <param name="cuyahogaContext"></param> public RolesFilter(IUserService userService, ICuyahogaContext cuyahogaContext) { _userService = userService; _cuyahogaContext = cuyahogaContext; }
/// <summary> /// DownloadsModule constructor. /// </summary> /// <param name="fileResourceService"></param> /// <param name="cuyahogaContext"></param> /// <param name="contentItemService"></param> public DownloadsModule(IFileResourceService fileResourceService, ICuyahogaContext cuyahogaContext, IContentItemService <FileResource> contentItemService) { this._fileResourceService = fileResourceService; this._contentItemService = contentItemService; this._cuyahogaContext = cuyahogaContext; }
private string GetIndexDirectory() { ICuyahogaContext cuyahogaContext = this._cuyahogaContextProvider.GetContext(); return(Path.Combine(cuyahogaContext.PhysicalSiteDataDirectory, "index")); }
/// <summary> /// Creates a new instance of the <see cref="SiteFilter"></see> class. /// </summary> /// <param name="siteService"></param> /// <param name="cuyahogaContext"></param> public SiteFilter(ISiteService siteService, ICuyahogaContext cuyahogaContext) { _siteService = siteService; _cuyahogaContext = cuyahogaContext; }
/// <summary> /// Creates a new instance of the <see cref="MenuDataFilter"></see> class. /// </summary> /// <param name="cuyahogaContext"></param> /// <param name="sitemapProvider"></param> public MenuDataFilter(ICuyahogaContext cuyahogaContext, IMvcSitemapProvider sitemapProvider) { _cuyahogaContext = cuyahogaContext; _sitemapProvider = sitemapProvider; }
/// <summary> /// Creates a new instance of the <see cref="MenuDataFilter"></see> class. /// </summary> /// <param name="cuyahogaContext"></param> /// <param name="sitemapProvider"></param> public MenuDataFilter(ICuyahogaContext cuyahogaContext, IMvcSitemapProvider sitemapProvider) { _cuyahogaContext = cuyahogaContext; _sitemapProvider = sitemapProvider; }