Skip to content

Commit f0ccb2a

Browse files
authored
Merge pull request #107 from labhackercd/develop
Edemocracia integration
2 parents 8e31a24 + 1338074 commit f0ccb2a

File tree

10 files changed

+126
-51
lines changed

10 files changed

+126
-51
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ RUN chmod 0644 /etc/cron.d/wikilegis
1212
ADD . /var/labhacker/wikilegis
1313
WORKDIR /var/labhacker/wikilegis
1414

15-
RUN pip3 install -r requirements.txt psycopg2 gunicorn && \
15+
RUN pip3 install -U pip && \
16+
pip3 install -r requirements.txt psycopg2 gunicorn && \
1617
rm -r /root/.cache
1718

1819
RUN npm install
1920

2021
WORKDIR /var/labhacker/wikilegis/wikilegis
21-
RUN python3 manage.py bower_install --allow-root && \
22+
RUN python3 manage.py activate_plugin camara_deputados && \
23+
python3 manage.py bower_install --allow-root && \
2224
python3 manage.py compress --force && \
2325
python3 manage.py collectstatic --no-input && \
2426
python3 manage.py compilemessages

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# wikilegis
2+
3+
Collaborative editing of legislative texts. See https://edemocracia.camara.leg.br/wikilegis/ for a live instance used by Brazil's Chamber of Deputies.
4+
15
# Requirements
26

37
* Python 3.x

wikilegis/accounts/middlewares.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ def process_request(self, request):
2424
try:
2525
username = request.META[self.header]
2626
except KeyError:
27-
# If specified header doesn't exist then remove any existing
28-
# authenticated remote-user, or return (leaving request.user set to
29-
# AnonymousUser by the AuthenticationMiddleware).
30-
if request.user.is_authenticated():
31-
try:
32-
stored_backend = load_backend(request.session.get(
33-
auth.BACKEND_SESSION_KEY, ''))
34-
if isinstance(stored_backend, RemoteUserBackend):
35-
auth.logout(request)
36-
except ImproperlyConfigured:
37-
# backend failed to load
38-
auth.logout(request)
3927
return
4028
# If the user is already authenticated and that user is the user we are
4129
# getting passed in the headers, then the correct user is already

wikilegis/api/authorization.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from tastypie.authorization import Authorization
2+
from tastypie.exceptions import Unauthorized
3+
from django.conf import settings
4+
from django.utils.translation import ugettext_lazy as _
5+
6+
7+
class UpdateUserAuthorization(Authorization):
8+
9+
def api_key_is_valid(self, bundle):
10+
api_key = bundle.request.GET.get('api_key', None)
11+
if api_key and api_key == settings.API_KEY:
12+
return True
13+
else:
14+
raise Unauthorized(_('Missing api key'))
15+
16+
def update_list(self, object_list, bundle):
17+
raise Unauthorized(_('You cannot perform this action'))
18+
19+
def update_detail(self, object_list, bundle):
20+
return self.api_key_is_valid(bundle)
21+
22+
def delete_list(self, object_list, bundle):
23+
raise Unauthorized(_('You cannot perform this action'))
24+
25+
def delete_detail(self, object_list, bundle):
26+
return self.api_key_is_valid(bundle)

wikilegis/api/resources.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.conf import settings
2+
from django.conf.urls import url
23
from django.contrib.auth import get_user_model
34
from django.contrib.contenttypes.models import ContentType
5+
from api.authorization import UpdateUserAuthorization
46
from tastypie.resources import ModelResource, ALL_WITH_RELATIONS, ALL
57
from tastypie import fields
68

@@ -10,23 +12,34 @@
1012
class UserResource(ModelResource):
1113

1214
def dehydrate(self, bundle):
15+
bundle.data.pop('is_active', None)
16+
bundle.data.pop('is_staff', None)
17+
bundle.data.pop('is_superuser', None)
18+
1319
key = bundle.request.GET.get('api_key', None)
1420
if key != settings.API_KEY:
1521
del bundle.data['email']
1622
return bundle
1723

18-
def dehydrate_username(self, bundle):
19-
return bundle.obj.__str__()
24+
def prepend_urls(self):
25+
re_url = r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$".format(
26+
self._meta.resource_name
27+
)
28+
return [
29+
url(re_url, self.wrap_view('dispatch_detail'),
30+
name="api_dispatch_detail"),
31+
]
2032

2133
class Meta:
2234
queryset = get_user_model().objects.all()
23-
allowed_methods = ['get']
24-
excludes = ['is_active', 'is_staff', 'is_superuser', 'last_login',
25-
'password', 'date_joined']
35+
allowed_methods = ['get', 'put', 'delete']
36+
excludes = ['last_login', 'password', 'date_joined']
37+
authorization = UpdateUserAuthorization()
38+
detail_uri_name = 'username'
2639
filtering = {
2740
'first_name': ALL,
2841
'last_name': ALL,
29-
'username': ALL
42+
'username': ALL,
3043
}
3144

3245

@@ -68,7 +81,8 @@ class BillResource(ModelResource):
6881
class Meta:
6982
queryset = core_models.Bill.objects.filter(
7083
allowed_users__isnull=True,
71-
is_visible=True).exclude(status='draft')
84+
is_visible=True).exclude(status='draft').order_by(
85+
'-status', '-modified')
7286
resource_name = 'bill'
7387
excludes = ['is_visible']
7488
allowed_methods = ['get']
@@ -77,7 +91,9 @@ class Meta:
7791
'title': ALL,
7892
'status': ALL,
7993
'id': ALL,
94+
'closing_date': ALL,
8095
}
96+
ordering = ['closing_date', 'status', 'modified']
8197

8298

8399
class SegmentTypeResource(ModelResource):

wikilegis/locale/en/LC_MESSAGES/django.po

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
11+
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -66,6 +66,14 @@ msgstr ""
6666
msgid "Users"
6767
msgstr ""
6868

69+
#: api/authorization.py:14
70+
msgid "Missing api key"
71+
msgstr ""
72+
73+
#: api/authorization.py:17 api/authorization.py:23
74+
msgid "You cannot perform this action"
75+
msgstr ""
76+
6977
#: core/admin.py:23 core/models.py:160
7078
msgid "reference"
7179
msgstr ""
@@ -368,8 +376,8 @@ msgid "New"
368376
msgstr ""
369377

370378
#: core/templates/base.html:34 core/templates/base.html:36
371-
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
372-
#: core/views.py:255 core/views.py:298
379+
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
380+
#: core/views.py:256 core/views.py:299
373381
msgid "Oops"
374382
msgstr ""
375383

@@ -569,33 +577,33 @@ msgstr ""
569577
msgid "Access control. Please log in and try again."
570578
msgstr ""
571579

572-
#: core/views.py:74
580+
#: core/views.py:75
573581
msgid "Access denied. Please contact the project author."
574582
msgstr ""
575583

576-
#: core/views.py:97 core/views.py:116
584+
#: core/views.py:98 core/views.py:117
577585
msgid ""
578586
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
579587
"strong>"
580588
msgstr ""
581589

582-
#: core/views.py:135
590+
#: core/views.py:136
583591
msgid "The following URL has returned no known segment."
584592
msgstr ""
585593

586-
#: core/views.py:214
594+
#: core/views.py:215
587595
msgid "This bill is closed for participation :("
588596
msgstr ""
589597

590-
#: core/views.py:234
598+
#: core/views.py:235
591599
msgid "You must be logged to comment :("
592600
msgstr ""
593601

594-
#: core/views.py:256
602+
#: core/views.py:257
595603
msgid "You must be logged to vote :("
596604
msgstr ""
597605

598-
#: core/views.py:299
606+
#: core/views.py:300
599607
msgid "You must be logged to suggest new amendment :("
600608
msgstr ""
601609

wikilegis/locale/es/LC_MESSAGES/django.po

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
11+
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -67,6 +67,14 @@ msgstr ""
6767
msgid "Users"
6868
msgstr ""
6969

70+
#: api/authorization.py:14
71+
msgid "Missing api key"
72+
msgstr ""
73+
74+
#: api/authorization.py:17 api/authorization.py:23
75+
msgid "You cannot perform this action"
76+
msgstr ""
77+
7078
#: core/admin.py:23 core/models.py:160
7179
msgid "reference"
7280
msgstr ""
@@ -369,8 +377,8 @@ msgid "New"
369377
msgstr ""
370378

371379
#: core/templates/base.html:34 core/templates/base.html:36
372-
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
373-
#: core/views.py:255 core/views.py:298
380+
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
381+
#: core/views.py:256 core/views.py:299
374382
msgid "Oops"
375383
msgstr ""
376384

@@ -570,33 +578,33 @@ msgstr ""
570578
msgid "Access control. Please log in and try again."
571579
msgstr ""
572580

573-
#: core/views.py:74
581+
#: core/views.py:75
574582
msgid "Access denied. Please contact the project author."
575583
msgstr ""
576584

577-
#: core/views.py:97 core/views.py:116
585+
#: core/views.py:98 core/views.py:117
578586
msgid ""
579587
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
580588
"strong>"
581589
msgstr ""
582590

583-
#: core/views.py:135
591+
#: core/views.py:136
584592
msgid "The following URL has returned no known segment."
585593
msgstr ""
586594

587-
#: core/views.py:214
595+
#: core/views.py:215
588596
msgid "This bill is closed for participation :("
589597
msgstr ""
590598

591-
#: core/views.py:234
599+
#: core/views.py:235
592600
msgid "You must be logged to comment :("
593601
msgstr ""
594602

595-
#: core/views.py:256
603+
#: core/views.py:257
596604
msgid "You must be logged to vote :("
597605
msgstr ""
598606

599-
#: core/views.py:299
607+
#: core/views.py:300
600608
msgid "You must be logged to suggest new amendment :("
601609
msgstr ""
602610

wikilegis/locale/pt_BR/LC_MESSAGES/django.po

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
11+
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -68,6 +68,14 @@ msgstr "Usuário"
6868
msgid "Users"
6969
msgstr "Usuários"
7070

71+
#: api/authorization.py:14
72+
msgid "Missing api key"
73+
msgstr "Chave da api não encontrada"
74+
75+
#: api/authorization.py:17 api/authorization.py:23
76+
msgid "You cannot perform this action"
77+
msgstr "Você não pode realizar essa ação"
78+
7179
#: core/admin.py:23 core/models.py:160
7280
msgid "reference"
7381
msgstr "referência"
@@ -370,8 +378,8 @@ msgid "New"
370378
msgstr "Novo"
371379

372380
#: core/templates/base.html:34 core/templates/base.html:36
373-
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
374-
#: core/views.py:255 core/views.py:298
381+
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
382+
#: core/views.py:256 core/views.py:299
375383
msgid "Oops"
376384
msgstr "Oops"
377385

@@ -577,35 +585,35 @@ msgstr "Erro 403"
577585
msgid "Access control. Please log in and try again."
578586
msgstr "Acesso controlado. Faça o login e tente novamente."
579587

580-
#: core/views.py:74
588+
#: core/views.py:75
581589
msgid "Access denied. Please contact the project author."
582590
msgstr "Acesso negado. Favor contatar o autor do projeto."
583591

584-
#: core/views.py:97 core/views.py:116
592+
#: core/views.py:98 core/views.py:117
585593
msgid ""
586594
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
587595
"strong>"
588596
msgstr ""
589597
"A seguinte URL não retornou um projeto de lei conhecido: <br> <strong>{}/"
590598
"bill/{}</strong>"
591599

592-
#: core/views.py:135
600+
#: core/views.py:136
593601
msgid "The following URL has returned no known segment."
594602
msgstr "A seguinte URL não retornou um trecho conhecido."
595603

596-
#: core/views.py:214
604+
#: core/views.py:215
597605
msgid "This bill is closed for participation :("
598606
msgstr "Este projeto de lei está fechado para participação :("
599607

600-
#: core/views.py:234
608+
#: core/views.py:235
601609
msgid "You must be logged to comment :("
602610
msgstr "Você deve estar logado para comentar :("
603611

604-
#: core/views.py:256
612+
#: core/views.py:257
605613
msgid "You must be logged to vote :("
606614
msgstr "Você deve estar logado para votar :("
607615

608-
#: core/views.py:299
616+
#: core/views.py:300
609617
msgid "You must be logged to suggest new amendment :("
610618
msgstr "Você deve estar logado para sugerir uma nova proposta :("
611619

wikilegis/start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22

3+
while true; do
4+
PG_STATUS=`PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -w -h $DATABASE_HOST -c '\l \q' | grep postgres | wc -l`
5+
if ! [ "$PG_STATUS" -eq "0" ]; then
6+
break
7+
fi
8+
9+
echo "Waiting Database Setup"
10+
sleep 10
11+
done
12+
313
PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -w -h $DATABASE_HOST -c "CREATE DATABASE ${DATABASE_NAME} OWNER ${DATABASE_USER}"
414

515
python3 manage.py migrate

0 commit comments

Comments
 (0)