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

loadPermissionsBatch() does not entirely load permission profiles #8139

Open
live627 opened this issue Mar 16, 2024 · 1 comment
Open

loadPermissionsBatch() does not entirely load permission profiles #8139

live627 opened this issue Mar 16, 2024 · 1 comment

Comments

@live627
Copy link
Contributor

live627 commented Mar 16, 2024

it confused me at first because I left $profile null,, expeting no data to be loaded.

Anyway, here my code

		$group_data = Group::loadSimple(
			Group::LOAD_NORMAL | (int) !empty(Config::$modSettings['permission_enable_postgroups']),
			[Group::ADMIN, Group::MOD]
		);
		Group::loadPermissionsBatch(array_map(fn ($group) => $group->id, $group_data));

		foreach ($group_data as $data) {
			var_export([$data->name => $data->permissions['board_profiles']]);

Expected result

array (
  'Guests' => 
  array (
    1 => 
    array (
      'poll_view' => 1,
    ),
    2 => 
    array (
      'poll_view' => 1,
    ),
    3 => 
    array (
      'poll_view' => 1,
    ),
    4 => 
    array (
      'poll_view' => 1,
    ),
  ),
)array (
  'Regular Members' => 
  array (
    1 => 
    array (
      'delete_own' => 1,
      'lock_own' => 1,
      'modify_own' => 1,
      'poll_add_own' => 1,
      'poll_edit_own' => 1,
      'poll_lock_own' => 1,
      'poll_post' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_own' => 1,
      'report_any' => 1,
      'view_attachments' => 1,
    ),
    2 => 
    array (
      'delete_own' => 1,
      'lock_own' => 1,
      'modify_own' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_own' => 1,
      'report_any' => 1,
      'view_attachments' => 1,
    ),
    3 => 
    array (
      'delete_own' => 1,
      'lock_own' => 1,
      'modify_own' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'remove_own' => 1,
      'report_any' => 1,
      'view_attachments' => 1,
    ),
    4 => 
    array (
      'poll_view' => 1,
      'poll_vote' => 1,
      'report_any' => 1,
      'view_attachments' => 1,
    ),
  ),
)array (
  'Global Moderator' => 
  array (
    1 => 
    array (
      'approve_posts' => 1,
      'delete_any' => 1,
      'delete_own' => 1,
      'lock_any' => 1,
      'lock_own' => 1,
      'make_sticky' => 1,
      'merge_any' => 1,
      'moderate_board' => 1,
      'modify_any' => 1,
      'modify_own' => 1,
      'move_any' => 1,
      'poll_add_any' => 1,
      'poll_edit_any' => 1,
      'poll_lock_any' => 1,
      'poll_post' => 1,
      'poll_remove_any' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_any' => 1,
      'report_any' => 1,
      'split_any' => 1,
      'view_attachments' => 1,
    ),
    2 => 
    array (
      'approve_posts' => 1,
      'delete_any' => 1,
      'delete_own' => 1,
      'lock_any' => 1,
      'lock_own' => 1,
      'make_sticky' => 1,
      'merge_any' => 1,
      'moderate_board' => 1,
      'modify_any' => 1,
      'modify_own' => 1,
      'move_any' => 1,
      'poll_add_any' => 1,
      'poll_edit_any' => 1,
      'poll_lock_any' => 1,
      'poll_post' => 1,
      'poll_remove_any' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_any' => 1,
      'report_any' => 1,
      'split_any' => 1,
      'view_attachments' => 1,
    ),
    3 => 
    array (
      'approve_posts' => 1,
      'delete_any' => 1,
      'delete_own' => 1,
      'lock_any' => 1,
      'lock_own' => 1,
      'make_sticky' => 1,
      'merge_any' => 1,
      'moderate_board' => 1,
      'modify_any' => 1,
      'modify_own' => 1,
      'move_any' => 1,
      'poll_add_any' => 1,
      'poll_edit_any' => 1,
      'poll_lock_any' => 1,
      'poll_post' => 1,
      'poll_remove_any' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_any' => 1,
      'report_any' => 1,
      'split_any' => 1,
      'view_attachments' => 1,
    ),
    4 => 
    array (
      'approve_posts' => 1,
      'delete_any' => 1,
      'delete_own' => 1,
      'lock_any' => 1,
      'lock_own' => 1,
      'make_sticky' => 1,
      'merge_any' => 1,
      'moderate_board' => 1,
      'modify_any' => 1,
      'modify_own' => 1,
      'move_any' => 1,
      'poll_add_any' => 1,
      'poll_edit_any' => 1,
      'poll_lock_any' => 1,
      'poll_post' => 1,
      'poll_remove_any' => 1,
      'poll_view' => 1,
      'poll_vote' => 1,
      'post_attachment' => 1,
      'post_draft' => 1,
      'post_new' => 1,
      'post_reply_any' => 1,
      'post_reply_own' => 1,
      'post_unapproved_attachments' => 1,
      'post_unapproved_replies_any' => 1,
      'post_unapproved_replies_own' => 1,
      'post_unapproved_topics' => 1,
      'remove_any' => 1,
      'report_any' => 1,
      'split_any' => 1,
      'view_attachments' => 1,
    ),
  ),
)

Actual result

array (
  'Guests' => 
  array (
    1 => 
    array (
      'poll_view' => 1,
    ),
    2 => 
    array (
      'poll_view' => 1,
    ),
    3 => 
    array (
      'poll_view' => 1,
    ),
    4 => 
    array (
      'poll_view' => 1,
    ),
  ),
)array (
  'Regular Members' => 
  array (
    1 => 
    array (
      'delete_own' => 1,
    ),
    2 => 
    array (
      'delete_own' => 1,
    ),
    3 => 
    array (
      'delete_own' => 1,
    ),
    4 => 
    array (
      'poll_view' => 1,
    ),
  ),
)array (
  'Global Moderator' => 
  array (
    1 => 
    array (
      'approve_posts' => 1,
    ),
    2 => 
    array (
      'approve_posts' => 1,
    ),
    3 => 
    array (
      'approve_posts' => 1,
    ),
    4 => 
    array (
      'approve_posts' => 1,
    ),
  ),
)

I got results by deleting deez

SMF/Sources/Group.php

Lines 2072 to 2075 in 5ad2a26

// If we're loading all profiles, but not reloading, don't overwrite existing data.
if (!isset($profile) && !$reload && isset(self::$loaded[$row['id_group']]->permissions['board_profiles'][$row['id_profile']])) {
continue;
}

Should loading a permission profile be optional?

@Sesquipedalian
Copy link
Member

As I recall, those lines exist because there are situations where loadPermissionsBatch() is called after some permissions have already been loaded and potentially adjusted, and preserving such adjustments is desired.

In your case, I think you just need to set the $reload parameter of loadPermissionsBatch() to true in order to get the behaviour that you want.

Caveat: I am currently on my phone, so I haven't done a thorough analysis to verify this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants