{# Source code of the Ubuntu-it website
 # Copyright (C) 2018  Pietro Albini <pietroalbini@ubuntu.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published
 # by the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; witout even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Affero General Public License for more details.
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #}

{% extends "layout.html" %}
{% from "actions/macros.html" import render_actions with context %}

{% block title %}Dettagli sessione{% endblock %}

{% block content %}
    <div class="page">
        <div class="row">
            <div class="col">
                <h1>Dettagli sessione</h1>

                <div class="table">
                    <table>
                        <tr>
                            <td>Nome utente</td>
                            <td><b>{{ session.nickname }}</b></td>
                        </tr>
                        <tr>
                            <td>Stato</td>
                            <td>{% if session.active -%}
                                <span class="text-green">Attiva</span>
                            {%- else -%}
                                <span class="text-red">Scaduta</span>
                            {%- endif %}</td>
                        </tr>
                        <tr>
                            <td>Indirizzo IP</td>
                            <td>{{ session.ip }}</td>
                        </tr>
                        <tr>
                            <td>Inizio</td>
                            <td>{{ session.created_at|format_timestamp }}</td>
                        </tr>
                        <tr>
                            <td>{% if session.active %}Scadenza{% else %}Fine{% endif %}</td>
                            <td>{{ session.expires_at|format_timestamp }}</td>
                        </tr>
                        <tr>
                            <td>Team</td>
                            <td>
                                {% for team in session.teams %}
                                    <a href="https://launchpad.net/~{{ team }}">
                                        ~{{ team -}}
                                    </a>
                                    {%- if not loop.last %},{% endif %}
                                {% endfor %}
                            </td>
                        </tr>
                    </table>
                </div>

                {% if g.auth_id != session.id and session.active %}
                <a class="btn" href="{{ url_for(".sessions_revoke", id=session.id) }}">
                    Disabilita sessione
                </a>
                {% endif %}
            </div>
        </div>
        {% if others %}
        <div class="row">
            <div class="col">
                {% if session.active %}
                <h2>Altre sessioni dell'utente</h2>
                {% else %}
                <h2>Sessioni correnti dell'utente</h2>
                {% endif %}
                <div class="table">
                    <table>
                        <tr>
                            <th>Indirizzo IP</th>
                            <th>Inizio</th>
                            <th>Scadenza</th>
                            <th></th>
                            <th></th>
                        </tr>
                        {% for session in others %}
                        <tr>
                            <td>{{ session.ip }}</td>
                            <td>{{ session.created_at|format_timestamp }}
                            <td>{{ session.expires_at|format_timestamp }}
                            <td>
                                <a href="{{ url_for(".sessions_show", id=session.id) }}">
                                    Dettagli
                                </a>
                            </td>
                            <td>
                                {% if session.id == g.auth_id %}
                                Sessione corrente
                                {% else %}
                                <a href="{{ url_for(".sessions_revoke", id=session.id) }}">
                                    Disabilita sessione
                                </a>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                </div>
            </div>
        </div>
        {% endif %}
    </div>

    {% if permission("actions.show") and actions %}
    <div class="page">
        <div class="row">
            <div class="col">
                <h2>Azioni eseguite in questa sessione</h2>
                {{ render_actions(actions, own=True) }}
            </div>
        </div>
    </div>
    {% endif %}
{% endblock %}
