[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Testopia System.
  #
  # The Initial Developer of the Original Code is Greg Hendricks.
  # Portions created by Greg Hendricks are Copyright (C) 2006
  # Novell. All Rights Reserved.
  #
  # Contributor(s): Greg Hendricks <ghendricks@novell.com>
  #%]
<script type="text/javascript">
function fireLoad(){
    Ext.getCmp('plan-permissions').fireEvent('load');
    if (Ext.get('adduser')){
        var adduser = new Testopia.User.Lookup({
            id: 'plan_permission_add_user',
            hiddenName: 'adduser'
        });
        adduser.render('adduser');
    }
}

function planAccess(o){
    var form = new Ext.form.BasicForm('plan_access_frm',{});
    form.on('beforeaction',function(f,a){
        f.el.mask('Processing...');
        if (o.action == 'delete'){
            form.baseParams = o;
        }
        else{
            form.baseParams = {action: o.action};
        }
    });


    form.submit({
        url: 'tr_plan_access.cgi',
        success: function(f,a){
            Testopia.Util.notify.msg('Test plan updated', 'Test plan {0} was updated successfully', 'Permissions');
            f.el.unmask();
            Ext.getCmp('plan-permissions').load({
                url: 'tr_plan_access.cgi',
                params: {plan_id: [% plan.id FILTER none %]},
                scripts: true,
                callback: fireLoad
            })
        },
        failure: Testopia.Util.error
    })
}
</script>
  
<p>
This page allows plan managers to permit access to a test plan. By
default, members of the <b>Testers</b> group in [% terms.Bugzilla %] have read
and write access. Beyond this, login names (email addresses) that
match a given regular expression are granted the level of permissions
specified. Lastly, individuals can be granted additional permissions
by adding them explicitly. (Note: you cannot remove permissions from a
user that has those rights by virtue of membership in the Testers group
or that matches the regular expression, although you can add additional
rights to that user.)
</p>
<br/>
<form id="plan_access_frm" onsubmit="return false">
<input type="hidden" name="plan_id" value="[% plan.id FILTER none %]">
<h3>Access Method</h3>
<br/>
<table>
  <tr class="bz_row_header">
    <th>User Regular Expression</th>
    <th>Read</th>
    <th>Write</th>
    <th>Delete</th>
    <th>Admin</th>
  </tr>
  <tr>
    <td><input name="userregexp" value="[% plan.tester_regexp FILTER html %]" size="70" [% 'disabled="disabled"' UNLESS plan.canadmin %]><br></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="pr" [% 'checked="checked"' IF plan.tester_regexp_permissions.read %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="pw" [% 'checked="checked"' IF plan.tester_regexp_permissions.write %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="pd" [% 'checked="checked"' IF plan.tester_regexp_permissions.delete %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="pa" [% 'checked="checked"' IF plan.tester_regexp_permissions.admin %] value="1"></td>
  </tr>
</table>
<br>
<h3>Access Control List</h3>
<br/>
<table>
  <tr class="bz_row_header">
    <th>User</th>
    <th>Read</th>
    <th>Write</th>
    <th>Delete</th>
    <th>Admin</th>
  </tr>
  [% FOREACH row = plan.access_list %]
  <tr class="[% loop.count % 2 == 0 ? "tr_row_odd" : "tr_row_even" %]">
    <td>[%'*' IF row.user.id == plan.author.id %][% row.user.identity FILTER html %]</td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="r[% row.user.id %]" [% 'checked="checked"' IF row.read %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="w[% row.user.id %]" [% 'checked="checked"' IF row.write %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="d[% row.user.id %]" [% 'checked="checked"' IF row.delete %] value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" [% 'disabled="disabled"' UNLESS plan.canadmin %] name="a[% row.user.id %]" [% 'checked="checked"' IF row.admin %] value="1"></td>
  [% IF plan.canadmin %]
    <td><input type="image" src="extensions/Testopia/img/delete.png" onclick="planAccess({action: 'delete', user: '[% row.user.id %]',plan_id: [% plan.id FILTER none %]})"> </td>
  [% END %]
  </tr>
  [% END %]
  [% IF plan.canadmin %]
  <tr style="background-color:#D8E5EE">
    <td style="padding: 3px;">
          <div id="adduser"></div>
    </td>
    <td align="center"><input type="checkbox" style="border: none" name="nr" value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" name="nw" value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" name="nd" value="1"></td>
    <td align="center"><input type="checkbox" style="border: none" name="na" value="1"></td>
    <td align="left"><input type="button" onclick="planAccess({action: 'add_user'})" value="Add User"></td>
  </tr>
  [% END %]
</table>
<p align="right">
[% IF plan.canadmin %]
<input type="button" onclick="planAccess({action: 'edit'})" value="Apply Changes">
</form>
[% END %]
</p>
<dl>
  <dt>Read</dt>
  <dd>Allows viewing rights to the plan and all test cases, test runs, and test case-runs associated with it. 
  Test cases linked to more than one plan will not be visible unless the user has view rights on all plans linked</dd>
  <dt>Write</dt>
  <dd>Implies Read. Allows rights to modify the plan and associated cases, runs, and case-runs.</dd>
  <dt>Delete</dt>
  <dd>Implies Read and Write. Allows rights to delete the plan and associated cases, runs, and case-runs.</dd>
  <dt>Admin</dt>
  <dd>Implies Read, Write, and Delete. Allows rights to modify the plan's access controls (this page).</dd>
</dl>
* Plan author

