[%# Shows list of groups the user is a member of or can grant
  # License: Dual-license MPL 1.1+ or GPL 3.0+
  # Author(s): Vitaliy Filippov %]

[%# INTERFACE:
  # all_groups: array of group objects
  # show_member: boolean, whether to show groups the user is member
  # pergroup: hashref in the form { group_id => { product_id => { <prod_perms> => [ product_names ] } } }
  #%]

[% SET user = Bugzilla.user %]

[% SET prod_perms = {
  'access'         => terms.Bug _ ' access'
  'optional'       => 'Optional ' _ terms.bug _ ' access'
  'canedit'        => terms.Bug _ ' edit access'
  'editcomponents' => 'Product administration'
  'editbugs'       => 'Bug field change access'
  'canconfirm'     => terms.Bug _ ' confirm access'
} %]
[% SET prod_perms_keys = [ 'access', 'optional', 'editcomponents', 'canedit', 'canconfirm', 'editbugs' ] %]

[% BLOCK special_groups %]
  [% IF group.name == Param('chartgroup') %]
  <br />Used as 'chartgroup'. Allows to use <a href="chart.cgi">New Charts</a>.
  [% END %]
  [% IF group.name == Param('insidergroup') %]
  <br />Used as 'insidergroup'. Allows to see private comments and attachments.
  [% END %]
  [% IF group.name == Param('querysharegroup') %]
  <br />Used as 'querysharegroup'. Allows to <a href="userprefs.cgi?tab=saved-searches">share Saved Searches</a> with other users.
  [% END %]
  [% IF group.name == Param('timetrackinggroup') %]
  <br />Used as 'timetrackinggroup'. Allows to register add see working time for [% terms.bugs %].
  [% END %]
[% END %]

<p>
  <b>System groups</b> just grant you some system-wide permission.<br />
  <b>[% terms.Bug %] groups</b> are configured by [% terms.Bugzilla %] administrators to grant you some per-product permissions.
  Note that several groups may restrict access to a single product; in this case you must be a member of <b>all</b> of them to see [% terms.bugs %] in that product.
</p>
[% PROCESS before_group_table %]
<table class="admin_table">
  [% FOREACH group = all_groups %]
    [% IF show_member AND user.in_group_id(group.id) OR user.can_bless(group.id) %]
    [% IF NOT last_group OR last_group.is_bug_group != group.is_bug_group %]
    [% IF last_group %]<tr><td colspan="4" style="border-width: 0; background: transparent">&nbsp;</td></tr>[% END %]
    <tr class="[% last_group ? "group_head" : "first_group_head" %]">
      <th align="left">
        [% group.is_bug_group ? terms.Bug _ " group" : "System group" %]
      </th>
      [% PROCESS group_head %]
      [% IF group.is_bug_group %]
      <th align="left">Description</th>
      <th style="width: 50%" align="left">Product permissions</th>
      [% ELSE %]
      <th align="left" colspan="2">Description</th>
      [% END %]
      [% SET last_group = group %]
      [% SET i = 0 %]
    </tr>
    [% END %]
    [% SET i = i+1 %]
    <tr class="[% (i % 2) ? 'even_row' : 'odd_row' %]">
      <td valign="top" align="left">
        [% IF user.can_bless(group.id) %]
          <b><a href="editusersingroup.cgi?group=[% group.id %]"[% IF !user.in_group_id(group.id) %] style="color: gray"[% END %]>[% group.name | html %]</a></b>
        [% ELSE %]
          <b>[% group.name | html %]</b>
        [% END %]
      </td>
      [% PROCESS group_row %]
      [% IF group.is_bug_group %]
        <td valign="top">
          [% group.description | html_light %]
          [% PROCESS special_groups %]
        </td>
        <td valign="top">
          [% SET p = pergroup.${group.id} %]
          [% FOREACH k = prod_perms_keys %]
            [% IF p.$k.size %]
              [% prod_perms.$k %]: [% p.$k.join(', ') %]<br />
            [% END %]
          [% END %]
        </td>
      [% ELSE %]
        <td valign="top" colspan="2">
          [% SET d = lc_messages.system_groups.${group.name} %]
          [% IF d %]
            [% d | none %]
          [% ELSE %]
            [% group.description | html_light %]
          [% END %]
          [% PROCESS special_groups %]
        </td>
      [% END %]
    </tr>
    [% END %]
  [% END %]
</table>
