private void SetNodePermission(SqlCommand cm, NodePermission np) { DatabaseHelper.InsertInt32Param("@NodeId", cm, np.NodeId); DatabaseHelper.InsertInt32Param("@RoleId", cm, np.Role.Id); DatabaseHelper.InsertBooleanParam("@ViewAllowed", cm, np.ViewAllowed); DatabaseHelper.InsertBooleanParam("@EditAllowed", cm, np.EditAllowed); }
private void SaveNodePermission(NodePermission np, SqlTransaction sqltransaction) { string sql = "INSERT INTO [NodeRole]([NodeId], [RoleId], [ViewAllowed], [EditAllowed])" + "VALUES(@NodeId, @RoleId, @ViewAllowed, @EditAllowed) SELECT @@identity"; using (SqlCommand cm = new SqlCommand(sql, DefaultConnection, sqltransaction)) { SetNodePermission(cm, np); np.Id = int.Parse(cm.ExecuteScalar().ToString()); } }
private void SetRoles() { 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 = ActiveNode; np.Role = (Role)CoreRepository.GetObjectById(typeof(Role), (int)ViewState[ri.ClientID]); np.ViewAllowed = chkView.Checked; np.EditAllowed = chkEdit.Checked; 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); } }
private void ReadNodePermissions(SqlDataReader dr, Node node) { while (dr.Read()) { NodePermission np = new NodePermission { Id = DatabaseHelper.GetInt32("NodeRoleId", dr), NodeId = node.Id, EditAllowed = DatabaseHelper.GetBoolean("EditAllowed", dr), ViewAllowed = DatabaseHelper.GetBoolean("ViewAllowed", dr) }; np.Role = new Role { Id = DatabaseHelper.GetInt32("role_id", dr), Name = DatabaseHelper.GetString("Name", dr), PermissionLevel = DatabaseHelper.GetInt32("PermissionLevel", dr) }; node.NodePermissions.Add(np); } }
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); }
static void CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, string[] nodes, IDbConnection ctx, IDbTransaction txn, string chatPrefix = null, string chatSuffix = null) #endif { #if ENTITY_FRAMEWORK_7 var grp = new Group() { Name = name, ApplyToGuests = guest, Parent = parent, Chat_Red = r, Chat_Green = g, Chat_Blue = b, Chat_Prefix = chatPrefix, Chat_Suffix = chatSuffix }; ctx.Groups.Add(grp); ctx.SaveChanges(); //Save to get the ID foreach (var nd in nodes) { var node = ctx.Nodes.SingleOrDefault(x => x.Node == nd && x.Permission == Permission.Permitted); if (node == null) { ctx.Nodes.Add(node = new NodePermission() { Node = nd, Permission = Permission.Permitted }); ctx.SaveChanges(); } ctx.GroupNodes.Add(new GroupNode() { GroupId = grp.Id, NodeId = node.Id }); } ctx.SaveChanges(); #elif DAPPER var grp = new Group() { Name = name, ApplyToGuests = guest, Parent = parent, Chat_Red = r, Chat_Green = g, Chat_Blue = b, Chat_Prefix = chatPrefix, Chat_Suffix = chatSuffix }; grp.Id = ctx.Insert(grp, txn); foreach (var nd in nodes) { var node = ctx.SingleOrDefault <PermissionNode>(new { Node = nd, Permission = Permission.Permitted }, transaction: txn); if (node == null) { node = new PermissionNode() { Node = nd, Permission = Permission.Permitted }; node.Id = ctx.Insert(node, transaction: txn); } ctx.Insert(new GroupNode() { GroupId = grp.Id, NodeId = node.Id }, transaction: txn); } #endif }