Browse Source

! Groups that can manage boards will always have access to boards, the UI now won't let you think anything different. I haven't added a message but I'm not sure one is really needed. Try this, let me know. Ref #1196

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
22aa767e55

+ 14 - 0
Sources/ManageBoards.php

@@ -390,6 +390,11 @@ function EditBoard()
 	require_once($sourcedir . '/ManagePermissions.php');
 	loadPermissionProfiles();
 
+	// People with manage-boards are special.
+	require_once($sourcedir . '/Subs-Members.php');
+	$groups = groupsAllowedTo('manage_boards', null);
+	$context['board_managers'] = $groups['allowed']; // We don't need *all* this in $context.
+
 	// id_board must be a number....
 	$_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0;
 	if (!isset($boards[$_REQUEST['boardid']]))
@@ -659,6 +664,15 @@ function EditBoard2()
 					$boardOptions['deny_groups'][] = (int) $group;
 			}
 
+		// People with manage-boards are special.
+		require_once($sourcedir . '/Subs-Members.php');
+		$board_managers = groupsAllowedTo('manage_boards', null);
+		$board_managers = array_diff($board_managers['allowed'], array(1)); // We don't need to list admins anywhere.
+		// Firstly, we can't ever deny them.
+		$boardOptions['deny_groups'] = array_diff($boardOptions['deny_groups'], $board_managers);
+		// Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded.
+		$boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers));
+
 		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
 			fatal_lang_error('too_many_groups', false);
 

+ 4 - 4
Themes/default/ManageBoards.template.php

@@ -372,7 +372,7 @@ function template_modify_board()
 		if (empty($modSettings['deny_boards_access']))
 			echo '
 							<label for="groups_', $group['id'], '">
-								<input type="checkbox" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '"', $group['allow'] ? ' checked="checked"' : '', ' class="input_check" />
+								<input type="checkbox" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '"', in_array($group['id'], $context['board_managers']) ? ' checked disabled' : ($group['allow'] ? ' checked' : ''), ' class="input_check" />
 								<span', $group['is_post_group'] ? ' class="post_group" title="' . $txt['mboards_groups_post_group'] . '"' : ($group['id'] == 0 ? ' class="regular_members" title="' . $txt['mboards_groups_regular_members'] . '"' : ''), '>
 									', $group['name'], '
 								</span>
@@ -388,13 +388,13 @@ function template_modify_board()
 										</label>
 									</td>
 									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '_a"', $group['allow'] ? ' checked="checked"' : '', ' class="input_radio" />
+										<input type="radio" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '_a"', in_array($group['id'], $context['board_managers']) ? ' checked disabled' : ($group['allow'] ? ' checked' : ''), ' class="input_radio" />
 									</td>
 									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="ignore" id="groups_', $group['id'], '_x"', !$group['allow'] && !$group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
+										<input type="radio" name="groups[', $group['id'], ']" value="ignore" id="groups_', $group['id'], '_x"', in_array($group['id'], $context['board_managers']) ? ' disabled' : (!$group['allow'] && !$group['deny'] ? ' checked' : ''), ' class="input_radio" />
 									</td>
 									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="deny" id="groups_', $group['id'], '_d"', $group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
+										<input type="radio" name="groups[', $group['id'], ']" value="deny" id="groups_', $group['id'], '_d"', in_array($group['id'], $context['board_managers']) ? ' disabled' : ($group['deny'] ? ' checked' : ''), ' class="input_radio" />
 									</td>
 									<td></td>
 								</tr>';

+ 2 - 2
Themes/default/scripts/script.js

@@ -647,10 +647,10 @@ function selectRadioByName(oRadioGroup, sName)
 	return false;
 }
 
-function selectAllRadio(oInvertCheckbox, oForm, sMask, sValue)
+function selectAllRadio(oInvertCheckbox, oForm, sMask, sValue, bIgnoreDisabled)
 {
 	for (var i = 0; i < oForm.length; i++)
-		if (oForm[i].name != undefined && oForm[i].name.substr(0, sMask.length) == sMask && oForm[i].value == sValue)
+		if (oForm[i].name != undefined && oForm[i].name.substr(0, sMask.length) == sMask && oForm[i].value == sValue && (!oForm[i].disabled || (typeof(bIgnoreDisabled) == 'boolean' && bIgnoreDisabled)))
 			oForm[i].checked = true;
 }
 

+ 60 - 0
other/upgrade_2-1_mysql.sql

@@ -286,6 +286,66 @@ ALTER TABLE {$db_prefix}boards
 ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
 ---#
 
+/******************************************************************************/
+--- Updating board access rules
+/******************************************************************************/
+---# Updating board access rules
+---{
+$member_groups = array(
+	'allowed' => array(),
+	'denied' => array(),
+);
+
+$request = $smcFunc['db_query']('', '
+	SELECT id_group, add_deny
+	FROM {db_prefix}permissions
+	WHERE permission = {string:permission}',
+	array(
+		'permission' => 'manage_boards',
+	)
+);
+while ($row = $smcFunc['db_fetch_assoc']($request))
+	$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
+$smcFunc['db_free_result']($request);
+
+$member_groups = array_diff($member_groups['allowed'], $member_groups['denied']);
+
+if (!empty($member_groups))
+{
+	$count = count($member_groups);
+	$changes = array();
+
+	$request = $smcFunc['db_query']('', '
+		SELECT id_board, member_groups
+		FROM {db_prefix}boards');
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		$current_groups = explode(',', $row['member_groups']);
+		if (count(array_intersect($current_groups, $member_groups)) != $count)
+		{
+			$new_groups = array_unique(array_merge($current_groups, $member_groups));
+			$changes[$row['id_board']] = implode(',', $new_groups);
+		}
+	}
+	$smcFunc['db_free_result']($request);
+
+	if (!empty($changes))
+	{
+		foreach ($changes as $id_board => $member_groups)
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}boards
+				SET member_groups = {string:member_groups}
+					WHERE id_board = {int:id_board}',
+				array(
+					'member_groups' => $member_groups,
+					'id_board' => $id_board,
+				)
+			);
+	}
+}
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for category descriptions
 /******************************************************************************/

+ 60 - 0
other/upgrade_2-1_postgresql.sql

@@ -346,6 +346,66 @@ upgrade_query("
 ---}
 ---#
 
+/******************************************************************************/
+--- Updating board access rules
+/******************************************************************************/
+---# Updating board access rules
+---{
+$member_groups = array(
+	'allowed' => array(),
+	'denied' => array(),
+);
+
+$request = $smcFunc['db_query']('', '
+	SELECT id_group, add_deny
+	FROM {db_prefix}permissions
+	WHERE permission = {string:permission}',
+	array(
+		'permission' => 'manage_boards',
+	)
+);
+while ($row = $smcFunc['db_fetch_assoc']($request))
+	$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
+$smcFunc['db_free_result']($request);
+
+$member_groups = array_diff($member_groups['allowed'], $member_groups['denied']);
+
+if (!empty($member_groups))
+{
+	$count = count($member_groups);
+	$changes = array();
+
+	$request = $smcFunc['db_query']('', '
+		SELECT id_board, member_groups
+		FROM {db_prefix}boards');
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		$current_groups = explode(',', $row['member_groups']);
+		if (count(array_intersect($current_groups, $member_groups)) != $count)
+		{
+			$new_groups = array_unique(array_merge($current_groups, $member_groups));
+			$changes[$row['id_board']] = implode(',', $new_groups);
+		}
+	}
+	$smcFunc['db_free_result']($request);
+
+	if (!empty($changes))
+	{
+		foreach ($changes as $id_board => $member_groups)
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}boards
+				SET member_groups = {string:member_groups}
+					WHERE id_board = {int:id_board}',
+				array(
+					'member_groups' => $member_groups,
+					'id_board' => $id_board,
+				)
+			);
+	}
+}
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for category descriptions
 /******************************************************************************/

+ 60 - 0
other/upgrade_2-1_sqlite.sql

@@ -318,6 +318,66 @@ $smcFunc['db_alter_table']('{db_prefix}boards', array(
 ---}
 ---#
 
+/******************************************************************************/
+--- Updating board access rules
+/******************************************************************************/
+---# Updating board access rules
+---{
+$member_groups = array(
+	'allowed' => array(),
+	'denied' => array(),
+);
+
+$request = $smcFunc['db_query']('', '
+	SELECT id_group, add_deny
+	FROM {db_prefix}permissions
+	WHERE permission = {string:permission}',
+	array(
+		'permission' => 'manage_boards',
+	)
+);
+while ($row = $smcFunc['db_fetch_assoc']($request))
+	$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
+$smcFunc['db_free_result']($request);
+
+$member_groups = array_diff($member_groups['allowed'], $member_groups['denied']);
+
+if (!empty($member_groups))
+{
+	$count = count($member_groups);
+	$changes = array();
+
+	$request = $smcFunc['db_query']('', '
+		SELECT id_board, member_groups
+		FROM {db_prefix}boards');
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		$current_groups = explode(',', $row['member_groups']);
+		if (count(array_intersect($current_groups, $member_groups)) != $count)
+		{
+			$new_groups = array_unique(array_merge($current_groups, $member_groups));
+			$changes[$row['id_board']] = implode(',', $new_groups);
+		}
+	}
+	$smcFunc['db_free_result']($request);
+
+	if (!empty($changes))
+	{
+		foreach ($changes as $id_board => $member_groups)
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}boards
+				SET member_groups = {string:member_groups}
+					WHERE id_board = {int:id_board}',
+				array(
+					'member_groups' => $member_groups,
+					'id_board' => $id_board,
+				)
+			);
+	}
+}
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for category descriptions
 /******************************************************************************/