{% extends "sentry/projects/manage.html" %}

{% load i18n %}
{% load sentry_helpers %}
{% load sentry_plugins %}

{% block title %}{% trans "Manage API Keys" %} | {{ block.super }}{% endblock %}

{% block inner %}
    <div class="page-header">
        {% if can_add_key %}
            <a href="{% url 'sentry-new-project-key' project.organization.slug project.slug %}" class="btn pull-right btn-primary">{% trans "Generate New Key" %}</a>
        {% endif %}
        <h2>
            {% trans "Manage API Keys" %}
        </h2>
    </div>
    <table class="table table-bordered table-striped">
        <colgroup>
            <col/>
            <col width="200px"/>
        </colgroup>
        <thead>
            <tr>
                <th>{% trans "API Key" %}</th>
                <th style="text-align:center">{% trans "Actions" %}</th>
            </tr>
        </thead>
        <tbody>
            {% for key in key_list %}
                <tr>
                    <td>
                        {% if key.label %}
                            <a href="{% url 'sentry-edit-project-key' project.organization.slug project.slug key.id %}">{{ key.label }}</a>
                        {% else %}
                            <a href="{% url 'sentry-edit-project-key' project.organization.slug project.slug key.id %}">{{ key.public_key }}</a> {% if key.user %} &mdash; {{ key.user.email }}{% endif %}
                        {% endif %}<br>
                        <code class="clippy">{{ key.dsn_private }}</code><br>
                        {% if key.user_added %}
                            <small>Added by {{ key.user_added.email }} ({{ key.date_added|timesince }})</small>
                        {% endif %}
                    </td>
                    <td style="text-align:center; vertical-align:middle;">
                        {% if key.can_edit %}
                            {% if key.is_active %}
                                <form method="POST" action="{% url 'sentry-disable-project-key' project.organization.slug project.slug key.id %}" style="display:inline">
                                    {% csrf_token %}
                                    <input type="submit" class="btn btn-primary btn-small" value="{% trans "Disable" %}">
                                </form>
                            {% else %}
                                <form method="POST" action="{% url 'sentry-enable-project-key' project.organization.slug project.slug key.id %}" style="display:inline">
                                    {% csrf_token %}
                                    <input type="submit" class="btn btn-primary btn-small" value="{% trans "Enable" %}">
                                </form>
                            {% endif %}
                        {% endif %}
                        {% if key.can_remove %}
                            <form method="POST" action="{% url 'sentry-remove-project-key' project.organization.slug project.slug key.id %}" style="display:inline">
                                {% csrf_token %}
                                <input type="submit" class="btn btn-danger btn-small" value="{% trans "Revoke" %}">
                            </form>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}
