/// <summary> /// Copy permissions from the parent Node /// </summary> public virtual void CopyRolesFromNode() { if (this.Node != null) { foreach (NodePermission np in this.Node.NodePermissions) { SectionPermission sp = new SectionPermission(); sp.Section = this; sp.Role = np.Role; sp.ViewAllowed = np.ViewAllowed; sp.EditAllowed = np.EditAllowed; this.SectionPermissions.Add(sp); } } }
private void SetRoles() { this._activeSection.SectionPermissions.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) { SectionPermission sp = new SectionPermission(); sp.Section = this._activeSection; sp.Role = (Role)base.CoreRepository.GetObjectById(typeof(Role), (int)ViewState[ri.ClientID]); sp.ViewAllowed = chkView.Checked; sp.EditAllowed = chkEdit.Checked; this._activeSection.SectionPermissions.Add(sp); } } }
private void PropagatePermissionsToSections(Node node) { foreach (Section section in node.Sections) { section.SectionPermissions.Clear(); foreach (NodePermission np in node.NodePermissions) { SectionPermission sp = new SectionPermission(); sp.Section = section; sp.Role = np.Role; sp.ViewAllowed = np.ViewAllowed; sp.EditAllowed = np.EditAllowed; section.SectionPermissions.Add(sp); } } UpdateObject(node); }
protected void SetRoles() { this._activeSection.SectionPermissions.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) { SectionPermission sp = new SectionPermission(); sp.Section = this._activeSection; int rcid = (int)ViewState[ri.ClientID]; sp.Role = UserService.GetRoleById(rcid); sp.ViewAllowed = chkView.Checked; sp.EditAllowed = chkEdit.Checked; this._activeSection.SectionPermissions.Add(sp); } } }
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); }