<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

  <xi:include href="master.html" />
  <xi:include href="lib.html" />

  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>Project Admin for $c.project._id</title>
  </head>
  
  <body>
    <h1 class="title">ProjectAdmin for ${project_links(c.project)}</h1>
    <div>
      <h2>Project ACL Admin</h2>
      <p>The project ACL determines project-level permissions.</p>
      <div py:for="permission, users in c.project.acl.iteritems()"
           style="border:1px solid black">
        <h3>Permission: $permission</h3>
        <ul>
          <li py:for="u in h.make_users(users)">
            $u.display_name
            <form 
               py:if="c.user != u or permission != 'security'"
               method="post" 
               action="del_perm" 
               style="display:inline">
              <input type="hidden" name="permission" value="$permission"/>
              <input type="hidden" name="user" value="${str(u._id)}"/>
              <input type="submit" value="Remove Permission"/>
            </form>
          </li>
        </ul>
        <form method="post" action="add_perm">
          <input type="hidden" name="permission" value="$permission"/>
          User Name: <input type="text" name="username"/>
          <input type="submit" value="Add Permission"/>
        </form>
      </div>
    </div>
    <div py:if="c.project.is_root">
      <h2>Role Admin</h2>
      <p>
        Each user on the project should have a private role.  
        Each role can have subroles.  A role inherits all the permissions 
        that its subroles have.
      </p>
      <div py:for="r in roles" style="border:1px solid black">
        <h3>$r._id 
          <span py:if="r.user_id">($r.user.display_name)</span>
        </h3>
        <form method="post" action="del_role">
          <input type="hidden" name="role" value="$r._id"/>
          <input type="submit" value="Remove Role"/>
        </form>
        <ul>
          <li py:for="rr in r.roles">
            $rr 
            <form method="post" action="del_role" style="display:inline">
              <input type="hidden" name="role" value="$r._id"/>
              <input type="hidden" name="subrole" value="$rr"/>
              <input type="submit" value="Remove Role"/>
            </form>
          </li>
        </ul>
        <form method="post" action="add_role">
          <input type="hidden" name="role" value="$r._id"/>
          New role
          <select name="subrole">
            <option py:for="r in roles" value="$r._id">
              $r._id
            </option>
          </select>
          <input type="submit" value="Add"/>
        </form>
      </div>
      <form method="post" action="add_group_role">
        <label for="name">New group role</label>
        <input type="text" name="name"/>
        <input type="submit" value="Add"/>
      </form>
      <form method="post" action="add_user_role">
        <label for="name">New user role</label>
        <select name="id">
          <option py:for="u in users" 
                  value="${str(u._id)}">$u.display_name</option>
        </select>
        <input type="submit" value="Add"/>
      </form>
    </div>
    
  </body>

</html>
