/// <summary> /// /// </summary> public virtual void CopyRolesFromParent() { if (this._parentNode != null) { foreach (NodePermission np in this._parentNode.NodePermissions) { NodePermission npNew = new NodePermission(); npNew.Node = this; npNew.Role = np.Role; npNew.ViewAllowed = np.ViewAllowed; npNew.EditAllowed = np.EditAllowed; this.NodePermissions.Add(npNew); } } }
// added for v1.6.0 /// <summary> /// Handles the Click event of the btnDuplicate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnDuplicate_Click( object sender, EventArgs e ) { try { if( ActiveNode == null ) { ShowError( "btnDuplicate_Click:: non starting node found." ); return; } Node node = new Node(); node.ParentNode = ActiveNode.ParentNode; node.Site = ActiveNode.Site; node.Title = "Copy of " + ActiveNode.Title; node.Template = ActiveNode.Template; node.Culture = ActiveNode.Culture; node.LinkUrl = ActiveNode.LinkUrl; node.MetaDescription = ActiveNode.MetaDescription; node.MetaKeywords = ActiveNode.MetaKeywords; node.LinkTarget = ActiveNode.LinkTarget; node.ShowInNavigation = ActiveNode.ShowInNavigation; node.CreateShortDescription(); foreach( NodePermission np in ActiveNode.NodePermissions ) { NodePermission npNew = new NodePermission(); npNew.Node = node; npNew.Role = np.Role; npNew.ViewAllowed = np.ViewAllowed; npNew.EditAllowed = np.EditAllowed; node.NodePermissions.Add( npNew ); } IList rootNodes = base.CoreRepository.GetRootNodes( node.Site ); node.CalculateNewPosition( rootNodes ); ActiveNode.ChildNodes.Add(node); base.CoreRepository.SaveObject( node ); CopySectionsFromNode( ActiveNode, node ); base.CoreRepository.ClearQueryCache( "Nodes" ); base.CoreRepository.ClearCollectionCache("Cuyahoga.Core.Domain.Node.ChildNodes"); Context.Response.Redirect(String.Format( "NodeEdit.aspx?NodeId={0}&message=Node has been duplicated.", node.Id ) ); } catch( Exception ee ) { ShowException( ee ); } }
private void SetRoles() { this.ActiveNode.NodePermissions.Clear(); foreach (RepeaterItem ri in rptRoles.Items) { // HACK: RoleId is stored in the ViewState because the repeater doesn't have a DataKeys property. CheckBox chkView = (CheckBox)ri.FindControl("chkViewAllowed"); CheckBox chkEdit = (CheckBox)ri.FindControl("chkEditAllowed"); if (chkView.Checked || chkEdit.Checked) { NodePermission np = new NodePermission(); np.Node = this.ActiveNode; np.Role = (Role)base.CoreRepository.GetObjectById(typeof(Role), (int)ViewState[ri.ClientID]); np.ViewAllowed = chkView.Checked; np.EditAllowed = chkEdit.Checked; this.ActiveNode.NodePermissions.Add(np); } } }
private void PropagatePermissionsToChildNodes(Node parentNode, bool propagateToSections) { foreach (Node childNode in parentNode.ChildNodes) { childNode.NodePermissions.Clear(); foreach (NodePermission pnp in parentNode.NodePermissions) { NodePermission childNodePermission = new NodePermission(); childNodePermission.Node = childNode; childNodePermission.Role = pnp.Role; childNodePermission.ViewAllowed = pnp.ViewAllowed; childNodePermission.EditAllowed = pnp.EditAllowed; childNode.NodePermissions.Add(childNodePermission); } if (propagateToSections) { PropagatePermissionsToSections(childNode); } PropagatePermissionsToChildNodes(childNode, propagateToSections); UpdateObject(childNode); } }
protected void btnDuplicate_Click(object sender, EventArgs e) { try { if (ActiveNode == null) { ShowError("btnDuplicate_Click:: non starting node found."); return; } Node node = new Node(); node.ParentNode = ActiveNode.ParentNode; node.Site = this.ActiveSite; node.Title = "Copy of " + ActiveNode.Title; //Custom: Check for existing copies and rename accordingly if (node.ParentNode.ChildNodes.Count > 0) { foreach (Node n in node.ParentNode.ChildNodes) { if (node.Title == n.Title) { node.Title = "Copy of " + n.Title; } } } node.Template = ActiveNode.Template; node.Culture = ActiveNode.Culture; node.LinkUrl = ActiveNode.LinkUrl; node.MetaDescription = ActiveNode.MetaDescription; node.MetaKeywords = ActiveNode.MetaKeywords; node.LinkTarget = ActiveNode.LinkTarget; node.ShowInNavigation = ActiveNode.ShowInNavigation; node.CreateShortDescription(); foreach (NodePermission np in ActiveNode.NodePermissions) { NodePermission npNew = new NodePermission(); npNew.Node = node; npNew.Role = np.Role; npNew.ViewAllowed = np.ViewAllowed; npNew.EditAllowed = np.EditAllowed; node.NodePermissions.Add(npNew); } IList rootNodes = NodeService.GetRootNodes(node.Site).ToList(); node.CalculateNewPosition(rootNodes); ActiveNode.ChildNodes.Add(node); NodeService.SaveNode(node); CopySectionsFromNode(ActiveNode, node); _commonDao.RemoveQueryFromCache("Nodes"); _commonDao.RemoveCollectionFromCache("Cuyahoga.Core.Domain.Node.ChildNodes"); Context.Response.Redirect(String.Format("NodeEdit.aspx?NodeId={0}&message=Node has been duplicated.", node.Id)); } catch (Exception ee) { ShowException(ee); } }
private void CreateSite() { Role defaultAuthenticatedRole = this._commonDao.GetObjectByDescription(typeof(Role), "Name", "Authenticated user") as Role; // Site Site site = new Site(); site.Name = "Cuyahoga Sample Site"; site.SiteUrl = UrlHelper.GetSiteUrl(); site.WebmasterEmail = "*****@*****.**"; site.UseFriendlyUrls = true; site.DefaultCulture = "en-US"; site.DefaultPlaceholder = "maincontent"; site.DefaultRole = defaultAuthenticatedRole; string systemTemplatePath = Server.MapPath(Config.GetConfiguration()["TemplateDir"]); this._siteService.CreateSite(site, Server.MapPath("~/SiteData"), this._commonDao.GetAll<Template>(), systemTemplatePath); // Template Template defaultTemplate = this._commonDao.GetAll<Template>().Where(t => t.Site == site && t.BasePath == "Templates/AnotherRed").Single(); site.DefaultTemplate = defaultTemplate; this._commonDao.UpdateObject(site); // Root node Node rootNode = new Node(); rootNode.Culture = site.DefaultCulture; rootNode.Position = 0; rootNode.ShortDescription = "home"; rootNode.ShowInNavigation = true; rootNode.Site = site; rootNode.Template = defaultTemplate; rootNode.Title = "Home"; IList allRoles = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRoles) { NodePermission np = new NodePermission(); np.Node = rootNode; np.Role = role; np.ViewAllowed = true; np.EditAllowed = role.HasRight(Rights.Administrator); rootNode.NodePermissions.Add(np); } this._commonDao.SaveOrUpdateObject(rootNode); // Sections on root Node Section loginSection = new Section(); loginSection.Site = site; loginSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "User") as ModuleType; loginSection.Title = "Login"; loginSection.CacheDuration = 0; loginSection.Node = rootNode; loginSection.PlaceholderId = "side1content"; loginSection.Position = 0; loginSection.ShowTitle = true; loginSection.Settings.Add("SHOW_EDIT_PROFILE", "True"); loginSection.Settings.Add("SHOW_RESET_PASSWORD", "True"); loginSection.Settings.Add("SHOW_REGISTER", "True"); loginSection.CopyRolesFromNode(); rootNode.Sections.Add(loginSection); this._commonDao.SaveOrUpdateObject(loginSection); Section introSection = new Section(); introSection.Site = site; introSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; introSection.Title = "Welcome"; introSection.CacheDuration = 0; introSection.Node = rootNode; introSection.PlaceholderId = "maincontent"; introSection.Position = 0; introSection.ShowTitle = true; introSection.CopyRolesFromNode(); rootNode.Sections.Add(introSection); this._commonDao.SaveOrUpdateObject(introSection); // Pages Node page1 = new Node(); page1.Culture = site.DefaultCulture; page1.Position = 0; page1.ShortDescription = "page1"; page1.ShowInNavigation = true; page1.Site = site; page1.Template = defaultTemplate; page1.Title = "Articles"; page1.ParentNode = rootNode; page1.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page1); ModuleType articlesModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Articles") as ModuleType; // Check if the articles module is installed if (articlesModuleType != null) { Section articleSection = new Section(); articleSection.Site = site; articleSection.ModuleType = articlesModuleType; articleSection.Title = "Articles"; articleSection.CacheDuration = 0; articleSection.Node = page1; articleSection.PlaceholderId = "maincontent"; articleSection.Position = 0; articleSection.ShowTitle = true; articleSection.Settings.Add("DISPLAY_TYPE", "FullContent"); articleSection.Settings.Add("ALLOW_ANONYMOUS_COMMENTS", "True"); articleSection.Settings.Add("ALLOW_COMMENTS", "True"); articleSection.Settings.Add("SORT_BY", "DateOnline"); articleSection.Settings.Add("SORT_DIRECTION", "DESC"); articleSection.Settings.Add("ALLOW_SYNDICATION", "True"); articleSection.Settings.Add("NUMBER_OF_ARTICLES_IN_LIST", "5"); articleSection.CopyRolesFromNode(); page1.Sections.Add(articleSection); this._commonDao.SaveOrUpdateObject(articleSection); } Node page2 = new Node(); page2.Culture = site.DefaultCulture; page2.Position = 1; page2.ShortDescription = "page2"; page2.ShowInNavigation = true; page2.Site = site; page2.Template = defaultTemplate; page2.Title = "Page 2"; page2.ParentNode = rootNode; page2.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page2); Section page2Section = new Section(); page2Section.Site = site; page2Section.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; page2Section.Title = "Page 2"; page2Section.CacheDuration = 0; page2Section.Node = page2; page2Section.PlaceholderId = "maincontent"; page2Section.Position = 0; page2Section.ShowTitle = true; page2Section.CopyRolesFromNode(); rootNode.Sections.Add(page2Section); this._commonDao.SaveOrUpdateObject(page2Section); // User Profile node Node userProfileNode = new Node(); userProfileNode.Culture = site.DefaultCulture; userProfileNode.Position = 2; userProfileNode.ShortDescription = "userprofile"; userProfileNode.ShowInNavigation = false; userProfileNode.Site = site; userProfileNode.Template = defaultTemplate; userProfileNode.Title = "User Profile"; userProfileNode.ParentNode = rootNode; userProfileNode.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(userProfileNode); Section userProfileSection = new Section(); userProfileSection.Site = site; userProfileSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "UserProfile") as ModuleType; userProfileSection.Title = "User Profile"; userProfileSection.CacheDuration = 0; userProfileSection.Node = userProfileNode; userProfileSection.PlaceholderId = "maincontent"; userProfileSection.Position = 0; userProfileSection.ShowTitle = false; userProfileSection.CopyRolesFromNode(); userProfileNode.Sections.Add(userProfileSection); this._commonDao.SaveOrUpdateObject(userProfileSection); // Connections from Login to User Profile loginSection.Connections.Add("Register", userProfileSection); loginSection.Connections.Add("ResetPassword", userProfileSection); loginSection.Connections.Add("ViewProfile", userProfileSection); loginSection.Connections.Add("EditProfile", userProfileSection); this._commonDao.SaveOrUpdateObject(loginSection); }
private void CreateSite() { this._commonDao.Flush();//TEST User adminUser = (User) this._commonDao.GetObjectById(typeof(User), 1); //If SiteData/1/ exists then delete it if(Directory.Exists(Server.MapPath("~/SiteData/1/"))) this._fileService.DeleteDirectory(Server.MapPath("~/SiteData/1/")); #region Sections for Templates //Template defaultTemplate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Another Red") as Template; Template defaultTemplate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Cuyahoga") as Template; //Other templates list here Template Corporate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Corporate") as Template; Template CityLights = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "CityLights") as Template; Template ImpactDroppy = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Impact(Droppy)") as Template; #endregion Role defaultAuthenticatedRole = this._commonDao.GetObjectByDescription(typeof(Role), "Name", "Authenticated User") as Role; #region Region for default site // Site Site site = new Site(); site.Name = "Cuyahoga Sample Site"; site.SiteUrl = UrlHelper.GetSiteUrl(); site.WebmasterEmail = "*****@*****.**"; site.UseFriendlyUrls = true; site.DefaultCulture = "en-US"; site.DefaultTemplate = defaultTemplate; site.DefaultPlaceholder = "Content_Main"; site.DefaultRole = defaultAuthenticatedRole; string systemTemplatePath = Server.MapPath(Config.GetConfiguration()["TemplateDir"]); this._siteService.CreateSite(site, Server.MapPath("~/SiteData"), this._commonDao.GetAll<Template>(), systemTemplatePath); //Assign admin user to site adminUser.Sites.Add(site); this._commonDao.SaveObject(adminUser); #endregion #region Region for Templates //Menu_Sub Section Menu_Sub = new Section(); Menu_Sub.Site = site; Menu_Sub.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Menu") as ModuleType; Menu_Sub.Title = "Menu_Sub"; Menu_Sub.CacheDuration = 0; Menu_Sub.PlaceholderId = "Navigation_Sub"; Menu_Sub.Position = 0; Menu_Sub.ShowTitle = false; Menu_Sub.Settings.Add("LAST_LEVEL", "-1"); Menu_Sub.Settings.Add("FIRST_LEVEL", "1"); Menu_Sub.Settings.Add("TYPE_RENDER", "NavigationTree"); Menu_Sub.Settings.Add("REQUIRES_JQUERY", "False"); //Menu_Main Section Menu_Main = new Section(); Menu_Main.Site = site; Menu_Main.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Menu") as ModuleType; Menu_Main.Title = "Menu_Main"; Menu_Main.CacheDuration = 0; Menu_Main.PlaceholderId = "Navigation_Main"; Menu_Main.Position = 0; Menu_Main.ShowTitle = false; Menu_Main.Settings.Add("LAST_LEVEL", "-1"); Menu_Main.Settings.Add("FIRST_LEVEL", "0"); Menu_Main.Settings.Add("TYPE_RENDER", "NavigationTree"); Menu_Main.Settings.Add("REQUIRES_JQUERY", "True"); //Section Permissions for all sections IList allRolesSection = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRolesSection) { SectionPermission spMenu_Sub = new SectionPermission(); spMenu_Sub.Section = Menu_Sub; spMenu_Sub.Role = role; spMenu_Sub.ViewAllowed = true; spMenu_Sub.EditAllowed = role.HasRight(Rights.EditSections); Menu_Sub.SectionPermissions.Add(spMenu_Sub); SectionPermission spMenu_Main = new SectionPermission(); spMenu_Main.Section = Menu_Main; spMenu_Main.Role = role; spMenu_Main.ViewAllowed = true; spMenu_Main.EditAllowed = role.HasRight(Rights.EditSections); Menu_Main.SectionPermissions.Add(spMenu_Main); } //Save the sections this._commonDao.SaveOrUpdateObject(Menu_Sub); this._commonDao.SaveOrUpdateObject(Menu_Main); //Attach Sections to 'defaulttemplate' Sections[PlaceHolderName Key] defaultTemplate.Sections["Navigation_Sub"] = Menu_Sub; defaultTemplate.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(defaultTemplate); //Attach Sections to other templates Sections[PlaceHolderName Key] CityLights.Sections["Navigation_Sub"] = Menu_Sub; CityLights.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(CityLights); ImpactDroppy.Sections["Navigation_Sub"] = Menu_Sub; ImpactDroppy.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(ImpactDroppy); Corporate.Sections["Navigation_Sub"] = Menu_Sub; Corporate.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(ImpactDroppy); //Attach these Sections to all the sites templates foreach (Template t in site.Templates) { t.Sections["Navigation_Sub"] = Menu_Sub; t.Sections["Navigation_Main"] = Menu_Main; this._commonDao.UpdateObject(t); } #endregion // Root node Node rootNode = new Node(); rootNode.Culture = site.DefaultCulture; rootNode.Position = 0; rootNode.ShortDescription = "home"; rootNode.ShowInNavigation = true; rootNode.Site = site; rootNode.Template = site.DefaultTemplate; rootNode.Title = "Home"; IList allRoles = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRoles) { NodePermission np = new NodePermission(); np.Node = rootNode; np.Role = role; np.ViewAllowed = true; np.EditAllowed = role.HasRight(Rights.EditSections); rootNode.NodePermissions.Add(np); } this._commonDao.SaveOrUpdateObject(rootNode); // Sections on root Node Section loginSection = new Section(); loginSection.Site = site; loginSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "User") as ModuleType; loginSection.Title = "Login"; loginSection.CacheDuration = 0; loginSection.Node = rootNode; loginSection.PlaceholderId = "Login_Main"; loginSection.Position = 0; loginSection.ShowTitle = true; loginSection.Settings.Add("SHOW_EDIT_PROFILE", "True"); loginSection.Settings.Add("SHOW_RESET_PASSWORD", "True"); loginSection.Settings.Add("SHOW_REGISTER", "True"); loginSection.CopyRolesFromNode(); rootNode.Sections.Add(loginSection); this._commonDao.SaveOrUpdateObject(loginSection); Section introSection = new Section(); introSection.Site = site; introSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; introSection.Title = "Welcome"; introSection.CacheDuration = 0; introSection.Node = rootNode; introSection.PlaceholderId = "Content_Main"; introSection.Position = 0; introSection.ShowTitle = true; introSection.CopyRolesFromNode(); rootNode.Sections.Add(introSection); this._commonDao.SaveOrUpdateObject(introSection); // Pages Node page1 = new Node(); page1.Culture = site.DefaultCulture; page1.Position = 0; page1.ShortDescription = "page1"; page1.ShowInNavigation = true; page1.Site = site; page1.Template = site.DefaultTemplate; page1.Title = "Articles"; page1.ParentNode = rootNode; page1.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page1); ModuleType articlesModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Articles") as ModuleType; // Check if the articles module is installed if (articlesModuleType != null) { Section articleSection = new Section(); articleSection.Site = site; articleSection.ModuleType = articlesModuleType; articleSection.Title = "Articles"; articleSection.CacheDuration = 0; articleSection.Node = page1; articleSection.PlaceholderId = "Content_Main"; articleSection.Position = 0; articleSection.ShowTitle = true; articleSection.Settings.Add("DISPLAY_TYPE", "FullContent"); articleSection.Settings.Add("ALLOW_ANONYMOUS_COMMENTS", "True"); articleSection.Settings.Add("ALLOW_COMMENTS", "True"); articleSection.Settings.Add("SORT_BY", "DateOnline"); articleSection.Settings.Add("SORT_DIRECTION", "DESC"); articleSection.Settings.Add("ALLOW_SYNDICATION", "True"); articleSection.Settings.Add("NUMBER_OF_ARTICLES_IN_LIST", "5"); articleSection.CopyRolesFromNode(); page1.Sections.Add(articleSection); this._commonDao.SaveOrUpdateObject(articleSection); } Node page2 = new Node(); page2.Culture = site.DefaultCulture; page2.Position = 1; page2.ShortDescription = "page2"; page2.ShowInNavigation = true; page2.Site = site; page2.Template = site.DefaultTemplate; page2.Title = "Page 2"; page2.ParentNode = rootNode; page2.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page2); Section page2Section = new Section(); page2Section.Site = site; page2Section.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; page2Section.Title = "Page 2"; page2Section.CacheDuration = 0; page2Section.Node = page2; page2Section.PlaceholderId = "Content_Main"; page2Section.Position = 0; page2Section.ShowTitle = true; page2Section.CopyRolesFromNode(); rootNode.Sections.Add(page2Section); this._commonDao.SaveOrUpdateObject(page2Section); // User Profile node Node userProfileNode = new Node(); userProfileNode.Culture = site.DefaultCulture; userProfileNode.Position = 2; userProfileNode.ShortDescription = "userprofile"; userProfileNode.ShowInNavigation = false; userProfileNode.Site = site; userProfileNode.Template = site.DefaultTemplate; userProfileNode.Title = "User Profile"; userProfileNode.ParentNode = rootNode; userProfileNode.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(userProfileNode); Section userProfileSection = new Section(); userProfileSection.Site = site; userProfileSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "UserProfile") as ModuleType; userProfileSection.Title = "User Profile"; userProfileSection.CacheDuration = 0; userProfileSection.Node = userProfileNode; userProfileSection.PlaceholderId = "Content_Main"; userProfileSection.Position = 0; userProfileSection.ShowTitle = false; userProfileSection.CopyRolesFromNode(); userProfileNode.Sections.Add(userProfileSection); this._commonDao.SaveOrUpdateObject(userProfileSection); // Connections from Login to User Profile loginSection.Connections.Add("Register", userProfileSection); loginSection.Connections.Add("ResetPassword", userProfileSection); loginSection.Connections.Add("ViewProfile", userProfileSection); loginSection.Connections.Add("EditProfile", userProfileSection); this._commonDao.SaveOrUpdateObject(loginSection); }