Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the "simple" permissions management page #623

Merged
merged 1 commit into from Jul 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 4 additions & 23 deletions sources/admin/ManagePermissions.php
Expand Up @@ -511,23 +511,11 @@ public function action_modify()
require_once(SUBSDIR . '/ManagePermissions.subs.php');
$context['group']['id'] = (int) $_GET['group'];

// Are they toggling the view?
if (isset($_GET['view']))
{
$context['admin_preferences']['pv'] = $_GET['view'] == 'classic' ? 'classic' : 'simple';

// Update the users preferences.
require_once(SUBSDIR . '/Admin.subs.php');
updateAdminPreferences();
}

$context['view_type'] = !empty($context['admin_preferences']['pv']) && $context['admin_preferences']['pv'] == 'classic' ? 'classic' : 'simple';

// It's not likely you'd end up here with this setting disabled.
if ($_GET['group'] == 1)
redirectexit('action=admin;area=permissions');

loadAllPermissions($context['view_type']);
loadAllPermissions();
loadPermissionProfiles();

if ($context['group']['id'] > 0)
Expand Down Expand Up @@ -592,20 +580,13 @@ public function action_modify()
{
// Create a shortcut for the current permission.
$curPerm = &$context['permissions'][$permissionType]['columns'][$position][$permissionGroup]['permissions'][$perm['id']];
if ($tmp['view'] == 'classic')
if ($perm['has_own_any'])
{
if ($perm['has_own_any'])
{
$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
}
else
$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'denied' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
}
else
{
$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'denied' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
}
}
}
}
Expand Down
281 changes: 115 additions & 166 deletions sources/subs/ManagePermissions.subs.php
Expand Up @@ -385,146 +385,119 @@ function loadPermissionProfiles()
/**
* Load permissions into $context['permissions'].
* @internal
*
* @param string $loadType options: 'classic' or 'simple'
*/
function loadAllPermissions($loadType = 'classic')
function loadAllPermissions()
{
global $context, $txt, $modSettings;

// List of all the groups dependant on the currently selected view - for the order so it looks pretty, yea?
// List of all the groups
// Note to Mod authors - you don't need to stick your permission group here if you don't mind having it as the last group of the page.
$permissionGroups = array(
'membergroup' => array(
'simple' => array(
'view_basic_info',
'disable_censor',
'use_pm_system',
'post_calendar',
'edit_profile',
'delete_account',
'use_avatar',
'moderate_general',
'administrate',
),
'classic' => array(
'general',
'pm',
'calendar',
'maintenance',
'member_admin',
'profile',
),
'general',
'pm',
'calendar',
'maintenance',
'member_admin',
'profile',
),
'board' => array(
'simple' => array(
'make_posts',
'make_unapproved_posts',
'post_polls',
'participate',
'modify',
'notification',
'attach',
'moderate',
),
'classic' => array(
'general_board',
'topic',
'post',
'poll',
'notification',
'attachment',
),
'general_board',
'topic',
'post',
'poll',
'notification',
'attachment',
),
);

/* The format of this list is as follows:
'membergroup' => array(
'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*),
'permissions_inside' => array(has_multiple_options, view_group),
),
'board' => array(
'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*),
'permissions_inside' => array(has_multiple_options, view_group),
);
*/
$permissionList = array(
'membergroup' => array(
'view_stats' => array(false, 'general', 'view_basic_info'),
'view_mlist' => array(false, 'general', 'view_basic_info'),
'who_view' => array(false, 'general', 'view_basic_info'),
'search_posts' => array(false, 'general', 'view_basic_info'),
'karma_edit' => array(false, 'general', 'moderate_general'),
'like_posts' => array(false, 'general', 'moderate_general'),
'disable_censor' => array(false, 'general', 'disable_censor'),
'pm_read' => array(false, 'pm', 'use_pm_system'),
'pm_send' => array(false, 'pm', 'use_pm_system'),
'pm_draft' => array(false, 'pm', 'use_pm_system'),
'pm_autosave_draft' => array(false, 'pm', 'use_pm_system'),
'send_email_to_members' => array(false, 'pm', 'use_pm_system'),
'calendar_view' => array(false, 'calendar', 'view_basic_info'),
'calendar_post' => array(false, 'calendar', 'post_calendar'),
'calendar_edit' => array(true, 'calendar', 'post_calendar', 'moderate_general'),
'admin_forum' => array(false, 'maintenance', 'administrate'),
'manage_boards' => array(false, 'maintenance', 'administrate'),
'manage_attachments' => array(false, 'maintenance', 'administrate'),
'manage_smileys' => array(false, 'maintenance', 'administrate'),
'edit_news' => array(false, 'maintenance', 'administrate'),
'access_mod_center' => array(false, 'maintenance', 'moderate_general'),
'moderate_forum' => array(false, 'member_admin', 'moderate_general'),
'manage_membergroups' => array(false, 'member_admin', 'administrate'),
'manage_permissions' => array(false, 'member_admin', 'administrate'),
'manage_bans' => array(false, 'member_admin', 'administrate'),
'send_mail' => array(false, 'member_admin', 'administrate'),
'issue_warning' => array(false, 'member_admin', 'moderate_general'),
'profile_view' => array(true, 'profile', 'view_basic_info', 'view_basic_info'),
'profile_identity' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_extra' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_title' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_remove' => array(true, 'profile', 'delete_account', 'moderate_general'),
'profile_server_avatar' => array(false, 'profile', 'use_avatar'),
'profile_upload_avatar' => array(false, 'profile', 'use_avatar'),
'profile_remote_avatar' => array(false, 'profile', 'use_avatar'),
'approve_emails' => array(false, 'member_admin', 'administrate'),
'view_stats' => array(false, 'general'),
'view_mlist' => array(false, 'general'),
'who_view' => array(false, 'general'),
'search_posts' => array(false, 'general'),
'karma_edit' => array(false, 'general'),
'like_posts' => array(false, 'general'),
'disable_censor' => array(false, 'general'),
'pm_read' => array(false, 'pm'),
'pm_send' => array(false, 'pm'),
'pm_draft' => array(false, 'pm'),
'pm_autosave_draft' => array(false, 'pm'),
'send_email_to_members' => array(false, 'pm'),
'calendar_view' => array(false, 'calendar'),
'calendar_post' => array(false, 'calendar'),
'calendar_edit' => array(true, 'calendar'),
'admin_forum' => array(false, 'maintenance'),
'manage_boards' => array(false, 'maintenance'),
'manage_attachments' => array(false, 'maintenance'),
'manage_smileys' => array(false, 'maintenance'),
'edit_news' => array(false, 'maintenance'),
'access_mod_center' => array(false, 'maintenance'),
'moderate_forum' => array(false, 'member_admin'),
'manage_membergroups' => array(false, 'member_admin'),
'manage_permissions' => array(false, 'member_admin'),
'manage_bans' => array(false, 'member_admin'),
'send_mail' => array(false, 'member_admin'),
'issue_warning' => array(false, 'member_admin'),
'profile_view' => array(true, 'profile'),
'profile_identity' => array(true, 'profile'),
'profile_extra' => array(true, 'profile'),
'profile_title' => array(true, 'profile'),
'profile_remove' => array(true, 'profile'),
'profile_server_avatar' => array(false, 'profile'),
'profile_upload_avatar' => array(false, 'profile'),
'profile_remote_avatar' => array(false, 'profile'),
'approve_emails' => array(false, 'member_admin'),
),
'board' => array(
'moderate_board' => array(false, 'general_board', 'moderate'),
'approve_posts' => array(false, 'general_board', 'moderate'),
'post_new' => array(false, 'topic', 'make_posts'),
'post_draft' => array(false, 'topic', 'make_posts'),
'post_autosave_draft' => array(false, 'topic', 'make_posts'),
'post_unapproved_topics' => array(false, 'topic', 'make_unapproved_posts'),
'post_unapproved_replies' => array(true, 'topic', 'make_unapproved_posts', 'make_unapproved_posts'),
'post_reply' => array(true, 'topic', 'make_posts', 'make_posts'),
'merge_any' => array(false, 'topic', 'moderate'),
'split_any' => array(false, 'topic', 'moderate'),
'send_topic' => array(false, 'topic', 'moderate'),
'make_sticky' => array(false, 'topic', 'moderate'),
'move' => array(true, 'topic', 'moderate', 'moderate'),
'lock' => array(true, 'topic', 'moderate', 'moderate'),
'remove' => array(true, 'topic', 'modify', 'moderate'),
'modify_replies' => array(false, 'topic', 'moderate'),
'delete_replies' => array(false, 'topic', 'moderate'),
'announce_topic' => array(false, 'topic', 'moderate'),
'delete' => array(true, 'post', 'modify', 'moderate'),
'modify' => array(true, 'post', 'modify', 'moderate'),
'report_any' => array(false, 'post', 'participate'),
'poll_view' => array(false, 'poll', 'participate'),
'poll_vote' => array(false, 'poll', 'participate'),
'poll_post' => array(false, 'poll', 'post_polls'),
'poll_add' => array(true, 'poll', 'post_polls', 'moderate'),
'poll_edit' => array(true, 'poll', 'modify', 'moderate'),
'poll_lock' => array(true, 'poll', 'moderate', 'moderate'),
'poll_remove' => array(true, 'poll', 'modify', 'moderate'),
'mark_any_notify' => array(false, 'notification', 'notification'),
'mark_notify' => array(false, 'notification', 'notification'),
'view_attachments' => array(false, 'attachment', 'participate'),
'post_unapproved_attachments' => array(false, 'attachment', 'make_unapproved_posts'),
'post_attachment' => array(false, 'attachment', 'attach'),
'postby_email' => array(false, 'topic', 'make_posts'),
'like_posts' => array(false, 'topic', 'participate'),
'moderate_board' => array(false, 'general_board'),
'approve_posts' => array(false, 'general_board'),
'post_new' => array(false, 'topic'),
'post_draft' => array(false, 'topic'),
'post_autosave_draft' => array(false, 'topic'),
'post_unapproved_topics' => array(false, 'topic'),
'post_unapproved_replies' => array(true, 'topic'),
'post_reply' => array(true, 'topic'),
'merge_any' => array(false, 'topic'),
'split_any' => array(false, 'topic'),
'send_topic' => array(false, 'topic'),
'make_sticky' => array(false, 'topic'),
'move' => array(true, 'topic'),
'lock' => array(true, 'topic'),
'remove' => array(true, 'topic'),
'modify_replies' => array(false, 'topic'),
'delete_replies' => array(false, 'topic'),
'announce_topic' => array(false, 'topic'),
'delete' => array(true, 'post'),
'modify' => array(true, 'post'),
'report_any' => array(false, 'post'),
'poll_view' => array(false, 'poll'),
'poll_vote' => array(false, 'poll'),
'poll_post' => array(false, 'poll'),
'poll_add' => array(true, 'poll'),
'poll_edit' => array(true, 'poll'),
'poll_lock' => array(true, 'poll'),
'poll_remove' => array(true, 'poll'),
'mark_any_notify' => array(false, 'notification'),
'mark_notify' => array(false, 'notification'),
'view_attachments' => array(false, 'attachment'),
'post_unapproved_attachments' => array(false, 'attachment'),
'post_attachment' => array(false, 'attachment'),
'postby_email' => array(false, 'topic'),
'like_posts' => array(false, 'topic'),
),
);

// All permission groups that will be shown in the left column on classic view.
// All permission groups that will be shown in the left column.
$leftPermissionGroups = array(
'general',
'calendar',
Expand Down Expand Up @@ -608,7 +581,6 @@ function loadAllPermissions($loadType = 'classic')
{
$context['permissions'][$permissionType] = array(
'id' => $permissionType,
'view' => $loadType,
'columns' => array()
);
foreach ($permissionList as $permission => $permissionArray)
Expand All @@ -618,76 +590,53 @@ function loadAllPermissions($loadType = 'classic')
continue;

// What groups will this permission be in?
$own_group = $permissionArray[($loadType == 'classic' ? 1 : 2)];
$any_group = $loadType == 'simple' && !empty($permissionArray[3]) ? $permissionArray[3] : ($loadType == 'simple' && $permissionArray[0] ? $permissionArray[2] : '');
$own_group = $permissionArray[1];

// First, Do these groups actually exist - if not add them.
if (!isset($permissionGroups[$permissionType][$loadType][$own_group]))
$permissionGroups[$permissionType][$loadType][$own_group] = true;
if (!empty($any_group) && !isset($permissionGroups[$permissionType][$loadType][$any_group]))
$permissionGroups[$permissionType][$loadType][$any_group] = true;
if (!isset($permissionGroups[$permissionType][$own_group]))
$permissionGroups[$permissionType][$own_group] = true;

// What column should this be located into?
$position = $loadType == 'classic' && !in_array($own_group, $leftPermissionGroups) ? 1 : 0;
$position = !in_array($own_group, $leftPermissionGroups) ? 1 : 0;

// If the groups have not yet been created be sure to create them.
$bothGroups = array('own' => $own_group);
$bothGroups = array();

// For guests, just reset the array.
if (!isset($context['group']['id']) || !($context['group']['id'] == -1 && $any_group))
// Guests can have only any, registered users both
if (!isset($context['group']['id']) || !($context['group']['id'] == -1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intention of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the comment says. :P (I hope 👼 )

Guests can have only the "any" permissions and since all the permissions are "any" by default unless otherwise, this checks that the group is set and is not -1 to add the "own".
Yes, the if is a bit screwed, may be:

if (!isset($context['group']['id']) || $context['group']['id'] != -1)

$any_group doesn't exist any more because it was true only for some permissions in the 'simple' view (see https://github.com/elkarte/Elkarte/pull/623/files#L1L622)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there is an else, then maybe:

if (isset($context['group']['id']) && $context['group']['id'] == -1)
$bothGroups['any'] = $own_group;
else
$bothGroups['own'] = $own_group;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, thank you. That's logically equivalent and easier to read. No biggie though. Lets see how it works and maybe indeed we'll simplify the expression.

$bothGroups['own'] = $own_group;

if ($any_group)
{
$bothGroups['any'] = $any_group;

}
else
$bothGroups['any'] = $own_group;

foreach ($bothGroups as $group)
if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]))
if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]['type']))
$context['permissions'][$permissionType]['columns'][$position][$group] = array(
'type' => $permissionType,
'id' => $group,
'name' => $loadType == 'simple' ? (isset($txt['permissiongroup_simple_' . $group]) ? $txt['permissiongroup_simple_' . $group] : '') : $txt['permissiongroup_' . $group],
'name' => $txt['permissiongroup_' . $group],
'icon' => isset($txt['permissionicon_' . $group]) ? $txt['permissionicon_' . $group] : $txt['permissionicon'],
'help' => isset($txt['permissionhelp_' . $group]) ? $txt['permissionhelp_' . $group] : '',
'hidden' => false,
'permissions' => array()
);

// This is where we set up the permission dependant on the view.
if ($loadType == 'classic')
{
$context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array(
'id' => $permission,
'name' => !isset($relabelPermissions[$permission]) ? $txt['permissionname_' . $permission] : $txt[$relabelPermissions[$permission]],
'show_help' => isset($txt['permissionhelp_' . $permission]),
'note' => isset($txt['permissionnote_' . $permission]) ? $txt['permissionnote_' . $permission] : '',
'has_own_any' => $permissionArray[0],
'own' => array(
'id' => $permission . '_own',
'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_own'] : ''
),
'any' => array(
'id' => $permission . '_any',
'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_any'] : ''
),
'hidden' => in_array($permission, $hiddenPermissions),
);
}
else
{
foreach ($bothGroups as $group_type => $group)
{
$context['permissions'][$permissionType]['columns'][$position][$group]['permissions'][$permission . ($permissionArray[0] ? '_' . $group_type : '')] = array(
'id' => $permission . ($permissionArray[0] ? '_' . $group_type : ''),
'name' => isset($txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')]) ? $txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')] : $txt['permissionname_' . $permission],
'help_index' => isset($txt['permissionhelp_' . $permission]) ? 'permissionhelp_' . $permission : '',
'hidden' => in_array($permission, $hiddenPermissions),
);
}
}
// This is where we set up the permission.
$context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array(
'id' => $permission,
'name' => !isset($relabelPermissions[$permission]) ? $txt['permissionname_' . $permission] : $txt[$relabelPermissions[$permission]],
'show_help' => isset($txt['permissionhelp_' . $permission]),
'note' => isset($txt['permissionnote_' . $permission]) ? $txt['permissionnote_' . $permission] : '',
'has_own_any' => $permissionArray[0],
'own' => array(
'id' => $permission . '_own',
'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_own'] : ''
),
'any' => array(
'id' => $permission . '_any',
'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_any'] : ''
),
'hidden' => in_array($permission, $hiddenPermissions),
);

if (in_array($permission, $hiddenPermissions))
{
Expand Down