[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[%#
  # bug: bug object
  #%]

[%
  PROCESS global/variables.none.tmpl;

  in_all_groups = 1;
  in_a_group = 0;
  FOREACH group IN bug.groups;
    IF NOT group.ingroup;
      in_all_groups = 0;
    END;
    IF group.ison;
      in_a_group = 1;
    END;
  END
%]

<div class="groups edit-hide">
  [% IF in_a_group %]
    <b>Only users in all of the following groups can view this [% terms.bug %]:</b>
    <ul>
      [% FOREACH group IN bug.groups %]
        [% NEXT UNLESS group.ison || group.mandatory %]
        <li>[% group.description FILTER html %]</li>
      [% END %]
    </ul>

    [% IF bug.reporter_accessible || bug.cclist_accessible %]
      <b>Users in the roles below can always view this [% terms.bug %]:</b>
      <ul>
        [% IF bug.reporter_accessible %]<li>Reporter</li>[% END %]
        [% IF bug.cclist_accessible %]<li>CC List</li>[% END %]
      </ul>
    [% END %]
  [% ELSE %]
    This [% terms.bug %] is publicly visible.
  [% END %]
</div>

<div class="groups edit-show" style="display:none">
  [% UNLESS bug.in_group(bug.product_obj.default_security_group_obj)
     || user.in_group(bug.product_obj.default_security_group)
     || (user.id != bug.reporter.id && !user.in_group('editbugs')) %]
    <div>
      <input type="checkbox" name="groups" class="restrict_sensitive"
             value="[% bug.product_obj.default_security_group FILTER none %]"
             id="group_[% bug.product_obj.default_security_group_obj.id FILTER html %]">
      <label for="group_[% bug.product_obj.default_security_group_obj.id FILTER html %]"
             title="This [% terms.bug %] is security sensitive and should be hidden from the public until it is resolved">
        Restrict access to this [% terms.bug %]
      </label>
    </div>
  [% END %]

  [% emitted_description = 0 %]
  [% FOREACH group IN bug.groups %]
    [% IF NOT emitted_description %]
      [% emitted_description = 1 %]
      <b>Only users in all of the selected groups can view this [% terms.bug %]:</b>
    [% END %]

    [% IF group.ingroup && !group.mandatory %]
      <input type="hidden" name="defined_groups" value="[% group.name FILTER html %]">
    [% END %]

    <div class="group">
      <input type="checkbox" value="[% group.name FILTER html %]"
        name="groups" id="group_[% group.bit FILTER html %]"
        [% " checked" IF group.ison %]
        [% " disabled" IF NOT group.ingroup || group.mandatory %]>
      <label for="group_[% group.bit FILTER html %]">
        [%~ group.description FILTER html_light ~%]
      </label>
    </div>
  [% END %]

  [% IF in_a_group %]
    <b>Users in the roles selected below can always view this [% terms.bug %]:</b>
    <div>
      [% user_can_edit_accessible = bug.check_can_change_field("reporter_accessible", 0, 1) %]
      [% IF user_can_edit_accessible %]
        <input type="hidden" name="defined_reporter_accessible" value="1">
      [% END %]
      <input type="checkbox" value="1"
             name="reporter_accessible" id="reporter_accessible"
             [% " checked" IF bug.reporter_accessible %]
             [% " disabled=\"disabled\"" UNLESS user_can_edit_accessible %]>
      <label for="reporter_accessible">Reporter</label>
    </div>
    <div>
      [% user_can_edit_accessible = bug.check_can_change_field("cclist_accessible", 0, 1) %]
      [% IF user_can_edit_accessible %]
        <input type="hidden" name="defined_cclist_accessible" value="1">
      [% END %]
      <input type="checkbox" value="1"
             name="cclist_accessible" id="cclist_accessible"
             [% " checked" IF bug.cclist_accessible %]
             [% " disabled=\"disabled\"" UNLESS user_can_edit_accessible %]>
      <label for="cclist_accessible">CC List</label>
    </div>
    The assignee[% IF (Param('useqacontact')) %], QA contact, [% END %]
    and triage owner can always see [% terms.abug %], and this section does not
    take effect unless the [% terms.bug %] is restricted to at least one group.
  [% END %]
</div>
