Skip to content

Commit

Permalink
Update for new tutelary functionality
Browse files Browse the repository at this point in the history
Also small change to get tests working, due to upgrade in djoser, which
now tests SEND_ACTIVATION_EMAIL setting before making new users active.
  • Loading branch information
Ian Ross committed Mar 14, 2016
1 parent 48da959 commit 756ddf3
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: python
python:
- "3.4"
- "3.5"
services:
- postgresql
addons:
Expand Down
2 changes: 1 addition & 1 deletion app/src/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SETTINGS = {
API_BASE: 'http://localhost:5000/v1'
API_BASE: 'http://0.0.0.0:5000/v1'
};

export default SETTINGS;
216 changes: 118 additions & 98 deletions app/src/locale/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,6 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Plural-Forms: nplurals = 2; plural = (n !== 1);\n"

#: src/js/account/components/Login.jsx:48
msgid "Sign in to your account"
msgstr ""

#: src/js/account/components/Profile.jsx:60
msgid "Username"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:88
msgid "This field is required"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:67
msgid "Password"
msgstr ""

#: src/js/account/components/Login.jsx:77
msgid "Forgotten password?"
msgstr ""

#: src/js/account/components/Login.jsx:84
msgid "Remember me"
msgstr ""

#: src/js/account/components/Login.jsx:93
msgid "Sign in"
msgstr ""

#: src/js/account/components/Profile.jsx:54
msgid "Update your profile"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:53
msgid "Email"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:57
msgid "Please provide a valid email address"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:98
msgid "First name"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:107
msgid "Last name"
msgstr ""

#: src/js/account/components/Profile.jsx:112
msgid "Update profile"
msgstr ""

#: src/js/account/components/Profile.jsx:115
msgid "Password options"
msgstr ""

#: src/js/account/components/Password.jsx:84
msgid "Change password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:81
msgid "Reset password"
msgstr ""

#: src/js/account/components/Password.jsx:34
msgid "Change your password"
msgstr ""

#: src/js/account/components/Password.jsx:40
msgid "Current password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:50
msgid "New password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:72
msgid "Your password must be at least 6 characters long."
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:65
msgid "Repeat new password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:87
msgid "Passwords must match."
msgstr ""

#: src/js/account/components/PasswordReset.jsx:34
msgid "Reset your password"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:41
msgid "Enter email"
msgstr ""

#: src/js/messages/reducer.js:10
msgid "Unable to login with provided username and password."
msgstr ""
Expand Down Expand Up @@ -165,8 +69,24 @@ msgstr ""
msgid "Account successfully activated."
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:44
msgid "Create a new password"
#: src/js/core/components/Footer.jsx:12
msgid "About Us"
msgstr ""

#: src/js/core/components/Footer.jsx:13
msgid "Privacy"
msgstr ""

#: src/js/core/components/Footer.jsx:14
msgid "Terms of Service"
msgstr ""

#: src/js/core/components/Footer.jsx:15
msgid "Code of Conduct"
msgstr ""

#: src/js/core/components/Footer.jsx:16
msgid "Visit us on Github"
msgstr ""

#: src/js/core/components/Header.jsx:23
Expand All @@ -193,6 +113,106 @@ msgstr ""
msgid "Choose username"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:71
msgid "This field is required"
msgstr ""

#: src/js/account/components/Profile.jsx:75
msgid "Email"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:46
msgid "Please provide a valid email address"
msgstr ""

#: src/js/account/components/Login.jsx:67
msgid "Password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:55
msgid "Your password must be at least 6 characters long."
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:82
msgid "Confirm password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:70
msgid "Passwords must match."
msgstr ""

#: src/js/account/components/Profile.jsx:91
msgid "First name"
msgstr ""

#: src/js/account/components/Profile.jsx:101
msgid "Last name"
msgstr ""

#: src/js/account/components/Login.jsx:48
msgid "Sign in to your account"
msgstr ""

#: src/js/account/components/Profile.jsx:60
msgid "Username"
msgstr ""

#: src/js/account/components/Login.jsx:77
msgid "Forgotten password?"
msgstr ""

#: src/js/account/components/Login.jsx:84
msgid "Remember me"
msgstr ""

#: src/js/account/components/Login.jsx:93
msgid "Sign in"
msgstr ""

#: src/js/account/components/Profile.jsx:54
msgid "Update your profile"
msgstr ""

#: src/js/account/components/Profile.jsx:112
msgid "Update profile"
msgstr ""

#: src/js/account/components/Profile.jsx:115
msgid "Password options"
msgstr ""

#: src/js/account/components/Password.jsx:84
msgid "Change password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:81
msgid "Reset password"
msgstr ""

#: src/js/account/components/Password.jsx:34
msgid "Change your password"
msgstr ""

#: src/js/account/components/Password.jsx:40
msgid "Current password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:50
msgid "New password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:65
msgid "Repeat new password"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:34
msgid "Reset your password"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:41
msgid "Enter email"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:44
msgid "Create a new password"
msgstr ""
1 change: 1 addition & 0 deletions cadasta/config/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

DJOSER.update({
'DOMAIN': 'localhost:8080',
'SEND_ACTIVATION_EMAIL': False,
})

# devserver settings
Expand Down
4 changes: 4 additions & 0 deletions cadasta/config/settings/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
'HOST': '',
}
}

DJOSER.update({
'SEND_ACTIVATION_EMAIL': False,
})
50 changes: 0 additions & 50 deletions cadasta/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import re
from django.http import Http404

from django.core.exceptions import ImproperlyConfigured
from django.utils import six
from django.utils.translation import ugettext_lazy as _

from rest_framework.exceptions import NotFound
from rest_framework.views import exception_handler as drf_exception_handler

from tutelary.engine import Object


def set_exception(exception):
if (type(exception) is Http404):
Expand Down Expand Up @@ -53,50 +50,3 @@ def exception_handler(exception, context):
response.data = eval_json(response.data)

return response


class PermissionRequiredMixin:
def get_permission_required(self):
"""
Override this method to override the permission_required attribute.
Must return an iterable.
"""
if self.permission_required is None:
raise ImproperlyConfigured(
'{0} is missing the permission_required attribute. Define '
'{0}.permission_required, or override '
'{0}.get_permission_required().'.format(
self.__class__.__name__)
)
if isinstance(self.permission_required, dict):
perms = self.permission_required[self.request.method]
else:
perms = self.permission_required

if isinstance(perms, six.string_types):
perms = (perms, )

if hasattr(self, 'add_permission_required'):
perms = perms + self.add_permission_required

return perms

def check_permissions(self, request):
obj = None
allowed = {}
if hasattr(self, 'model') and hasattr(self.model, 'TutelaryMeta'):
obj = Object(self.model.TutelaryMeta.perm_type)
allowed = self.model.TutelaryMeta.allowed_methods
try:
if hasattr(self, 'get_object') and self.get_object() is not None:
obj = self.get_object().get_permissions_object()
except:
pass
perms = self.get_permission_required()

has_perm = all(self.request.user.has_perm(p, obj) for p in perms
if not (p in allowed and
self.request.method in allowed[p]))

if not has_perm:
self.permission_denied(request, message="Permission denied.")
6 changes: 4 additions & 2 deletions cadasta/organization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class Organization(RandomIDModel):
class TutelaryMeta:
perm_type = 'organization'
path_fields = ('slug',)
actions = (('org.list', "List existing organisations"),
actions = (('org.list', {'description': "List existing organisations",
'permissions_object': None}),
('org.view', "View existing organisations"),
('org.create', "Create organisations"),
('org.create', {'description': "Create organisations",
'permissions_object': None}),
('org.update', "Update an existing organization"),
('org.archive', "Archive an existing organization"),
('org.unarchive', "Unarchive an existing organization"),
Expand Down
Loading

0 comments on commit 756ddf3

Please sign in to comment.