{% extends "base.html" %}

{% block main %}
<div class="page-grid">
  <div class="page-grid__toolbar"></div>
  <div class="page-grid__sidebar">
    {{ navbar | safe }}
  </div>
  <main class="page-grid__main">
    <section class="section">
      <h1>Sharing</h1>
    </section>
    <section class="section">
      <h2>Table Owners</h2>
      <p class="notice notice--info">
        Owners are able to edit table structure, including configuring columns,
        adding, updating, and deleting record data, and dropping the table
        entirely from the database.
      </p>
      <p class="notice notice--info">
        Each table in Postgres has exactly one owner role, so it's typically
        best practice to create a dedicated role for this purpose and then grant
        membership of that role to one or more users.
      </p>
      {{ owners | safe }}
    </section>
    <section class="section">
      <h2>Invitations</h2>
      <a href="{{ settings.root_path }}/d/{{ base.id.simple() }}/r/{{ pg_class.oid.0 }}/rbac/invite">
        Invite Collaborators
      </a>
      <table class="users-table">
        <thead>
          <tr>
            <th class="users-table__th">Email</th>
            {# rolname is intentionally hidden in a submenu (todo), as it is
               likely to confuse new users #}
            <th class="users-table__th">Privileges</th>
            <th class="users-table__th"><span class="sr-only">Actions</span></th>
          </tr>
        </thead>
        <tbody>
          {# place invitations at beginning of list as they're liable to cause
             unpleasant surprises if forgotten #}
          {% for (email, invites) in invites_by_email %}
          <tr>
            <td class="users-table__td">{{ email }}</td>
            <td class="users-table__td">
              <code>{% for invite in invites %}{{ invite.privilege }}{% endfor %}</code>
            </td>
            <td class="users-table__td"></td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </section>
    <section class="section">
      <h2>Permissions</h2>
      <ul>
        {% for acl_tree in acl_trees %}
        <li>
          <div>
            {% for privilege in acl_tree.acl_item.privileges %}{{ privilege.privilege.to_abbrev() }}{% endfor %}
          </div>
          {{ acl_tree.grantees | safe }}
        </li>
        {% endfor %}
      </ul>
    </section>
  </main>
</div>
{% endblock %}
