Skip to content

Commit

Permalink
allow teams to have email addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Mar 4, 2016
1 parent 8d99dc9 commit 13e341b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
8 changes: 7 additions & 1 deletion liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def make_active(cls, username, kind, password, cursor=None):
p.change_username(username, c)
return p

def make_team(self, name):
def make_team(self, name, email=None):
with self.db.get_cursor() as c:
t = c.one("""
INSERT INTO participants
Expand All @@ -129,6 +129,8 @@ def make_team(self, name):
""")
t.change_username(name, c)
t.add_member(self, c)
if email:
t.add_email(email)
return t

@classmethod
Expand Down Expand Up @@ -1638,6 +1640,10 @@ def to_dict(self, details=False, inquirer=None):
def path(self, path):
return '/%s/%s' % (self.username, path)

@property
def is_person(self):
return self.kind in ('individual', 'organization')


class NeedConfirmation(Exception):
"""Represent the case where we need user confirmation during a merge.
Expand Down
15 changes: 7 additions & 8 deletions templates/create-team.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<form action="/about/teams" method="POST">
<form class="form-inline" action="/about/teams" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
<div class="input-group">
<input class="form-control" name="name" size=30
placeholder="{{ _('Name of the team') }}" />
<div class="input-group-btn">
<button class="btn btn-success">{{ _("Create") }}</button>
</div>
</div>

<input class="form-control" name="name" size=30
placeholder="{{ _('Name of the team') }}" />
<input class="form-control" name="email" type="email" size=30
placeholder="{{ _('Email of the team (optional)') }}" />
<button class="btn btn-success">{{ _("Create") }}</button>
</form>
3 changes: 2 additions & 1 deletion templates/settings.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
% extends "templates/base.html"

% block subnav
{% set pages = [
{% set pages = ([
('/giving/', _('Giving')),
('/receiving/', _('Receiving')),
('/wallet/', _('Wallet')),
('/settings/', _('Settings')),
('/identity', _('Identity')),
] if participant.is_person else []) + [
('/emails/', _('Emails')),
('/widgets/', _('Widgets')),
] + ([
Expand Down
2 changes: 1 addition & 1 deletion www/%username/emails/index.spt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from liberapay.utils import get_participant

[---]

participant = get_participant(state, restrict=True)
participant = get_participant(state, restrict=True, allow_member=True)
title = participant.username
subhead = _("Email settings")
emails = participant.get_emails()
Expand Down
2 changes: 1 addition & 1 deletion www/%username/emails/modify.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from liberapay.utils import get_participant
[-----------------------------------------]

request.allow("POST")
participant = get_participant(state, restrict=True)
participant = get_participant(state, restrict=True, allow_member=True)

if not participant.email_lang:
participant.set_email_lang(request.headers.get("Accept-Language"))
Expand Down
5 changes: 3 additions & 2 deletions www/%username/emails/verify.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ from liberapay.utils import emails, get_participant
[-----------------------------------------------------------------------------]

participant = get_participant(state, restrict=False)
if participant == user:
ok = participant == user or participant.kind == 'group' and user.member_of(participant)
if ok:
email = request.qs.get('email', '')
nonce = request.qs.get('nonce', '')
result = participant.verify_email(email, nonce)
Expand All @@ -27,7 +28,7 @@ if participant == user:
<p>{{ _("Sign in to finish connecting your email.") }}</p>

<p>{% include "templates/sign-in-link.html" %}</p>
% elif user != participant
% elif not ok
<h1>{{ _("Wrong Account") }}</h1>

<p>{{ _("You're signed into the wrong Liberapay account to complete this email "
Expand Down
2 changes: 1 addition & 1 deletion www/about/teams.spt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if request.method == 'POST':
else:
raise UsernameAlreadyTaken(name)
else:
t = user.make_team(name)
t = user.make_team(name, request.body.get('email'))
response.redirect('/'+t.username+'/edit')

title = _("Teams")
Expand Down

0 comments on commit 13e341b

Please sign in to comment.