Commit 24d493b7 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Differentiate between modify right and private view right

/close #15
parent fcccf7cd
"""empty message
Revision ID: 7dd3c479c048
Revises: ab996d2365af
Create Date: 2017-03-01 03:54:18.283388
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7dd3c479c048'
down_revision = 'ab996d2365af'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('protocoltypes', sa.Column('modify_group', sa.String(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('protocoltypes', 'modify_group')
# ### end Alembic commands ###
......@@ -26,6 +26,7 @@ class ProtocolType(db.Model):
organization = db.Column(db.String)
usual_time = db.Column(db.Time)
is_public = db.Column(db.Boolean)
modify_group = db.Column(db.String)
private_group = db.Column(db.String)
public_group = db.Column(db.String)
private_mail = db.Column(db.String)
......@@ -42,13 +43,15 @@ class ProtocolType(db.Model):
todos = relationship("Todo", backref=backref("protocoltype"), order_by="Todo.id")
def __init__(self, name, short_name, organization, usual_time,
is_public, private_group, public_group, private_mail, public_mail,
is_public, modify_group, private_group, public_group,
private_mail, public_mail,
use_wiki, wiki_category, wiki_only_public, printer, calendar):
self.name = name
self.short_name = short_name
self.organization = organization
self.usual_time = usual_time
self.is_public = is_public
self.modify_group = modify_group
self.private_group = private_group
self.public_group = public_group
self.private_mail = private_mail
......@@ -61,15 +64,15 @@ class ProtocolType(db.Model):
def __repr__(self):
return ("<ProtocolType(id={}, short_name={}, name={}, "
"organization={}, is_public={}, private_group={}, "
"public_group={}, use_wiki={}, wiki_category='{}', "
"wiki_only_public={}, printer={}, usual_time={}, "
"calendar='{}')>".format(
"organization={}, is_public={}, modify_group={}, "
"private_group={}, public_group={}, use_wiki={}, "
"wiki_category='{}', wiki_only_public={}, printer={}, "
"usual_time={}, calendar='{}')>".format(
self.id, self.short_name, self.name,
self.organization, self.is_public, self.private_group,
self.public_group, self.use_wiki, self.wiki_category,
self.wiki_only_public, self.printer, self.usual_time,
self.calendar))
self.organization, self.is_public, self.modify_group,
self.private_group, self.public_group, self.use_wiki,
self.wiki_category, self.wiki_only_public, self.printer,
self.usual_time, self.calendar))
def get_latest_protocol(self):
candidates = sorted([protocol for protocol in self.protocols if protocol.is_done()], key=lambda p: p.date, reverse=True)
......@@ -88,7 +91,7 @@ class ProtocolType(db.Model):
return (user is not None and self.private_group != "" and self.private_group in user.groups)
def has_modify_right(self, user):
return self.has_private_view_right(user)
return (user is not None and self.modify_group != "" and self.modify_group in user.groups)
@staticmethod
def get_modifiable_protocoltypes(user):
......
......@@ -10,7 +10,11 @@ from shared import current_user
import config
def get_protocoltype_choices(protocoltypes, add_all=True):
choices = [(protocoltype.id, protocoltype.short_name) for protocoltype in protocoltypes]
choices = [
(protocoltype.id, protocoltype.short_name)
for protocoltype
in sorted(protocoltypes, key=lambda t: t.short_name)
]
if add_all:
choices.insert(0, (-1, "Alle"))
return choices
......@@ -23,12 +27,17 @@ def get_todostate_choices():
def get_calendar_choices():
calendars = CalendarClient().get_calendars()
choices = list(zip(calendars, calendars))
choices = []
if calendars is not None:
calendars = sorted(calendars)
choices = list(zip(calendars, calendars))
choices.insert(0, ("", "Kein Kalender"))
return choices
def get_printer_choices():
choices = list(zip(config.PRINTING_PRINTERS, config.PRINTING_PRINTERS))
choices = []
if config.PRINTING_PRINTERS is not None:
choices = list(zip(config.PRINTING_PRINTERS, config.PRINTING_PRINTERS))
choices.insert(0, ("", "Nicht drucken"))
return choices
......@@ -54,6 +63,7 @@ class ProtocolTypeForm(FlaskForm):
organization = StringField("Organisation", validators=[InputRequired("Du musst eine zugehörige Organisation angeben.")])
usual_time = DateTimeField("Üblicher Beginn", validators=[InputRequired("Bitte gib die Zeit an, zu der die Sitzung beginnt.")], format="%H:%M")
is_public = BooleanField("Öffentlich sichtbar")
modify_group = SelectField("Bearbeitungsgruppe", choices=[])
private_group = SelectField("Interne Gruppe", choices=[])
public_group = SelectField("Öffentliche Gruppe", choices=[])
private_mail = StringField("Interner Verteiler")
......@@ -69,6 +79,7 @@ class ProtocolTypeForm(FlaskForm):
self.calendar.choices = get_calendar_choices()
self.printer.choices = get_printer_choices()
group_choices = get_group_choices()
self.modify_group.choices = group_choices
self.private_group.choices = group_choices
self.public_group.choices = group_choices
......
......@@ -108,7 +108,8 @@ class ProtocolTypeTable(SingleValueTable):
def headers(self):
general_headers = ["Name", "Abkürzung", "Organisation", "Beginn",
"Öffentlich", "Interne Gruppe", "Öffentliche Gruppe"]
"Öffentlich", "Bearbeitungsgruppe", "Interne Gruppe",
"Öffentliche Gruppe"]
mail_headers = ["Interner Verteiler", "Öffentlicher Verteiler"]
if not config.MAIL_ACTIVE:
mail_headers = []
......@@ -132,6 +133,7 @@ class ProtocolTypeTable(SingleValueTable):
self.value.organization,
self.value.usual_time.strftime("%H:%M") if self.value.usual_time is not None else "", # todo: remove if, this field is required
Table.bool(self.value.is_public),
self.value.modify_group,
self.value.private_group,
self.value.public_group,
]
......
Markdown is supported
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