Commit 6fd9dfd8 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Publish protocols before decisions and attachments are visible

parent 18bb9969
"""empty message
Revision ID: a1f23743bddb
Revises: 0555db125011
Create Date: 2017-02-28 13:38:25.900461
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a1f23743bddb'
down_revision = '0555db125011'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('protocols', sa.Column('public', sa.Boolean(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('protocols', 'public')
# ### end Alembic commands ###
...@@ -125,13 +125,14 @@ class Protocol(db.Model): ...@@ -125,13 +125,14 @@ class Protocol(db.Model):
participants = db.Column(db.String) participants = db.Column(db.String)
location = db.Column(db.String) location = db.Column(db.String)
done = db.Column(db.Boolean) done = db.Column(db.Boolean)
public = db.Column(db.Boolean)
tops = relationship("TOP", backref=backref("protocol"), cascade="all, delete-orphan", order_by="TOP.number") tops = relationship("TOP", backref=backref("protocol"), cascade="all, delete-orphan", order_by="TOP.number")
decisions = relationship("Decision", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Decision.id") decisions = relationship("Decision", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Decision.id")
documents = relationship("Document", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Document.is_compiled") documents = relationship("Document", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Document.is_compiled")
errors = relationship("Error", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Error.id") errors = relationship("Error", backref=backref("protocol"), cascade="all, delete-orphan", order_by="Error.id")
def __init__(self, protocoltype_id, date, source=None, content_public=None, content_private=None, start_time=None, end_time=None, author=None, participants=None, location=None, done=False): def __init__(self, protocoltype_id, date, source=None, content_public=None, content_private=None, start_time=None, end_time=None, author=None, participants=None, location=None, done=False, public=False):
self.protocoltype_id = protocoltype_id self.protocoltype_id = protocoltype_id
self.date = date self.date = date
self.source = source self.source = source
...@@ -143,6 +144,7 @@ class Protocol(db.Model): ...@@ -143,6 +144,7 @@ class Protocol(db.Model):
self.participants = participants self.participants = participants
self.location = location self.location = location
self.done = done self.done = done
self.public = public
def __repr__(self): def __repr__(self):
return "<Protocol(id={}, protocoltype_id={})>".format( return "<Protocol(id={}, protocoltype_id={})>".format(
...@@ -190,6 +192,18 @@ class Protocol(db.Model): ...@@ -190,6 +192,18 @@ class Protocol(db.Model):
if LOCATION_KEY in remarks: if LOCATION_KEY in remarks:
self.location = remarks[LOCATION_KEY].value.strip() self.location = remarks[LOCATION_KEY].value.strip()
def has_public_view_right(self, user):
return (
(self.public and self.protocoltype.has_public_view_right(user))
or self.protocoltype.has_private_view_right(user)
)
def has_private_view_right(self, user):
return self.protocoltype.has_private_view_right(user)
def has_modify_right(self, user):
return self.protocoltype.has_modify_right(user)
def is_done(self): def is_done(self):
return self.done return self.done
......
...@@ -104,7 +104,12 @@ def index(): ...@@ -104,7 +104,12 @@ def index():
key=_sort_key key=_sort_key
) )
finished_protocols = sorted( finished_protocols = sorted(
[protocol for protocol in protocols if protocol.done], [
protocol for protocol in protocols
if protocol.done
and (protocol.has_public_view_right(user)
or protocol.has_private_view_right(user))
],
key=_sort_key key=_sort_key
) )
protocol = finished_protocols[0] if len(finished_protocols) > 0 else None protocol = finished_protocols[0] if len(finished_protocols) > 0 else None
...@@ -112,7 +117,7 @@ def index(): ...@@ -112,7 +117,7 @@ def index():
if check_login(): if check_login():
todos = [ todos = [
todo for todo in Todo.query.all() todo for todo in Todo.query.all()
if todo.protocoltype.has_public_view_right(user) if todo.protocoltype.has_private_view_right(user)
and not todo.is_done() and not todo.is_done()
] ]
todos_table = TodosTable(todos) if todos is not None else None todos_table = TodosTable(todos) if todos is not None else None
...@@ -395,7 +400,7 @@ def list_protocols(): ...@@ -395,7 +400,7 @@ def list_protocols():
protocol for protocol in protocols protocol for protocol in protocols
if (protocol.protocoltype.has_private_view_right(user) if (protocol.protocoltype.has_private_view_right(user)
and _matches_search(protocol.content_private)) and _matches_search(protocol.content_private))
or (protocol.protocoltype.has_public_view_right(user) or (protocol.has_public_view_right(user)
and _matches_search(protocol.content_public)) and _matches_search(protocol.content_public))
] ]
for protocol in protocols: for protocol in protocols:
...@@ -464,12 +469,12 @@ def show_protocol(protocol_id): ...@@ -464,12 +469,12 @@ def show_protocol(protocol_id):
user = current_user() user = current_user()
protocol = Protocol.query.filter_by(id=protocol_id).first() protocol = Protocol.query.filter_by(id=protocol_id).first()
if protocol is None or not protocol.protocoltype.has_public_view_right(user): if protocol is None or not protocol.protocoltype.has_public_view_right(user):
flash("Invalides Protokoll.", "alert-error") flash("Invalides Protokoll oder fehlende Zugriffsrechte.", "alert-error")
return redirect(request.args.get("next") or url_for("index")) return redirect(request.args.get("next") or url_for("index"))
errors_table = ErrorsTable(protocol.errors) errors_table = ErrorsTable(protocol.errors)
visible_documents = [ visible_documents = [
document for document in protocol.documents document for document in protocol.documents
if (not document.is_private and document.protocol.protocoltype.has_public_view_right(user)) if (not document.is_private and document.protocol.has_public_view_right(user))
or (document.is_private and document.protocol.protocoltype.has_private_view_right(user)) or (document.is_private and document.protocol.protocoltype.has_private_view_right(user))
] ]
documents_table = DocumentsTable(visible_documents) documents_table = DocumentsTable(visible_documents)
...@@ -650,6 +655,19 @@ def update_protocol(protocol_id): ...@@ -650,6 +655,19 @@ def update_protocol(protocol_id):
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
return render_template("protocol-update.html", upload_form=upload_form, edit_form=edit_form, protocol=protocol) return render_template("protocol-update.html", upload_form=upload_form, edit_form=edit_form, protocol=protocol)
@app.route("/protocol/publish/<int:protocol_id>")
@login_required
def publish_protocol(protocol_id):
user = current_user()
protocol = Protocol.query.filter_by(id=protocol_id).first()
if protocol is None or not protocol.protocoltype.has_modify_right(user):
flash("Invalides Protokoll oder keine Berechtigung.", "alert-error")
return redirect(request.args.get("next") or url_for("index"))
protocol.public = True
db.session.commit()
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
@app.route("/prococol/send/<int:protocol_id>") @app.route("/prococol/send/<int:protocol_id>")
@login_required @login_required
def send_protocol(protocol_id): def send_protocol(protocol_id):
...@@ -891,7 +909,7 @@ def list_decisions(): ...@@ -891,7 +909,7 @@ def list_decisions():
search_form.search.data = search_term search_form.search.data = search_term
decisions = [ decisions = [
decision for decision in Decision.query.all() decision for decision in Decision.query.all()
if decision.protocol.protocoltype.has_public_view_right(user) if decision.protocol.has_public_view_right(user)
] ]
if protocoltype_id is not None and protocoltype_id != -1: if protocoltype_id is not None and protocoltype_id != -1:
decisions = [ decisions = [
...@@ -926,7 +944,7 @@ def download_document(document_id): ...@@ -926,7 +944,7 @@ def download_document(document_id):
if ((document.is_private if ((document.is_private
and not document.protocol.protocoltype.has_private_view_right(user)) and not document.protocol.protocoltype.has_private_view_right(user))
or (not document.is_private or (not document.is_private
and not document.protocol.protocoltype.has_public_view_right(user))): and not document.protocol.has_public_view_right(user))):
flash("Keine Berechtigung.", "alert-error") flash("Keine Berechtigung.", "alert-error")
return redirect(request.args.get("next") or url_for("index")) return redirect(request.args.get("next") or url_for("index"))
return send_file(document.as_file_like(), cache_timeout=1, as_attachment=True, attachment_filename=document.name) return send_file(document.as_file_like(), cache_timeout=1, as_attachment=True, attachment_filename=document.name)
......
...@@ -4,41 +4,47 @@ ...@@ -4,41 +4,47 @@
{% set logged_in = check_login() %} {% set logged_in = check_login() %}
{% set user = current_user() %} {% set user = current_user() %}
{% set has_public_view_right = protocol.protocoltype.has_public_view_right(user) %} {% set has_public_type_view_right = protocol.protocoltype.has_public_view_right(user) %}
{% set has_private_view_right = protocol.protocoltype.has_private_view_right(user) %} {% set has_public_view_right = protocol.has_public_view_right(user) %}
{% set has_modify_right = protocol.protocoltype.has_modify_right(user) %} {% set has_private_view_right = protocol.has_private_view_right(user) %}
{% set has_modify_right = protocol.has_modify_right(user) %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="btn-group"> {% if has_modify_right %}
{% if has_modify_right %} <div class="btn-group">
{% if config.ETHERPAD_ACTIVE %} {% if has_modify_right %}
<a class="btn {% if protocol.source is none %}btn-primary{% else %}btn-default{% endif %}" href="{{url_for("etherpull_protocol", protocol_id=protocol.id)}}">Aus Etherpad</a>
{% endif %}
{% if protocol.source is not none %}
<a class="btn btn-primary" href="{{url_for("get_protocol_source", protocol_id=protocol.id)}}">Quelltext</a>
{% endif %}
<a class="btn {% if protocol.is_done() %}btn-success{% else %}btn-default{% endif %}" href="{{url_for("update_protocol", protocol_id=protocol.id)}}">Editieren</a>
{% if not protocol.is_done() %}
<a class="btn btn-default" href="{{url_for("get_protocol_template", protocol_id=protocol.id)}}">Vorlage</a>
{% if config.ETHERPAD_ACTIVE %} {% if config.ETHERPAD_ACTIVE %}
<a class="btn btn-primary" href="{{url_for("etherpush_protocol", protocol_id=protocol.id)}}">In Etherpad</a> <a class="btn {% if protocol.source is none %}btn-primary{% else %}btn-default{% endif %}" href="{{url_for("etherpull_protocol", protocol_id=protocol.id)}}">Aus Etherpad</a>
{% endif %} {% endif %}
{% else %} {% if protocol.source is not none %}
{% if config.MAIL_ACTIVE %} <a class="btn btn-primary" href="{{url_for("get_protocol_source", protocol_id=protocol.id)}}">Quelltext</a>
<a class="btn btn-default" href="{{url_for("send_protocol", protocol_id=protocol.id)}}">Mail versenden</a> {% endif %}
<a class="btn {% if protocol.is_done() %}btn-success{% else %}btn-default{% endif %}" href="{{url_for("update_protocol", protocol_id=protocol.id)}}">Editieren</a>
{% if not protocol.is_done() %}
<a class="btn btn-default" href="{{url_for("get_protocol_template", protocol_id=protocol.id)}}">Vorlage</a>
{% if config.ETHERPAD_ACTIVE %}
<a class="btn btn-primary" href="{{url_for("etherpush_protocol", protocol_id=protocol.id)}}">In Etherpad</a>
{% endif %}
{% else %}
{% if config.MAIL_ACTIVE %}
<a class="btn btn-default" href="{{url_for("send_protocol", protocol_id=protocol.id)}}">Mail versenden</a>
{% endif %}
{% if not protocol.public %}
<a class="btn btn-default" href="{{url_for("publish_protocol", protocol_id=protocol.id)}}">Veröffentlichen</a>
{% endif %}
{% endif %} {% endif %}
{% if config.ETHERPAD_ACTIVE %}
<a class="btn btn-default" href="{{protocol.get_etherpad_link()}}" target="_blank">Etherpad</a>
{% endif %}
<a class="btn btn-default" href="{{url_for("show_type", type_id=protocol.protocoltype.id)}}">Typ</a>
{% if protocol.has_compiled_document() %}
<a class="btn btn-success" href="{{url_for("download_document", document_id=protocol.get_compiled_document().id)}}">Download</a>
{% endif %}
<a class="btn btn-danger" href="{{url_for("delete_protocol", protocol_id=protocol.id)}}" onclick="return confirm('Bist du dir sicher, dass du das Protokoll {{protocol.get_identifier()}} löschen möchtest?');">Löschen</a>
{% endif %} {% endif %}
{% if config.ETHERPAD_ACTIVE %} </div>
<a class="btn btn-default" href="{{protocol.get_etherpad_link()}}" target="_blank">Etherpad</a> {% endif %}
{% endif %}
<a class="btn btn-default" href="{{url_for("show_type", type_id=protocol.protocoltype.id)}}">Typ</a>
{% if protocol.has_compiled_document() %}
<a class="btn btn-success" href="{{url_for("download_document", document_id=protocol.get_compiled_document().id)}}">Download</a>
{% endif %}
<a class="btn btn-danger" href="{{url_for("delete_protocol", protocol_id=protocol.id)}}" onclick="return confirm('Bist du dir sicher, dass du das Protokoll {{protocol.get_identifier()}} löschen möchtest?');">Löschen</a>
{% endif %}
</div>
<div class="row"> <div class="row">
<div id="left-column" class="col-lg-6"> <div id="left-column" class="col-lg-6">
{% if protocol.is_done() %} {% if protocol.is_done() %}
...@@ -69,7 +75,7 @@ ...@@ -69,7 +75,7 @@
<h3>Tagesordnung{% if has_modify_right and not protocol.has_nonplanned_tops() %} <a href="{{url_for("new_top", protocol_id=protocol.id)}}">Top hinzufügen</a>{% endif %}</h3> <h3>Tagesordnung{% if has_modify_right and not protocol.has_nonplanned_tops() %} <a href="{{url_for("new_top", protocol_id=protocol.id)}}">Top hinzufügen</a>{% endif %}</h3>
{% include "protocol-tops-include.html" %} {% include "protocol-tops-include.html" %}
{% if protocol.is_done() %} {% if protocol.is_done() and has_public_view_right %}
<h3>Beschlüsse</h3> <h3>Beschlüsse</h3>
<ul> <ul>
{% if protocol.decisions|length > 0 %} {% if protocol.decisions|length > 0 %}
...@@ -105,7 +111,7 @@ ...@@ -105,7 +111,7 @@
{{render_table(errors_table)}} {{render_table(errors_table)}}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if protocol.documents|length > 0 %} {% if protocol.documents|length > 0 and has_public_view_right %}
{{render_table(documents_table)}} {{render_table(documents_table)}}
{% else %} {% else %}
{% if has_modify_right %} {% if has_modify_right %}
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
{% for top in protocol.tops %} {% for top in protocol.tops %}
<li> <li>
{{top.name}} {{top.name}}
{% if not protocol.is_done() and has_private_view_right %} {% if not protocol.is_done() and has_public_type_view_right %}
({{top.number}}) ({{top.number}})
{% endif %} {% endif %}
{% if not protocol.is_done() and has_modify_right %} {% if not protocol.is_done() and has_modify_right %}
......
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
{% set loggedin = check_login() %} {% set loggedin = check_login() %}
{% set user = current_user() %} {% set user = current_user() %}
{% set has_public_view_right = protocol.protocoltype.has_public_view_right(user) %} {% set has_public_type_view_right = protocol.has_public_type_view_right(user) %}
{% set has_private_view_right = protocol.protocoltype.has_private_view_right(user) %} {% set has_public_view_right = protocol.has_public_view_right(user) %}
{% set has_modify_right = protocol.protocoltype.has_modify_right(user) %} {% set has_private_view_right = protocol.has_private_view_right(user) %}
{% set has_modify_right = protocol.has_modify_right(user) %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
......
...@@ -106,6 +106,7 @@ class ProtocolForm(FlaskForm): ...@@ -106,6 +106,7 @@ class ProtocolForm(FlaskForm):
author = StringField("Protokollant") author = StringField("Protokollant")
participants = StringField("Anwesende") participants = StringField("Anwesende")
done = BooleanField("Fertig") done = BooleanField("Fertig")
public = BooleanField("Veröffentlicht")
class TopForm(FlaskForm): class TopForm(FlaskForm):
name = StringField("TOP", validators=[InputRequired("Du musst den Namen des TOPs angeben.")]) name = StringField("TOP", validators=[InputRequired("Du musst den Namen des TOPs angeben.")])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment