public HttpResponseMessage ToggleSecurity(ToggleSecurityDTO dto)
        {
            var db = new Data.Common();
            var sb = new StringBuilder();

            switch (dto.Action)
            {
            case "delete":
            {
                Permissions.RemoveObjectFromAll(dto.SecurityId, dto.SecurityType, dto.PermissionsId);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            case "addobject":
            {
                if (dto.SecurityType == 1)
                {
                    var uc = new UserController();
                    var ui = uc.GetUser(PortalSettings.PortalId, dto.ModuleId, dto.SecurityId);
                    dto.SecurityId = ui != null?ui.UserId.ToString() : string.Empty;
                }
                else
                {
                    if (dto.SecurityId.Contains(":"))
                    {
                        dto.SecurityType = 2;
                    }
                }
                if (!(string.IsNullOrEmpty(dto.SecurityId)))
                {
                    var permSet = db.GetPermSet(dto.PermissionsId, "View");
                    permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                    db.SavePermSet(dto.PermissionsId, "View", permSet);
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            default:
            {
                var permSet = db.GetPermSet(dto.PermissionsId, dto.SecurityKey);
                if (dto.Action == "remove")
                {
                    permSet = Permissions.RemovePermFromSet(dto.SecurityId, dto.SecurityType, permSet);
                }
                else
                {
                    permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                }

                db.SavePermSet(dto.PermissionsId, dto.SecurityKey, permSet);
                return(Request.CreateResponse(HttpStatusCode.OK, dto.Action + "|" + dto.ReturnId));
            }
            }
        }
Ejemplo n.º 2
0
        internal static bool RemoveObjectFromAll(string objectId, int objectType, int PermissionsId)
        {
            var   enumType = typeof(SecureActions);
            Array values   = Enum.GetValues(enumType);
            var   db       = new Data.Common();

            for (int i = 0; i < values.Length; i++)
            {
                string text    = Convert.ToString(Enum.Parse(enumType, values.GetValue(i).ToString()));
                string permSet = db.GetPermSet(PermissionsId, text);
                permSet = RemovePermFromSet(objectId, objectType, permSet);
                db.SavePermSet(PermissionsId, text, permSet);
            }
            return(true);
        }
Ejemplo n.º 3
0
        internal static void CreateDefaultSets(int PortalId, int PermissionsId)
        {
            var db = new Data.Common();
            var rc = new Security.Roles.RoleController();

            Security.Roles.RoleInfo ri;
            ri = rc.GetRoleByName(PortalId, "Registered Users");
            string permSet;

            if (ri != null)
            {
                permSet = db.GetPermSet(PermissionsId, "View");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "View", permSet);
                permSet = db.GetPermSet(PermissionsId, "Read");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Read", permSet);
                permSet = db.GetPermSet(PermissionsId, "Create");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Create", permSet);
                permSet = db.GetPermSet(PermissionsId, "Reply");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Reply", permSet);
            }
            permSet = db.GetPermSet(PermissionsId, "View");
            permSet = AddPermToSet("-3", 0, permSet);
            db.SavePermSet(PermissionsId, "View", permSet);
            permSet = db.GetPermSet(PermissionsId, "Read");
            permSet = AddPermToSet("-3", 0, permSet);
            db.SavePermSet(PermissionsId, "Read", permSet);
            permSet = db.GetPermSet(PermissionsId, "View");
            permSet = AddPermToSet("-1", 0, permSet);
            db.SavePermSet(PermissionsId, "View", permSet);
            permSet = db.GetPermSet(PermissionsId, "Read");
            permSet = AddPermToSet("-1", 0, permSet);
            db.SavePermSet(PermissionsId, "Read", permSet);
        }
        public HttpResponseMessage ToggleSecurity(ToggleSecurityDTO dto)
        {
            var db = new Data.Common();
            var sb = new StringBuilder();
            switch (dto.Action)
            {
                case "delete":
                    {
                        Permissions.RemoveObjectFromAll(dto.SecurityId, dto.SecurityType, dto.PermissionsId);
                        return Request.CreateResponse(HttpStatusCode.OK);
                    }
                case "addobject":
                    {
                        if (dto.SecurityType == 1)
                        {
                            var uc = new UserController();
                            var ui = uc.GetUser(PortalSettings.PortalId, dto.ModuleId, dto.SecurityId);
                            dto.SecurityId = ui != null ? ui.UserId.ToString() : string.Empty;
                        }
                        else
                        {
                            if (dto.SecurityId.Contains(":"))
                                dto.SecurityType = 2;
                        }
                        if (!(string.IsNullOrEmpty(dto.SecurityId)))
                        {
                            var permSet = db.GetPermSet(dto.PermissionsId, "View");
                            permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                            db.SavePermSet(dto.PermissionsId, "View", permSet);
                        }

                        return Request.CreateResponse(HttpStatusCode.OK);
                    }
                default:
                    {
                        var permSet = db.GetPermSet(dto.PermissionsId, dto.SecurityKey);
                        if (dto.Action == "remove")
                            permSet = Permissions.RemovePermFromSet(dto.SecurityId, dto.SecurityType, permSet);
                        else
                            permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);

                        db.SavePermSet(dto.PermissionsId, dto.SecurityKey, permSet);
                        return Request.CreateResponse(HttpStatusCode.OK, dto.Action + "|" + dto.ReturnId);
                    }
            }
        }
Ejemplo n.º 5
0
        public int CreateGroupForum(int portalId, int moduleId, int socialGroupId, int forumGroupId, string forumName, string forumDescription, bool isPrivate, string forumConfig)
        {
            var forumId = -1;

            try
            {
                var rc          = new RoleController();
                var forumsDb    = new Data.Common();
                var fgc         = new ForumGroupController();
                var gi          = fgc.Groups_Get(moduleId, forumGroupId);
                var socialGroup = rc.GetRole(socialGroupId, portalId);
                var groupAdmin  = socialGroupId.ToString() + ":0";
                var groupMember = socialGroupId.ToString();

                var ri            = rc.GetRoleByName(portalId, "Administrators");
                var permissionsId = forumsDb.CreatePermSet(ri.RoleID.ToString());

                moduleId = gi.ModuleId;

                var fi = new Forum
                {
                    ForumDesc     = forumDescription,
                    Active        = true,
                    ForumGroupId  = forumGroupId,
                    ForumID       = -1,
                    ForumName     = forumName,
                    Hidden        = isPrivate,
                    ModuleId      = gi.ModuleId,
                    ParentForumId = 0,
                    PortalId      = portalId,
                    PermissionsId = gi.PermissionsId,
                    SortOrder     = 0,
                    SocialGroupId = socialGroupId
                };

                forumId          = Forums_Save(portalId, fi, true, true);
                fi               = GetForum(portalId, moduleId, forumId);
                fi.PermissionsId = permissionsId;
                Forums_Save(portalId, fi, false, false);

                var xDoc = new XmlDocument();
                xDoc.LoadXml(forumConfig);

                var xRoot = xDoc.DocumentElement;
                if (xRoot != null)
                {
                    var    xSecList = xRoot.SelectSingleNode("//security[@type='groupadmin']");
                    string permSet;
                    string secKey;
                    if (xSecList != null)
                    {
                        foreach (XmlNode n in xSecList.ChildNodes)
                        {
                            secKey = n.Name;
                            if (n.Attributes == null || n.Attributes["value"].Value != "true")
                            {
                                continue;
                            }
                            permSet = forumsDb.GetPermSet(permissionsId, secKey);
                            permSet = Permissions.AddPermToSet(groupAdmin, 2, permSet);
                            forumsDb.SavePermSet(permissionsId, secKey, permSet);
                        }
                    }

                    xSecList = xRoot.SelectSingleNode("//security[@type='groupmember']");
                    if (xSecList != null)
                    {
                        foreach (XmlNode n in xSecList.ChildNodes)
                        {
                            secKey = n.Name;

                            if (n.Attributes == null || n.Attributes["value"].Value != "true")
                            {
                                continue;
                            }

                            permSet = forumsDb.GetPermSet(permissionsId, secKey);
                            permSet = Permissions.AddPermToSet(groupMember, 0, permSet);
                            forumsDb.SavePermSet(permissionsId, secKey, permSet);
                        }
                    }

                    if (socialGroup.IsPublic)
                    {
                        xSecList = xRoot.SelectSingleNode("//security[@type='registereduser']");
                        ri       = rc.GetRoleByName(portalId, "Registered Users");
                        if (xSecList != null)
                        {
                            foreach (XmlNode n in xSecList.ChildNodes)
                            {
                                secKey = n.Name;

                                if (n.Attributes == null || n.Attributes["value"].Value != "true")
                                {
                                    continue;
                                }

                                permSet = forumsDb.GetPermSet(permissionsId, secKey);
                                permSet = Permissions.AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                                forumsDb.SavePermSet(permissionsId, secKey, permSet);
                            }
                        }

                        xSecList = xRoot.SelectSingleNode("//security[@type='anon']");
                        if (xSecList != null)
                        {
                            foreach (XmlNode n in xSecList.ChildNodes)
                            {
                                secKey = n.Name;

                                if (n.Attributes == null || n.Attributes["value"].Value != "true")
                                {
                                    continue;
                                }

                                permSet = forumsDb.GetPermSet(permissionsId, secKey);
                                permSet = Permissions.AddPermToSet("-1", 0, permSet);
                                forumsDb.SavePermSet(permissionsId, secKey, permSet);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            DataCache.CacheClear(moduleId + "fv");

            return(forumId);
        }
Ejemplo n.º 6
0
		internal static void CreateDefaultSets(int PortalId, int PermissionsId)
		{
			var db = new Data.Common();
			var rc = new Security.Roles.RoleController();
			Security.Roles.RoleInfo ri;
			ri = rc.GetRoleByName(PortalId, "Registered Users");
			string permSet;
			if (ri != null)
			{
				permSet = db.GetPermSet(PermissionsId, "View");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "View", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Read");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Read", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Create");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Create", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Reply");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Reply", permSet);
			}
			permSet = db.GetPermSet(PermissionsId, "View");
			permSet = AddPermToSet("-3", 0, permSet);
			db.SavePermSet(PermissionsId, "View", permSet);
		    permSet = db.GetPermSet(PermissionsId, "Read");
			permSet = AddPermToSet("-3", 0, permSet);
			db.SavePermSet(PermissionsId, "Read", permSet);
		    permSet = db.GetPermSet(PermissionsId, "View");
			permSet = AddPermToSet("-1", 0, permSet);
			db.SavePermSet(PermissionsId, "View", permSet);
		    permSet = db.GetPermSet(PermissionsId, "Read");
			permSet = AddPermToSet("-1", 0, permSet);
			db.SavePermSet(PermissionsId, "Read", permSet);
		}
Ejemplo n.º 7
0
		internal static bool RemoveObjectFromAll(string objectId, int objectType, int PermissionsId)
		{
			var enumType = typeof(SecureActions);
			Array values = Enum.GetValues(enumType);
			var db = new Data.Common();
			for (int i = 0; i < values.Length; i++)
			{
				string text = Convert.ToString(Enum.Parse(enumType, values.GetValue(i).ToString()));
				string permSet = db.GetPermSet(PermissionsId, text);
				permSet = RemovePermFromSet(objectId, objectType, permSet);
				db.SavePermSet(PermissionsId, text, permSet);
			}
			return true;
		}
Ejemplo n.º 8
0
		public int CreateGroupForum(int portalId, int moduleId, int socialGroupId, int forumGroupId, string forumName, string forumDescription, bool isPrivate, string forumConfig)
		{
			var forumId = -1;

			try
			{
				var rc = new RoleController();
				var forumsDb = new Data.Common();
			    var fgc = new ForumGroupController();
				var gi = fgc.Groups_Get(moduleId, forumGroupId);
				var socialGroup = rc.GetRole(socialGroupId, portalId);
				var groupAdmin = socialGroupId.ToString() + ":0";
				var groupMember = socialGroupId.ToString();

			    var ri = rc.GetRoleByName(portalId, "Administrators");
				var permissionsId = forumsDb.CreatePermSet(ri.RoleID.ToString());

				moduleId = gi.ModuleId;

				var fi = new Forum
				{
				    ForumDesc = forumDescription,
				    Active = true,
				    ForumGroupId = forumGroupId,
				    ForumID = -1,
				    ForumName = forumName,
				    Hidden = isPrivate,
				    ModuleId = gi.ModuleId,
				    ParentForumId = 0,
				    PortalId = portalId,
				    PermissionsId = gi.PermissionsId,
				    SortOrder = 0,
				    SocialGroupId = socialGroupId
				};

			    forumId = Forums_Save(portalId, fi, true, true);
				fi = GetForum(portalId, moduleId, forumId);
				fi.PermissionsId = permissionsId;
				Forums_Save(portalId, fi, false, false);

			    var xDoc = new XmlDocument();
				xDoc.LoadXml(forumConfig);

				var xRoot = xDoc.DocumentElement;
			    if (xRoot != null)
			    {
			        var xSecList = xRoot.SelectSingleNode("//security[@type='groupadmin']");
			        string permSet;
			        string secKey;
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupAdmin, 2, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        xSecList = xRoot.SelectSingleNode("//security[@type='groupmember']");
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
						    
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
						    
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupMember, 0, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        if (socialGroup.IsPublic)
			        {
			            xSecList = xRoot.SelectSingleNode("//security[@type='registereduser']");
			            ri = rc.GetRoleByName(portalId, "Registered Users");
			            if (xSecList != null)
			            {
			                foreach (XmlNode n in xSecList.ChildNodes)
			                {
			                    secKey = n.Name;
							    
			                    if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                        continue;
							    
			                    permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                    permSet = Permissions.AddPermToSet(ri.RoleID.ToString(), 0, permSet);
			                    forumsDb.SavePermSet(permissionsId, secKey, permSet);
			                }
			            }

			            xSecList = xRoot.SelectSingleNode("//security[@type='anon']");
			            if (xSecList != null)
			            {
			                foreach (XmlNode n in xSecList.ChildNodes)
			                {
			                    secKey = n.Name;

			                    if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                        continue;

			                    permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                    permSet = Permissions.AddPermToSet("-1", 0, permSet);
			                    forumsDb.SavePermSet(permissionsId, secKey, permSet);
			                }
			            }
			        }
			    }
			}
			catch (Exception ex)
			{

			}

			DataCache.CacheClear(moduleId + "fv");

			return forumId;
		}