Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Drop USER_ROLE_CLASS.

  • Loading branch information...
commit 4f6a72a0e316e8372958bfa25e7db93535cd10cf 1 parent ba7fa1e
Tom Christie tomchristie authored
25 README.md
View
@@ -66,31 +66,6 @@ The `role_required` decorator provides similar behavior to Django's `login_requi
def view(request):
...
-Using Custom Role Classes
--------------------------
-
-It can sometime be useful to override the default user role class.
-You can do this by setting `USER_ROLE_CLASS` in your settings file.
-
-`settings.py`:
-
- USER_ROLE_CLASS = 'myapp.models.CustomUserRole'
-
-`models.py`:
-
- def CustomUserRole(userroles.UserRole):
- @property
- def can_moderate_discussions(self):
- return self.is_moderator or self.is_manager
-
-`views.py`:
-
- def view(request):
- if user.role.can_moderate_discussions:
- ...
- else:
- ...
-
Testing
-------
2  testproject/settings.py
View
@@ -123,5 +123,3 @@
'django.contrib.staticfiles',
'userroles',
)
-
-USER_ROLE_CLASS = 'userroles.tests.CustomUserRole'
12 userroles/models.py
View
@@ -1,9 +1,8 @@
-from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db import models
-from userroles import roles, _import_class_from_string
+from userroles import roles
class UserRole(models.Model):
@@ -14,9 +13,6 @@ class UserRole(models.Model):
profile = generic.GenericForeignKey('content_type', 'object_id')
valid_roles = roles
- class Meta:
- abstract = bool(getattr(settings, 'USER_ROLE_CLASS', None))
-
def __eq__(self, other):
return self.name == other.name
@@ -30,7 +26,7 @@ def __getattr__(self, name):
def set_user_role(user, role):
- user_role_string = getattr(settings, 'USER_ROLE_CLASS', None)
- user_role_class = _import_class_from_string(user_role_string) or UserRole
- role = user_role_class(user=user, name=role.name)
+ #user_role_string = getattr(settings, 'USER_ROLE_CLASS', None)
+ #user_role_class = _import_class_from_string(user_role_string) or UserRole
+ role = UserRole(user=user, name=role.name)
role.save()
26 userroles/testapp/models.py
View
@@ -1,17 +1,17 @@
-from userroles.models import UserRole
-from userroles.tests import roles
+# from userroles.models import UserRole
+# from userroles.tests import roles
-class CustomUserRole(UserRole):
- """
- Custom user role class to test 'USER_ROLE_CLASS' setting.
- """
+# class CustomUserRole(UserRole):
+# """
+# Custom user role class to test 'USER_ROLE_CLASS' setting.
+# """
- # Play nicely with project we're installed into, by using our custom
- # test roles for our UserRole class, rather than the default global roles,
- # loaded from the project settings.
- valid_roles = roles
+# # Play nicely with project we're installed into, by using our custom
+# # test roles for our UserRole class, rather than the default global roles,
+# # loaded from the project settings.
+# valid_roles = roles
- @property
- def can_moderate_discussions(self):
- return self.is_moderator or self.is_manager
+# @property
+# def can_moderate_discussions(self):
+# return self.is_moderator or self.is_manager
19 userroles/tests.py
View
@@ -5,7 +5,7 @@
from milkman.dairy import milkman
-from userroles.models import set_user_role
+from userroles.models import set_user_role, UserRole
from userroles.utils import SettingsTestCase
from userroles import Roles
@@ -20,10 +20,10 @@
)
installed_apps_config = list(settings.INSTALLED_APPS)
-installed_apps_config.remove('userroles')
installed_apps_config.append('userroles.testapp')
roles = Roles(roles_config)
+UserRole.valid_roles = roles
class TestCase(SettingsTestCase):
@@ -31,7 +31,6 @@ def setUp(self):
super(TestCase, self).setUp()
self.settings(
INSTALLED_APPS=installed_apps_config,
- USER_ROLE_CLASS='userroles.testapp.models.CustomUserRole',
ROOT_URLCONF='userroles.testapp.urls',
USER_ROLES=roles_config
)
@@ -122,11 +121,11 @@ def test_get_disallowed_view(self):
# Tests for using a custom UserRole class
-class UserRoleClassSettingTests(TestCase):
- def setUp(self):
- super(UserRoleClassSettingTests, self).setUp()
- self.user = milkman.deliver(User)
- set_user_role(self.user, roles.moderator)
+# class UserRoleClassSettingTests(TestCase):
+# def setUp(self):
+# super(UserRoleClassSettingTests, self).setUp()
+# self.user = milkman.deliver(User)
+# set_user_role(self.user, roles.moderator)
- def test_role_has_custom_property(self):
- self.assertTrue(self.user.role.can_moderate_discussions)
+# def test_role_has_custom_property(self):
+# self.assertTrue(self.user.role.can_moderate_discussions)
Please sign in to comment.
Something went wrong with that request. Please try again.