Skip to content

Commit

Permalink
Merge pull request #107 from labhackercd/develop
Browse files Browse the repository at this point in the history
Edemocracia integration
  • Loading branch information
msfernandes authored Apr 10, 2018
2 parents 8e31a24 + 1338074 commit f0ccb2a
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 51 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ RUN chmod 0644 /etc/cron.d/wikilegis
ADD . /var/labhacker/wikilegis
WORKDIR /var/labhacker/wikilegis

RUN pip3 install -r requirements.txt psycopg2 gunicorn && \
RUN pip3 install -U pip && \
pip3 install -r requirements.txt psycopg2 gunicorn && \
rm -r /root/.cache

RUN npm install

WORKDIR /var/labhacker/wikilegis/wikilegis
RUN python3 manage.py bower_install --allow-root && \
RUN python3 manage.py activate_plugin camara_deputados && \
python3 manage.py bower_install --allow-root && \
python3 manage.py compress --force && \
python3 manage.py collectstatic --no-input && \
python3 manage.py compilemessages
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# wikilegis

Collaborative editing of legislative texts. See https://edemocracia.camara.leg.br/wikilegis/ for a live instance used by Brazil's Chamber of Deputies.

# Requirements

* Python 3.x
Expand Down
12 changes: 0 additions & 12 deletions wikilegis/accounts/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ def process_request(self, request):
try:
username = request.META[self.header]
except KeyError:
# If specified header doesn't exist then remove any existing
# authenticated remote-user, or return (leaving request.user set to
# AnonymousUser by the AuthenticationMiddleware).
if request.user.is_authenticated():
try:
stored_backend = load_backend(request.session.get(
auth.BACKEND_SESSION_KEY, ''))
if isinstance(stored_backend, RemoteUserBackend):
auth.logout(request)
except ImproperlyConfigured:
# backend failed to load
auth.logout(request)
return
# If the user is already authenticated and that user is the user we are
# getting passed in the headers, then the correct user is already
Expand Down
26 changes: 26 additions & 0 deletions wikilegis/api/authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from tastypie.authorization import Authorization
from tastypie.exceptions import Unauthorized
from django.conf import settings
from django.utils.translation import ugettext_lazy as _


class UpdateUserAuthorization(Authorization):

def api_key_is_valid(self, bundle):
api_key = bundle.request.GET.get('api_key', None)
if api_key and api_key == settings.API_KEY:
return True
else:
raise Unauthorized(_('Missing api key'))

def update_list(self, object_list, bundle):
raise Unauthorized(_('You cannot perform this action'))

def update_detail(self, object_list, bundle):
return self.api_key_is_valid(bundle)

def delete_list(self, object_list, bundle):
raise Unauthorized(_('You cannot perform this action'))

def delete_detail(self, object_list, bundle):
return self.api_key_is_valid(bundle)
30 changes: 23 additions & 7 deletions wikilegis/api/resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf import settings
from django.conf.urls import url
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from api.authorization import UpdateUserAuthorization
from tastypie.resources import ModelResource, ALL_WITH_RELATIONS, ALL
from tastypie import fields

Expand All @@ -10,23 +12,34 @@
class UserResource(ModelResource):

def dehydrate(self, bundle):
bundle.data.pop('is_active', None)
bundle.data.pop('is_staff', None)
bundle.data.pop('is_superuser', None)

key = bundle.request.GET.get('api_key', None)
if key != settings.API_KEY:
del bundle.data['email']
return bundle

def dehydrate_username(self, bundle):
return bundle.obj.__str__()
def prepend_urls(self):
re_url = r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$".format(
self._meta.resource_name
)
return [
url(re_url, self.wrap_view('dispatch_detail'),
name="api_dispatch_detail"),
]

class Meta:
queryset = get_user_model().objects.all()
allowed_methods = ['get']
excludes = ['is_active', 'is_staff', 'is_superuser', 'last_login',
'password', 'date_joined']
allowed_methods = ['get', 'put', 'delete']
excludes = ['last_login', 'password', 'date_joined']
authorization = UpdateUserAuthorization()
detail_uri_name = 'username'
filtering = {
'first_name': ALL,
'last_name': ALL,
'username': ALL
'username': ALL,
}


Expand Down Expand Up @@ -68,7 +81,8 @@ class BillResource(ModelResource):
class Meta:
queryset = core_models.Bill.objects.filter(
allowed_users__isnull=True,
is_visible=True).exclude(status='draft')
is_visible=True).exclude(status='draft').order_by(
'-status', '-modified')
resource_name = 'bill'
excludes = ['is_visible']
allowed_methods = ['get']
Expand All @@ -77,7 +91,9 @@ class Meta:
'title': ALL,
'status': ALL,
'id': ALL,
'closing_date': ALL,
}
ordering = ['closing_date', 'status', 'modified']


class SegmentTypeResource(ModelResource):
Expand Down
28 changes: 18 additions & 10 deletions wikilegis/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -66,6 +66,14 @@ msgstr ""
msgid "Users"
msgstr ""

#: api/authorization.py:14
msgid "Missing api key"
msgstr ""

#: api/authorization.py:17 api/authorization.py:23
msgid "You cannot perform this action"
msgstr ""

#: core/admin.py:23 core/models.py:160
msgid "reference"
msgstr ""
Expand Down Expand Up @@ -368,8 +376,8 @@ msgid "New"
msgstr ""

#: core/templates/base.html:34 core/templates/base.html:36
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
#: core/views.py:255 core/views.py:298
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
#: core/views.py:256 core/views.py:299
msgid "Oops"
msgstr ""

Expand Down Expand Up @@ -569,33 +577,33 @@ msgstr ""
msgid "Access control. Please log in and try again."
msgstr ""

#: core/views.py:74
#: core/views.py:75
msgid "Access denied. Please contact the project author."
msgstr ""

#: core/views.py:97 core/views.py:116
#: core/views.py:98 core/views.py:117
msgid ""
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
"strong>"
msgstr ""

#: core/views.py:135
#: core/views.py:136
msgid "The following URL has returned no known segment."
msgstr ""

#: core/views.py:214
#: core/views.py:215
msgid "This bill is closed for participation :("
msgstr ""

#: core/views.py:234
#: core/views.py:235
msgid "You must be logged to comment :("
msgstr ""

#: core/views.py:256
#: core/views.py:257
msgid "You must be logged to vote :("
msgstr ""

#: core/views.py:299
#: core/views.py:300
msgid "You must be logged to suggest new amendment :("
msgstr ""

Expand Down
28 changes: 18 additions & 10 deletions wikilegis/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -67,6 +67,14 @@ msgstr ""
msgid "Users"
msgstr ""

#: api/authorization.py:14
msgid "Missing api key"
msgstr ""

#: api/authorization.py:17 api/authorization.py:23
msgid "You cannot perform this action"
msgstr ""

#: core/admin.py:23 core/models.py:160
msgid "reference"
msgstr ""
Expand Down Expand Up @@ -369,8 +377,8 @@ msgid "New"
msgstr ""

#: core/templates/base.html:34 core/templates/base.html:36
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
#: core/views.py:255 core/views.py:298
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
#: core/views.py:256 core/views.py:299
msgid "Oops"
msgstr ""

Expand Down Expand Up @@ -570,33 +578,33 @@ msgstr ""
msgid "Access control. Please log in and try again."
msgstr ""

#: core/views.py:74
#: core/views.py:75
msgid "Access denied. Please contact the project author."
msgstr ""

#: core/views.py:97 core/views.py:116
#: core/views.py:98 core/views.py:117
msgid ""
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
"strong>"
msgstr ""

#: core/views.py:135
#: core/views.py:136
msgid "The following URL has returned no known segment."
msgstr ""

#: core/views.py:214
#: core/views.py:215
msgid "This bill is closed for participation :("
msgstr ""

#: core/views.py:234
#: core/views.py:235
msgid "You must be logged to comment :("
msgstr ""

#: core/views.py:256
#: core/views.py:257
msgid "You must be logged to vote :("
msgstr ""

#: core/views.py:299
#: core/views.py:300
msgid "You must be logged to suggest new amendment :("
msgstr ""

Expand Down
28 changes: 18 additions & 10 deletions wikilegis/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-07 13:18-0300\n"
"POT-Creation-Date: 2018-01-24 11:17-0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -68,6 +68,14 @@ msgstr "Usuário"
msgid "Users"
msgstr "Usuários"

#: api/authorization.py:14
msgid "Missing api key"
msgstr "Chave da api não encontrada"

#: api/authorization.py:17 api/authorization.py:23
msgid "You cannot perform this action"
msgstr "Você não pode realizar essa ação"

#: core/admin.py:23 core/models.py:160
msgid "reference"
msgstr "referência"
Expand Down Expand Up @@ -370,8 +378,8 @@ msgid "New"
msgstr "Novo"

#: core/templates/base.html:34 core/templates/base.html:36
#: core/templates/base.html:38 core/views.py:213 core/views.py:233
#: core/views.py:255 core/views.py:298
#: core/templates/base.html:38 core/views.py:214 core/views.py:234
#: core/views.py:256 core/views.py:299
msgid "Oops"
msgstr "Oops"

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

#: core/views.py:74
#: core/views.py:75
msgid "Access denied. Please contact the project author."
msgstr "Acesso negado. Favor contatar o autor do projeto."

#: core/views.py:97 core/views.py:116
#: core/views.py:98 core/views.py:117
msgid ""
"The following URL has returned no known bill: <br> <strong>{}/bill/{}</"
"strong>"
msgstr ""
"A seguinte URL não retornou um projeto de lei conhecido: <br> <strong>{}/"
"bill/{}</strong>"

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

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

#: core/views.py:234
#: core/views.py:235
msgid "You must be logged to comment :("
msgstr "Você deve estar logado para comentar :("

#: core/views.py:256
#: core/views.py:257
msgid "You must be logged to vote :("
msgstr "Você deve estar logado para votar :("

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

Expand Down
10 changes: 10 additions & 0 deletions wikilegis/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

while true; do
PG_STATUS=`PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -w -h $DATABASE_HOST -c '\l \q' | grep postgres | wc -l`
if ! [ "$PG_STATUS" -eq "0" ]; then
break
fi

echo "Waiting Database Setup"
sleep 10
done

PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -w -h $DATABASE_HOST -c "CREATE DATABASE ${DATABASE_NAME} OWNER ${DATABASE_USER}"

python3 manage.py migrate
Expand Down
Loading

0 comments on commit f0ccb2a

Please sign in to comment.