MyBB Community Forums

Full Version: Removing moderator on forum is reseting gid
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
I actually didn't post a fix but I guess I could.

Here is a rewritten admin/modules/forums/management.php

Use at your own risk but I have tested it pretty well.

Here are the 2 replacement functions.

if($mybb->input['action'] == "deletemod")
{
	$plugins->run_hooks("admin_forum_management_deletemod");
	
	$query = $db->simple_select("moderators", "*", "uid='{$mybb->input['uid']}' AND fid='{$mybb->input['fid']}'");
	$mod = $db->fetch_array($query);
	
	// Does the forum not exist?
	if(!$mod['mid'])
	{
		flash_message($lang->error_invalid_moderator, 'error');
		admin_redirect("index.php?module=forum/management&fid=".$mybb->input['fid']);
	}
	
	// User clicked no
	if($mybb->input['no'])
	{
		admin_redirect("index.php?module=forum/management&fid=".$mybb->input['fid']);
	}
	
	if($mybb->request_method == "post")
	{
		$mid = $mod['mid'];
		$query = $db->query("
			SELECT m.*, u.username, u.usergroup, u.additionalgroups
			FROM ".TABLE_PREFIX."moderators m 
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=m.uid)
			WHERE m.mid='{$mid}'
		");
		$mod = $db->fetch_array($query);
		
		$db->delete_query("moderators", "mid='{$mid}'");
		$query = $db->simple_select("moderators", "*", "uid='{$mod['uid']}'");
		if($db->num_rows($query) == 0)
		{

			$additionalgroups = explode(",", $mod['additionalgroups']);

			if (!in_array("6", $additionalgroups));
				foreach($additionalgroups as $key => $value) {
				if ($value == "6") unset($additionalgroups[$key]);
			}

			$additionalgroups = implode(",", $additionalgroups);

			$updatequery = array(

				"additionalgroups" => $additionalgroups
			);
			$db->update_query("users", $updatequery, "uid='{$mod['uid']}' AND usergroup != '4' AND usergroup != '3'");
		}
		$cache->update_moderators();
		
		$plugins->run_hooks("admin_forum_management_deletemod_commit");
		
		$forum = get_forum($mybb->input['fid']);
		
		// Log admin action
		log_admin_action($mod['uid'], $mod['username'], $forum['fid'], $forum['name']);
		
		flash_message($lang->success_moderator_deleted, 'success');
		admin_redirect("index.php?module=forum/management&fid=".$mybb->input['fid']."#tab_moderators");
	}
	else
	{
		$page->output_confirm_action("index.php?module=forum/management&action=deletemod&fid={$mod['fid']}&uid={$mod['uid']}", $lang->confirm_moderator_deletion);
	}
}

		elseif($mybb->input['add'] == "moderators")
		{
			
			$forum = get_forum($fid);
			if(!$forum)
			{
				flash_message($lang->error_invalid_forum, 'error');
				admin_redirect("index.php?module=forum/management&fid={$fid}#tab_moderators");
			}
			$query = $db->simple_select("users", "uid, username, usergroup, additionalgroups", "username='".$db->escape_string($mybb->input['username'])."'", array('limit' => 1));
			$user = $db->fetch_array($query);
			if($user['uid'])
			{
				$query = $db->simple_select("moderators", "uid", "uid='".$user['uid']."' AND fid='".$fid."'", array('limit' => 1));
				$mod = $db->fetch_array($query);
				if(!$mod['uid'])
				{
					$new_mod = array(
						"fid" => $fid,
						"uid" => $user['uid'],
						"caneditposts" => 1,
						"candeleteposts" => 1,
						"canviewips" => 1,
						"canopenclosethreads" => 1,
						"canmanagethreads" => 1,
						"canmovetononmodforum" => 1
					);
					$mid = $db->insert_query("moderators", $new_mod);

					$additionalgroups = explode(",", $user['additionalgroups']);
					if(!in_array("6", $additionalgroups))
					{
						$additionalgroups[] = "6";
					}

					$additionalgroups = trim(implode(",", $additionalgroups), ",");

					$groupupdate = array("additionalgroups" => $additionalgroups);

					$db->update_query("users", $groupupdate, "uid='{$user['uid']}'");

					$cache->update_moderators();
					
					$plugins->run_hooks("admin_forum_management_start_moderators_commit");
					
					// Log admin action
					log_admin_action('addmod', $new_mod['fid'], $user['username'], $fid, $forum['name']);
					
					flash_message($lang->success_moderator_added, 'success');
					admin_redirect("index.php?module=forum/management&action=editmod&mid={$mid}");
				}
				else
				{
					flash_message($lang->error_moderator_already_added, 'error');
					admin_redirect("index.php?module=forum/management&fid={$fid}#tab_moderators");
				}
			}
			else
			{
				flash_message($lang->error_moderator_not_found, 'error');
				admin_redirect("index.php?module=forum/management&fid={$fid}#tab_moderators");
			}
		}

SQA please review them. This will basically make the forum moderator an additionalgroup. It takes into account if a member is already in additionalgroup 6. If member is a forum moderator for two forums and is removed from one they will remain in additionalgroup 6.

Thank you...I hope my changes get committed.
I tested the changes, labrocca, and they seemed to work OK and didn't have any problems. Although I'll leave it up to Ryan and management to decide really - it's a question on functionality, and I'm never really good on that sort of stuff... Toungue
(2009-07-13, 08:26 AM)Tomm M Wrote: [ -> ]/.../ Although I'll leave it up to Ryan and management to decide really - it's a question on functionality, and I'm never really good on that sort of stuff... Toungue

So hear the voice of people Wink
I think that if you are a moderator that your usergroup should reflect that. And I think that if you are removed from all forums as a moderator, then your usergroup should reflect that as well.
That doesn't make sense as labrocca said if you are a member of another privileged group, as it'll reset ALL your privileges to those of gid 2.
(2009-07-14, 03:08 AM)StingReay Wrote: [ -> ]That doesn't make sense as labrocca said if you are a member of another privileged group, as it'll reset ALL your privileges to those of gid 2.

As far as I am aware, you can only have one "usergroup" at a time. Display groups and additional groups are separate things. Also, as far as I am aware, we facilitate the "usergroup" when adding or removing a moderator from a forum, not the "additional groups".
Quote:I think that if you are a moderator that your usergroup should reflect that. And I think that if you are removed from all forums as a moderator, then your usergroup should reflect that as well.

If admin chooses he can make moderator display group allowed which is default anyways.

Quote:we facilitate the "usergroup" when adding or removing a moderator from a forum, not the "additional groups".

Yes and that creates problem behaviors as I have outlined in previous posts. Please read how my changes do not effect any actual moderator abilities not even the list of forum moderators displayed on index. What this does effect (and properly) is the group the member is assigned. A forum moderator is special and specific. It's almost not even a group.

Please read some of my previous posts in this thread carefully as I believe I outline the issue well. Keep in mind I didn't report this bug either. I just agree with it, had the same problems, and presented a fix. The changes I present are one file and fairly simple to implement. If you require an exact diff please let me know.
I do not have any information not already well on my English Big Grin I'm still wondering if the problem solution
Quote:as far as I am aware, we facilitate the "usergroup" when adding or removing a moderator from a forum, not the "additional groups".

That's what my fix changes.

The heart of the problem is that forum moderators are based off usergroup and unneccessarily. There is little reason for the behavior. Forum moderators can be additional usergroups just fine and if the member wants that as display group it can be achieved.

Now you might ask "well why is this a bug"...quite simple it's because adding someone as a forum moderator overwrites their usergroup no matter if they are in a special group or not. It's part bug and part bad behavior. One that can be fixed easily and will improve mybb.
Tiki, this isn't good logical understanding of moderator idea.
In MyBB moderator is:
- user, member of group gid=6
- user, who has privileges to moderate forum (but doesn't have to be member of group gid=6)
- user, who has privileges to moderate forum AND member of group gid=6.

labrocca's fix makes possible every above-cited option, so what's the problem? Smile
Pages: 1 2 3 4 5