Skip to content

Commit

Permalink
Include permissions profile in visibility previews
Browse files Browse the repository at this point in the history
  • Loading branch information
msikma committed Jan 6, 2024
1 parent 7e15a5d commit 055f5f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/context.php
Expand Up @@ -111,9 +111,10 @@ function add_board_permissions_data($board_id, &$board_member_groups, &$board) {
$hidden_to_all_but_admins = $hidden_to_guest && $hidden_to_members && $hidden_to_gmods;
$hidden_to_some = $hidden_to_guest || $hidden_to_members || $hidden_to_gmods;

$board['_permissions_profile'] = $data['id_profile'];
$board['_permissions_profile'] = $data['profile'];
$board['_member_groups'] = $data['member_groups'];
$board['_group_permissions'] = [
$board['_permissions'] = [
'non_default_profile' => $data['profile'] !== 'default',
'only_admin' => $hidden_to_all_but_admins,
'hidden_to_guest' => $hidden_to_guest,
'hidden_to_members' => $hidden_to_members,
Expand Down
10 changes: 7 additions & 3 deletions lib/db.php
Expand Up @@ -54,13 +54,17 @@ function get_board_member_groups($board_ids = []) {
return [];
}

// Fetch all member groups to get their names.
// Fetch all member groups and permission profiles to get their names.
$groups = [];
$request = $smcFunc['db_query']('', 'select id_group, group_name from {db_prefix}membergroups', []);

while ($row = $smcFunc['db_fetch_assoc']($request)) {
$groups[$row['id_group']] = $row;
}
$profiles = [];
$request = $smcFunc['db_query']('', 'select id_profile, profile_name from {db_prefix}permission_profiles', []);
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$profiles[$row['id_profile']] = $row;
}

// Manually add in the guest and regular member groups, which are special groups with IDs -1 and 0 respectively.
$groups[-1] = ['id_group' => -1, 'group_name' => 'Guest'];
Expand All @@ -85,7 +89,7 @@ function get_board_member_groups($board_ids = []) {
}
$boards[$row['id_board']] = [
'id' => $row['id_board'],
'id_profile' => $row['id_profile'],
'profile' => $profiles[$row['id_profile']]['profile_name'],
'member_groups' => $board_groups,
];
}
Expand Down
11 changes: 7 additions & 4 deletions templates/components/forum/forum_row.twig
Expand Up @@ -20,15 +20,18 @@
<td class="info light sections">
<div class="section board_name">
<a class="subject" href="{{ board.href }}" name="b{{ board.id }}">{{ board.name }}</a>
{% if board._group_permissions.hidden_to_some and context.user.is_admin %}
{% if (board._permissions.hidden_to_some or board._permissions.non_default_profile) and context.user.is_admin %}
<div class="subsection hidden_to_groups">
{% if board._group_permissions.only_admin %}
{% if board._permissions_profile == 'read_only' %}
<span class="hidden">Read-only</span>
{% endif %}
{% if board._permissions.only_admin %}
<span class="hidden admin_only">Administrator only</span>
{% else %}
{% if board._group_permissions.hidden_to_guest %}
{% if board._permissions.hidden_to_guest %}
<span class="hidden">Hidden to Guests</span>
{% endif %}
{% if board._group_permissions.hidden_to_members %}
{% if board._permissions.hidden_to_members %}
<span class="hidden">Hidden to Members</span>
{% endif %}
{% endif %}
Expand Down

0 comments on commit 055f5f5

Please sign in to comment.