コード例 #1
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Removes all users which ID's are stored in UsersToRemove, from the role with ID RoleID.
        /// </summary>
        /// <param name="userIDsToRemove">ArrayList with UserIDs of the users to Remove</param>
        /// <param name="roleID">ID of role the users will be removed from</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool RemoveUsersFromRole(List <int> userIDsToRemove, int roleID)
        {
            if (userIDsToRemove.Count <= 0)
            {
                return(true);
            }

            // we'll delete all role-user combinations for the users in the given range plus for the given role.
            // if there's just one user, we'll use an optimization, as the range query will result in an IN (param, param... ) query,
            // and an field IN (param) query, is much slower compared to field = param, at least on Sqlserver.

            // produce the filter which will be used to filter out the entities to delete.
            PredicateExpression filter = new PredicateExpression();

            if (userIDsToRemove.Count == 1)
            {
                // use compare value predicate instead
                filter.Add((RoleUserFields.UserID == userIDsToRemove[0]));
            }
            else
            {
                // add a range filter
                filter.Add((RoleUserFields.UserID == userIDsToRemove));
            }
            // add the filter for the role as with AND.
            filter.AddWithAnd((RoleUserFields.RoleID == roleID));

            // delete the entities directly from the database. As this gives a single DELETE statement, we don't have to start a transaction manually.
            RoleUserCollection roleUsers = new RoleUserCollection();

            return(roleUsers.DeleteMulti(filter) > 0);
        }
コード例 #2
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Deletes the given role from the system.
        /// </summary>
        /// <param name="roleID">ID of role to delete</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteRole(int roleID)
        {
            RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID);

            if (toDelete == null)
            {
                // not found
                return(false);
            }

            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole");

            try
            {
                // remove the role - forum - action right entities
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID);

                // Remove role-audit action entities
                RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
                trans.Add(roleAuditActions);
                roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID);

                // remove Role - systemright entities
                RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection();
                trans.Add(roleSystemRights);
                roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);

                // remove Role - user entities
                RoleUserCollection roleUsers = new RoleUserCollection();
                trans.Add(roleUsers);
                roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID);

                // delete the actual role
                trans.Add(toDelete);
                toDelete.Delete();
                trans.Commit();
                return(true);
            }
            catch
            {
                // error occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
コード例 #3
0
        public override int AddUsersToRoles(RoleUserCollection roleUsers)
        {
            using (SqlQuery query = new SqlQuery())
            {
                int count = 0;
                query.CommandText = "bx_AddUserToRole_xh";
                query.CommandType = CommandType.StoredProcedure;
                foreach (RoleUser item in roleUsers)
                {
                    query.CreateParameter <int>("@UserID", item.UserID, SqlDbType.Int);
                    query.CreateParameter <int>("@RoleID", item.RoleID, SqlDbType.Int);
                    query.CreateParameter <DateTime>("@BeginDate", item.BeginDate, SqlDbType.DateTime);
                    query.CreateParameter <DateTime>("@EndDate", item.EndDate, SqlDbType.DateTime);

                    count += query.ExecuteNonQuery();
                }
                return(count);
            }
        }
コード例 #4
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Adds all users which ID's are stored in UsersToAdd, to the role with ID RoleID.
        /// </summary>
        /// <param name="userIDsToAdd">List with UserIDs of the users to add</param>
        /// <param name="roleID">ID of role the users will be added to</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool AddUsersToRole(List<int> userIDsToAdd, int roleID)
        {
            if(userIDsToAdd.Count<=0)
            {
                return true;
            }

            RoleUserCollection roleUsers = new RoleUserCollection();
            // for each userid in the list, add a new entity to the collection
            foreach(int userID in userIDsToAdd)
            {
                RoleUserEntity newRoleUser = new RoleUserEntity();
                newRoleUser.UserID = userID;
                newRoleUser.RoleID = roleID;
                roleUsers.Add(newRoleUser);
            }

            // save the new role-user combinations
            return (roleUsers.SaveMulti() > 0);
        }
コード例 #5
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Adds all users which ID's are stored in UsersToAdd, to the role with ID RoleID.
        /// </summary>
        /// <param name="userIDsToAdd">List with UserIDs of the users to add</param>
        /// <param name="roleID">ID of role the users will be added to</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool AddUsersToRole(List <int> userIDsToAdd, int roleID)
        {
            if (userIDsToAdd.Count <= 0)
            {
                return(true);
            }

            RoleUserCollection roleUsers = new RoleUserCollection();

            // for each userid in the list, add a new entity to the collection
            foreach (int userID in userIDsToAdd)
            {
                RoleUserEntity newRoleUser = new RoleUserEntity();
                newRoleUser.UserID = userID;
                newRoleUser.RoleID = roleID;
                roleUsers.Add(newRoleUser);
            }

            // save the new role-user combinations
            return(roleUsers.SaveMulti() > 0);
        }
コード例 #6
0
ファイル: RoleBO.cs プロジェクト: zhangbo27/bbsmax
        public int AddUsersToRole(AuthUser operatorUser, IEnumerable <int> userIds, Role role, DateTime beginDate, DateTime enddate)
        {
            RoleUserCollection roleusers = new RoleUserCollection();

            RoleUser ru;

            SimpleUserCollection users = UserBO.Instance.GetSimpleUsers(userIds);
            SimpleUser           user;

            foreach (int i in userIds)
            {
                if (users.TryGetValue(i, out user))
                {
                    ru           = new RoleUser();
                    ru.UserID    = i;
                    ru.RoleID    = role.RID;
                    ru.BeginDate = beginDate;
                    ru.EndDate   = enddate;
                    roleusers.Add(ru);
                }
            }

            return(Math.Abs(RoleDao.Instance.AddUsersToRoles(roleusers)));
        }
コード例 #7
0
ファイル: RoleDao.cs プロジェクト: xiongeee/bbsmax
 /// <summary>
 /// 将一组用户加入一组用户组
 /// </summary>
 /// <param name="userRoles"></param>
 public abstract int AddUsersToRoles(RoleUserCollection roleUsers);
コード例 #8
0
ファイル: UserManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Deletes the user with the ID passed in. Will reset all posts made by the user to the userid 0. 
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <remarks>Can't delete user 0</remarks>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteUser(int userID)
        {
            if(userID == 0)
            {
                // can't delete the Anonymous coward user.
                return false;
            }

            UserEntity toDelete = UserGuiHelper.GetUser(userID);
            if(toDelete==null)
            {
                // user doesn't exist
                return false;
            }

            // all actions have to take place in a transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteUser");

            try
            {
                // we'll first update all PostedByUserId fields of all messages which are posted by the user to delete.
                MessageEntity messageUpdater = new MessageEntity();
                messageUpdater.PostedByUserID = 0;	// reset to AC.
                MessageCollection messages = new MessageCollection();
                trans.Add(messages);	// add to the transaction
                // update all entities directly in the DB, which match the following filter and update them with the new values set in messageUpdater.
                messages.UpdateMulti(messageUpdater, (MessageFields.PostedByUserID == userID));

                // set the startuser of threads started by this user to 0
                ThreadEntity threadUpdater = new ThreadEntity();
                threadUpdater.StartedByUserID = 0;
                ThreadCollection threads = new ThreadCollection();
                trans.Add(threads);
                threads.UpdateMulti(threadUpdater, (ThreadFields.StartedByUserID == userID));

                // remove the user from the UserRoles set, as the user shouldn't be in any roles.
                RoleUserCollection roleUsersDeleter = new RoleUserCollection();
                trans.Add(roleUsersDeleter);
                // delete all entities directly from the DB which match the following filter.
                roleUsersDeleter.DeleteMulti(RoleUserFields.UserID == userID);

                // delete all bookmarks of user
                BookmarkCollection bookmarkDeleter = new BookmarkCollection();
                trans.Add(bookmarkDeleter);
                // delete all bookmarks for this user directly from the DB using the following filter.
                bookmarkDeleter.DeleteMulti(BookmarkFields.UserID == userID);

                // delete all audit data
                AuditDataCoreCollection auditDataDeleter = new AuditDataCoreCollection();
                // first fetch it, then delete all entities from the collection, as the audit data is in an inheritance hierarchy of TargetPerEntity which can't
                // be deleted directly from the db.
                trans.Add(auditDataDeleter);
                auditDataDeleter.GetMulti(AuditDataCoreFields.UserID == userID);
                auditDataDeleter.DeleteMulti();

                // set IP bans set by this user to userid 0
                IPBanEntity ipbanUpdater = new IPBanEntity();
                ipbanUpdater.IPBanSetByUserID = 0;
                IPBanCollection ipBans = new IPBanCollection();
                trans.Add(ipBans);
                ipBans.UpdateMulti(ipbanUpdater, (IPBanFields.IPBanSetByUserID == userID));

                // delete threadsubscriptions
                ThreadSubscriptionCollection threadSubscriptionsDeleter = new ThreadSubscriptionCollection();
                trans.Add(threadSubscriptionsDeleter);
                threadSubscriptionsDeleter.DeleteMulti(ThreadSubscriptionFields.UserID == userID);

                // remove supportqueuethread claims
                SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection();
                trans.Add(supportQueueThreads);
                supportQueueThreads.DeleteMulti(SupportQueueThreadFields.ClaimedByUserID == userID);

                // set all placed in queue references to userid 0, so the threads stay in the queues.
                SupportQueueThreadEntity supportQueueThreadUpdater = new SupportQueueThreadEntity();
                supportQueueThreadUpdater.PlacedInQueueByUserID=0;
                supportQueueThreads.UpdateMulti(supportQueueThreadUpdater, (SupportQueueThreadFields.PlacedInQueueByUserID == userID));

                // now delete the actual user entity
                trans.Add(toDelete);
                toDelete.Delete();

                // all done
                trans.Commit();
                return true;
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
コード例 #9
0
ファイル: UserManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Deletes the user with the ID passed in. Will reset all posts made by the user to the userid 0.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <remarks>Can't delete user 0</remarks>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteUser(int userID)
        {
            if (userID == 0)
            {
                // can't delete the Anonymous coward user.
                return(false);
            }

            UserEntity toDelete = UserGuiHelper.GetUser(userID);

            if (toDelete == null)
            {
                // user doesn't exist
                return(false);
            }

            // all actions have to take place in a transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteUser");

            try
            {
                // we'll first update all PostedByUserId fields of all messages which are posted by the user to delete.
                MessageEntity messageUpdater = new MessageEntity();
                messageUpdater.PostedByUserID = 0;      // reset to AC.
                MessageCollection messages = new MessageCollection();
                trans.Add(messages);                    // add to the transaction
                // update all entities directly in the DB, which match the following filter and update them with the new values set in messageUpdater.
                messages.UpdateMulti(messageUpdater, (MessageFields.PostedByUserID == userID));

                // set the startuser of threads started by this user to 0
                ThreadEntity threadUpdater = new ThreadEntity();
                threadUpdater.StartedByUserID = 0;
                ThreadCollection threads = new ThreadCollection();
                trans.Add(threads);
                threads.UpdateMulti(threadUpdater, (ThreadFields.StartedByUserID == userID));

                // remove the user from the UserRoles set, as the user shouldn't be in any roles.
                RoleUserCollection roleUsersDeleter = new RoleUserCollection();
                trans.Add(roleUsersDeleter);
                // delete all entities directly from the DB which match the following filter.
                roleUsersDeleter.DeleteMulti(RoleUserFields.UserID == userID);

                // delete all bookmarks of user
                BookmarkCollection bookmarkDeleter = new BookmarkCollection();
                trans.Add(bookmarkDeleter);
                // delete all bookmarks for this user directly from the DB using the following filter.
                bookmarkDeleter.DeleteMulti(BookmarkFields.UserID == userID);

                // delete all audit data
                AuditDataCoreCollection auditDataDeleter = new AuditDataCoreCollection();
                // first fetch it, then delete all entities from the collection, as the audit data is in an inheritance hierarchy of TargetPerEntity which can't
                // be deleted directly from the db.
                trans.Add(auditDataDeleter);
                auditDataDeleter.GetMulti(AuditDataCoreFields.UserID == userID);
                auditDataDeleter.DeleteMulti();

                // set IP bans set by this user to userid 0
                IPBanEntity ipbanUpdater = new IPBanEntity();
                ipbanUpdater.IPBanSetByUserID = 0;
                IPBanCollection ipBans = new IPBanCollection();
                trans.Add(ipBans);
                ipBans.UpdateMulti(ipbanUpdater, (IPBanFields.IPBanSetByUserID == userID));

                // delete threadsubscriptions
                ThreadSubscriptionCollection threadSubscriptionsDeleter = new ThreadSubscriptionCollection();
                trans.Add(threadSubscriptionsDeleter);
                threadSubscriptionsDeleter.DeleteMulti(ThreadSubscriptionFields.UserID == userID);

                // remove supportqueuethread claims
                SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection();
                trans.Add(supportQueueThreads);
                supportQueueThreads.DeleteMulti(SupportQueueThreadFields.ClaimedByUserID == userID);

                // set all placed in queue references to userid 0, so the threads stay in the queues.
                SupportQueueThreadEntity supportQueueThreadUpdater = new SupportQueueThreadEntity();
                supportQueueThreadUpdater.PlacedInQueueByUserID = 0;
                supportQueueThreads.UpdateMulti(supportQueueThreadUpdater, (SupportQueueThreadFields.PlacedInQueueByUserID == userID));

                // now delete the actual user entity
                trans.Add(toDelete);
                toDelete.Delete();

                // all done
                trans.Commit();
                return(true);
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
コード例 #10
0
ファイル: RoleDao.cs プロジェクト: huchao007/bbsmax
        public override int AddUsersToRoles(RoleUserCollection roleUsers)
        {
            using (SqlQuery query = new SqlQuery())
            {
                int count=0;
                query.CommandText = "bx_AddUserToRole_xh";
                query.CommandType = CommandType.StoredProcedure;
                foreach (RoleUser item in roleUsers)
                {
                    query.CreateParameter<int>("@UserID", item.UserID, SqlDbType.Int);
                    query.CreateParameter<int>("@RoleID",item.RoleID,SqlDbType.Int);
                    query.CreateParameter<DateTime>("@BeginDate", item.BeginDate, SqlDbType.DateTime);
                    query.CreateParameter<DateTime>("@EndDate", item.EndDate, SqlDbType.DateTime);

                    count += query.ExecuteNonQuery();
                }
                return count;
            }

            
        }
コード例 #11
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Removes all users which ID's are stored in UsersToRemove, from the role with ID RoleID.
        /// </summary>
        /// <param name="userIDsToRemove">ArrayList with UserIDs of the users to Remove</param>
        /// <param name="roleID">ID of role the users will be removed from</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool RemoveUsersFromRole(List<int> userIDsToRemove, int roleID)
        {
            if(userIDsToRemove.Count<=0)
            {
                return true;
            }

            // we'll delete all role-user combinations for the users in the given range plus for the given role.
            // if there's just one user, we'll use an optimization, as the range query will result in an IN (param, param... ) query,
            // and an field IN (param) query, is much slower compared to field = param, at least on Sqlserver.

            // produce the filter which will be used to filter out the entities to delete.
            PredicateExpression filter = new PredicateExpression();
            if(userIDsToRemove.Count == 1)
            {
                // use compare value predicate instead
                filter.Add((RoleUserFields.UserID == userIDsToRemove[0]));
            }
            else
            {
                // add a range filter
                filter.Add((RoleUserFields.UserID == userIDsToRemove));
            }
            // add the filter for the role as with AND.
            filter.AddWithAnd((RoleUserFields.RoleID == roleID));

            // delete the entities directly from the database. As this gives a single DELETE statement, we don't have to start a transaction manually.
            RoleUserCollection roleUsers = new RoleUserCollection();
            return (roleUsers.DeleteMulti(filter) > 0);
        }
コード例 #12
0
ファイル: SecurityManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Deletes the given role from the system.
        /// </summary>
        /// <param name="roleID">ID of role to delete</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteRole(int roleID)
        {
            RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID);
            if(toDelete == null)
            {
                // not found
                return false;
            }

            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole");

            try
            {
                // remove the role - forum - action right entities
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID);

                // Remove role-audit action entities
                RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
                trans.Add(roleAuditActions);
                roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID);

                // remove Role - systemright entities
                RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection();
                trans.Add(roleSystemRights);
                roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);

                // remove Role - user entities
                RoleUserCollection roleUsers = new RoleUserCollection();
                trans.Add(roleUsers);
                roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID);

                // delete the actual role
                trans.Add(toDelete);
                toDelete.Delete();
                trans.Commit();
                return true;
            }
            catch
            {
                // error occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }