- blabla, additional bugfixing permissions...

git-svn-id: file:///svn/phpbb/trunk@5580 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-02-24 17:33:42 +00:00
parent 37e0e0a4da
commit 724b37ae97
8 changed files with 111 additions and 65 deletions

View file

@ -194,7 +194,7 @@
<!-- ENDIF --> <!-- ENDIF -->
</td> </td>
<td style="vertical-align: top; white-space: nowrap;"><a href="{roles.U_EDIT}">{L_EDIT_ROLE}</a></td> <td style="vertical-align: top; white-space: nowrap;"><a href="{roles.U_EDIT}">{L_EDIT_ROLE}</a></td>
<td style="vertical-align: top; white-space: nowrap;"><a href="{roles.U_DISPLAY_ITEMS}">{L_VIEW_ASSIGNED_ITEMS}</a></td> <td style="vertical-align: top; white-space: nowrap;"><!-- IF roles.U_DISPLAY_ITEMS --><a href="{roles.U_DISPLAY_ITEMS}">{L_VIEW_ASSIGNED_ITEMS}</a><!-- ELSE -->{L_VIEW_ASSIGNED_ITEMS}<!-- ENDIF --></td>
<td style="vertical-align: top; white-space: nowrap;"><a href="{roles.U_REMOVE}">{L_REMOVE_ROLE}</a></td> <td style="vertical-align: top; white-space: nowrap;"><a href="{roles.U_REMOVE}">{L_REMOVE_ROLE}</a></td>
</tr> </tr>
<!-- END roles --> <!-- END roles -->

View file

@ -111,7 +111,7 @@ class acp_permission_roles
if (confirm_box(true)) if (confirm_box(true))
{ {
$this->remove_role($role_id); $this->remove_role($role_id, $permission_type);
add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_REMOVED', $role_row['role_name']); add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_REMOVED', $role_row['role_name']);
trigger_error($user->lang['ROLE_DELETED'] . adm_back_link($this->u_action)); trigger_error($user->lang['ROLE_DELETED'] . adm_back_link($this->u_action));
@ -189,9 +189,12 @@ class acp_permission_roles
if (!$row['negate'] && !isset($row['name'])) if (!$row['negate'] && !isset($row['name']))
{ {
foreach ($groups[$row['type']] as $group_id => $group_name) if (isset($groups[$row['type']]))
{ {
$role_group_ids[] = $group_id; foreach ($groups[$row['type']] as $group_id => $group_name)
{
$role_group_ids[] = $group_id;
}
} }
} }
else if ($row['negate'] && !isset($row['name'])) else if ($row['negate'] && !isset($row['name']))
@ -201,6 +204,11 @@ class acp_permission_roles
foreach ($group_types as $type) foreach ($group_types as $type)
{ {
if (!isset($groups[$type]))
{
continue;
}
foreach ($groups[$type] as $group_id => $group_name) foreach ($groups[$type] as $group_id => $group_name)
{ {
$role_group_ids[] = $group_id; $role_group_ids[] = $group_id;
@ -223,6 +231,11 @@ class acp_permission_roles
foreach ($group_types as $type) foreach ($group_types as $type)
{ {
if (!isset($groups[$type]))
{
continue;
}
foreach ($groups[$type] as $group_id => $group_name) foreach ($groups[$type] as $group_id => $group_name)
{ {
if ($type != $row['type']) if ($type != $row['type'])
@ -421,7 +434,11 @@ class acp_permission_roles
if (sizeof($hold_ary)) if (sizeof($hold_ary))
{ {
$template->assign_var('S_DISPLAY_ROLE_MASK', true); $template->assign_var(array(
'S_DISPLAY_ROLE_MASK' => true,
'L_ROLE_ASSIGNED_TO' => sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_row['role_name']))
);
$auth_admin->display_role_mask($hold_ary); $auth_admin->display_role_mask($hold_ary);
} }
} }
@ -466,6 +483,9 @@ class acp_permission_roles
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
// Display assigned items?
$display_item = request_var('display_item', 0);
$s_role_options = ''; $s_role_options = '';
foreach ($roles as $row) foreach ($roles as $row)
{ {
@ -476,7 +496,7 @@ class acp_permission_roles
'U_EDIT' => $this->u_action . '&amp;action=edit&amp;role_id=' . $row['role_id'], 'U_EDIT' => $this->u_action . '&amp;action=edit&amp;role_id=' . $row['role_id'],
'U_REMOVE' => $this->u_action . '&amp;action=remove&amp;role_id=' . $row['role_id'], 'U_REMOVE' => $this->u_action . '&amp;action=remove&amp;role_id=' . $row['role_id'],
'U_DISPLAY_ITEMS' => $this->u_action . '&amp;display_item=' . $row['role_id'] . '#assigned_to') 'U_DISPLAY_ITEMS' => ($row['role_id'] == $display_item) ? '' : $this->u_action . '&amp;display_item=' . $row['role_id'] . '#assigned_to')
); );
if (isset($groups[$row['role_id']]) && sizeof($groups[$row['role_id']])) if (isset($groups[$row['role_id']]) && sizeof($groups[$row['role_id']]))
@ -492,18 +512,24 @@ class acp_permission_roles
} }
$s_role_options .= '<option value="' . $row['role_id'] . '">' . $row['role_name'] . '</option>'; $s_role_options .= '<option value="' . $row['role_id'] . '">' . $row['role_name'] . '</option>';
if ($display_item == $row['role_id'])
{
$template->assign_vars(array(
'L_ROLE_ASSIGNED_TO' => sprintf($user->lang['ROLE_ASSIGNED_TO'], $row['role_name']))
);
}
} }
$template->assign_vars(array( $template->assign_vars(array(
'S_ROLE_OPTIONS' => $s_role_options) 'S_ROLE_OPTIONS' => $s_role_options)
); );
// Display assigned items?
$display_item = request_var('display_item', 0);
if ($display_item) if ($display_item)
{ {
$template->assign_var('S_DISPLAY_ROLE_MASK', true); $template->assign_vars(array(
'S_DISPLAY_ROLE_MASK' => true)
);
$hold_ary = $auth_admin->get_role_mask($display_item); $hold_ary = $auth_admin->get_role_mask($display_item);
$auth_admin->display_role_mask($hold_ary); $auth_admin->display_role_mask($hold_ary);
@ -662,11 +688,19 @@ class acp_permission_roles
} }
} }
foreach ($group_types as $type) if ($s_selected)
{ {
if (!isset($selected_groups[$type]) || sizeof($selected_groups[$type]) != sizeof($groups[$type])) foreach ($group_types as $type)
{ {
$s_selected = false; if (!isset($groups[$type]))
{
continue;
}
if (!isset($selected_groups[$type]) || sizeof($selected_groups[$type]) != sizeof($groups[$type]))
{
$s_selected = false;
}
} }
} }
} }
@ -687,20 +721,32 @@ class acp_permission_roles
/** /**
* Remove role * Remove role
*/ */
function remove_role($role_id) function remove_role($role_id, $permission_type)
{ {
global $db; global $db;
$auth_admin = new auth_admin(); $auth_admin = new auth_admin();
// First of all, get the role auth settings we need to re-set... // Get complete auth array
$sql = 'SELECT auth_option, auth_option_id
FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option LIKE '" . $db->sql_escape($permission_type) . "%'";
$result = $db->sql_query($sql);
$auth_settings = array();
while ($row = $db->sql_fetchrow($result))
{
$auth_settings[$row['auth_option']] = ACL_UNSET;
}
$db->sql_freeresult($result);
// Get the role auth settings we need to re-set...
$sql = 'SELECT o.auth_option, r.auth_setting $sql = 'SELECT o.auth_option, r.auth_setting
FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
WHERE o.auth_option_id = r.auth_option_id WHERE o.auth_option_id = r.auth_option_id
AND r.role_id = ' . $role_id; AND r.role_id = ' . $role_id;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$auth_settings = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$auth_settings[$row['auth_option']] = $row['auth_setting']; $auth_settings[$row['auth_option']] = $row['auth_setting'];
@ -710,7 +756,21 @@ class acp_permission_roles
// Get role assignments // Get role assignments
$hold_ary = $auth_admin->get_role_mask($role_id); $hold_ary = $auth_admin->get_role_mask($role_id);
// Remove role from users and groups // Re-assign permisisons
foreach ($hold_ary as $forum_id => $forum_ary)
{
if (isset($forum_ary['users']))
{
$auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false);
}
if (isset($forum_ary['groups']))
{
$auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false);
}
}
// Remove role from users and groups just to be sure (happens through acl_set)
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . ' $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
WHERE auth_role_id = ' . $role_id; WHERE auth_role_id = ' . $role_id;
$db->sql_query($sql); $db->sql_query($sql);
@ -719,20 +779,6 @@ class acp_permission_roles
WHERE auth_role_id = ' . $role_id; WHERE auth_role_id = ' . $role_id;
$db->sql_query($sql); $db->sql_query($sql);
// Re-assign permisisons
foreach ($hold_ary as $forum_id => $forum_ary)
{
if (isset($forum_ary['users']))
{
$auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings);
}
if (isset($forum_ary['groups']))
{
$auth_admin->acl_set('group', $forum_id, $forum_ary['users'], $auth_settings);
}
}
// Remove role data and role // Remove role data and role
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE role_id = ' . $role_id; WHERE role_id = ' . $role_id;
@ -741,6 +787,8 @@ class acp_permission_roles
$sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '
WHERE role_id = ' . $role_id; WHERE role_id = ' . $role_id;
$db->sql_query($sql); $db->sql_query($sql);
$auth_admin->acl_clear_prefetch();
} }
} }

View file

@ -47,6 +47,20 @@ class auth_admin extends auth
$cache->put('acl_options', $this->acl_options); $cache->put('acl_options', $this->acl_options);
} }
if (!sizeof($this->option_ids))
{
$sql = 'SELECT auth_option_id, auth_option
FROM ' . ACL_OPTIONS_TABLE;
$result = $db->sql_query($sql);
$this->option_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$this->option_ids[$row['auth_option']] = $row['auth_option_id'];
}
$db->sql_freeresult($result);
}
} }
/** /**
@ -662,20 +676,6 @@ class auth_admin extends auth
$ug_id = array($ug_id); $ug_id = array($ug_id);
} }
if (!sizeof($this->option_ids))
{
$sql = 'SELECT auth_option_id, auth_option
FROM ' . ACL_OPTIONS_TABLE;
$result = $db->sql_query($sql);
$this->option_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$this->option_ids[$row['auth_option']] = $row['auth_option_id'];
}
$db->sql_freeresult($result);
}
$ug_id_sql = 'IN (' . implode(', ', array_map('intval', $ug_id)) . ')'; $ug_id_sql = 'IN (' . implode(', ', array_map('intval', $ug_id)) . ')';
$forum_sql = 'IN (' . implode(', ', array_map('intval', $forum_id)) . ') '; $forum_sql = 'IN (' . implode(', ', array_map('intval', $forum_id)) . ') ';
@ -781,20 +781,6 @@ class auth_admin extends auth
{ {
global $db; global $db;
if (!sizeof($this->option_ids))
{
$sql = 'SELECT auth_option_id, auth_option
FROM ' . ACL_OPTIONS_TABLE;
$result = $db->sql_query($sql);
$this->option_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$this->option_ids[$row['auth_option']] = $row['auth_option_id'];
}
$db->sql_freeresult($result);
}
// Remove current auth options... // Remove current auth options...
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE role_id = ' . $role_id; WHERE role_id = ' . $role_id;

View file

@ -130,7 +130,7 @@ function user_delete($mode, $user_id)
if (!function_exists('delete_posts')) if (!function_exists('delete_posts'))
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
} }
$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts

View file

@ -602,6 +602,11 @@ function mcp_delete_post($post_ids)
if (confirm_box(true)) if (confirm_box(true))
{ {
if (!function_exists('delete_posts'))
{
include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
}
// Count the number of topics that are affected // Count the number of topics that are affected
// I did not use COUNT(DISTINCT ...) because I remember having problems // I did not use COUNT(DISTINCT ...) because I remember having problems
// with it on older versions of MySQL -- Ashe // with it on older versions of MySQL -- Ashe

View file

@ -613,6 +613,11 @@ function disapprove_post($post_id_list)
if (sizeof($post_disapprove_sql)) if (sizeof($post_disapprove_sql))
{ {
if (!function_exists('delete_posts'))
{
include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
}
// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
delete_posts('post_id', $post_disapprove_sql); delete_posts('post_id', $post_disapprove_sql);
} }

View file

@ -129,7 +129,7 @@ $lang = array_merge($lang, array(
'REMOVE_ROLE' => 'Remove Role', 'REMOVE_ROLE' => 'Remove Role',
'ROLE' => 'Role', 'ROLE' => 'Role',
'ROLE_ADD_SUCCESS' => 'Role successfully added.', 'ROLE_ADD_SUCCESS' => 'Role successfully added.',
'ROLE_ASSIGNED_TO' => 'Role assigned to', 'ROLE_ASSIGNED_TO' => 'Users/Groups assigned to %s',
'ROLE_DELETED' => 'Role successfully removed.', 'ROLE_DELETED' => 'Role successfully removed.',
'ROLE_DETAILS' => 'Role Details', 'ROLE_DETAILS' => 'Role Details',
'ROLE_EDIT_SUCCESS' => 'Role successfully edited.', 'ROLE_EDIT_SUCCESS' => 'Role successfully edited.',

View file

@ -1177,13 +1177,15 @@ page_footer();
*/ */
function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) function delete_post($mode, $post_id, $topic_id, $forum_id, &$data)
{ {
global $db, $user, $config, $auth, $phpEx, $SID; global $db, $user, $config, $auth, $phpEx, $SID, $phpbb_root_path;
// Specify our post mode // Specify our post mode
$post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete')); $post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete'));
$sql_data = array(); $sql_data = array();
$next_post_id = 0; $next_post_id = 0;
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
$db->sql_transaction(); $db->sql_transaction();
if (!delete_posts('post_id', array($post_id), false)) if (!delete_posts('post_id', array($post_id), false))