This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4287 from gratipay/project-closing
Implement project (Team) closing
- Loading branch information
Showing
20 changed files
with
195 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .available import AvailableMixin as Available | ||
from .closing import ClosingMixin as Closing | ||
from .membership import MembershipMixin as Membership | ||
from .takes import TakesMixin as Takes | ||
from .tip_migration import TipMigrationMixin as TipMigration | ||
|
||
__all__ = ['Available', 'Membership', 'Takes', 'TipMigration'] | ||
__all__ = ['Available', 'Closing', 'Membership', 'Takes', 'TipMigration'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.models import add_event | ||
|
||
|
||
class ClosingMixin(object): | ||
"""This mixin implements team closing. | ||
""" | ||
|
||
#: Whether the team is closed or not. | ||
|
||
is_closed = False | ||
|
||
|
||
def close(self): | ||
"""Close the team account. | ||
""" | ||
with self.db.get_cursor() as cursor: | ||
cursor.run("UPDATE teams SET is_closed=true WHERE id=%s", (self.id,)) | ||
add_event(cursor, 'team', dict(id=self.id, action='set', values=dict(is_closed=True))) | ||
self.set_attributes(is_closed=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.danger-zone { | ||
margin-top: 64px; | ||
border: 1px solid $red; | ||
@include border-radius(5px); | ||
padding: 20px; | ||
h2 { | ||
margin: 0 0 10px; | ||
padding: 0; | ||
color: $red; | ||
} | ||
button { | ||
background: $red; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.testing import Harness, T | ||
|
||
|
||
class TestTeamClosing(Harness): | ||
|
||
def test_teams_can_be_closed_via_python(self): | ||
team = self.make_team() | ||
team.close() | ||
assert team.is_closed | ||
|
||
def test_teams_can_be_closed_via_http(self): | ||
self.make_team() | ||
response = self.client.PxST('/TheEnterprise/edit/close', auth_as='picard') | ||
assert response.headers['Location'] == '/~picard/' | ||
assert response.code == 302 | ||
assert T('TheEnterprise').is_closed | ||
|
||
def test_but_not_by_anon(self): | ||
self.make_team() | ||
response = self.client.PxST('/TheEnterprise/edit/close') | ||
assert response.code == 401 | ||
|
||
def test_nor_by_turkey(self): | ||
self.make_participant('turkey') | ||
self.make_team() | ||
response = self.client.PxST('/TheEnterprise/edit/close', auth_as='turkey') | ||
assert response.code == 403 | ||
|
||
def test_admin_is_cool_though(self): | ||
self.make_participant('Q', is_admin=True) | ||
self.make_team() | ||
response = self.client.PxST('/TheEnterprise/edit/close', auth_as='Q') | ||
assert response.headers['Location'] == '/~Q/' | ||
assert response.code == 302 | ||
assert T('TheEnterprise').is_closed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from aspen import Response | ||
from gratipay.utils import get_team | ||
|
||
[----------------------------------------------------------------------------] | ||
|
||
if user.ANON: | ||
raise Response(401, _("You need to log in to access this page.")) | ||
|
||
request.allow('POST') | ||
|
||
team = get_team(state) | ||
|
||
if not user.ADMIN and user.participant.username != team.owner: | ||
raise Response(403, _("You are not authorized to access this page.")) | ||
|
||
if team.is_closed: | ||
raise Response(403, _("Already closed.")) | ||
|
||
team.close() | ||
|
||
website.redirect('/~{}/'.format(user.participant.username)) | ||
[---] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.