Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #34 from theonion/django-1.7
Browse files Browse the repository at this point in the history
adds Django 1.7 compatability

__fuck yeah__
  • Loading branch information
Vince Forgione committed Nov 6, 2014
2 parents f303365 + f5c045d commit 3bd15c0
Show file tree
Hide file tree
Showing 63 changed files with 1,531 additions and 769 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ language: python
python:
- '2.7'
env:
- DJANGO_VERSION=1.5
- DJANGO_VERSION=1.6
- DJANGO_VERSION=1.7
cache:
directories:
- $HOME/.pip-cache/
Expand All @@ -25,4 +24,4 @@ deploy:
secure: KOj/PW07DMSP8aNQMjC6yjLohuhat6//GMHfg9r/XjxLqNd86/t8z1KpNgyRsIC25x2KUkPHjUxg6VC7Dbr5YBptq3kcXR7vkhGFVVud6W4A93/wHhrE6QLrwQzu1vD32Hp5dNY0qggQSwFE2AYS0dXPpbiJuxZJAwtaOfS5Hk4=
on:
tags: true
python: 2.7
python: 2.7
13 changes: 13 additions & 0 deletions bulbs/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
]
Empty file.
2 changes: 0 additions & 2 deletions bulbs/api/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

class UncachedResponse(object):

@property
def default_response_headers(self):
return {
Expand Down
40 changes: 35 additions & 5 deletions bulbs/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,78 @@ class HasPermissionOrIsAuthor(permissions.BasePermission):
protected_methods = []

def has_object_permission(self, request, view, obj):
"""determines if requesting user has permissions for the object
:param request: WSGI request object - where we get the user from
:param view: the view calling for permission
:param obj: the object in question
:return: `bool`
"""
# Give permission if we're not protecting this method
if self.protected_methods and not request.method in self.protected_methods:
return True

user = getattr(request, "user", None)

if not user or user.is_anonymous():
return False

if self.require_staff and not user.is_staff:
return False

# if they have higher-level privileges we can return true right now
if user.has_perms(self.permissions):
return True

# no? ok maybe they're the author and have appropriate author permissions.
authors_field = getattr(obj, self.authors_field, None)

if not authors_field:
return False

if self.author_permissions and not user.has_perms(self.author_permissions):
return False

return user in authors_field.all()


class CanEditContent(HasPermissionOrIsAuthor):
"""
extends `HasPermissionOrIsAuthor` and protects PUT method
"""

permissions = ["content.change_content"]
protected_methods = ["PUT"]


class CanPromoteContent(HasPermissionOrIsAuthor):
"""
extends `HasPermissionOrIsAuthor` and ensures user has promotion rights
"""

permissions = ["content.promote_content"]


class CanPublishContent(HasPermissionOrIsAuthor):
"""
extends `HasPermissionOrIsAuthor` and ensures user has publishing rights
"""

permissions = ["content.publish_content"]
author_permissions = ["content.publish_own_content"]


class CanEditCmsNotifications(permissions.BasePermission):
"""
permission class to handle CMS rights
"""

def has_permission(self, request, view):
"""If method is GET, user can access, if method is PUT or POST user must be a superuser."""
"""If method is GET, user can access, if method is PUT or POST user must be a superuser.
"""
has_permission = False

if request.method == "GET" \
or request.method in ["PUT", "POST", "DELETE"] and request.user and request.user.is_superuser:
or request.method in ["PUT", "POST", "DELETE"] \
and request.user and request.user.is_superuser:
has_permission = True

return has_permission
return has_permission
5 changes: 3 additions & 2 deletions bulbs/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from bulbs.cms_notifications.api import notifications_view
from django.conf import settings
from django.conf.urls import url, include

from bulbs.cms_notifications.api import notifications_view
from .views import api_v1_router, MeViewSet


urlpatterns = (
url(r"^me/logout/?$", "django.contrib.auth.views.logout", name="logout"),
url(r"^me/?$", MeViewSet.as_view({"get": "retrieve"}), name="me"),
url(r"^", include(api_v1_router.urls)) # noqa
url(r"^", include(api_v1_router.urls)) # noqa
)

if "bulbs.cms_notifications" in settings.INSTALLED_APPS:
Expand Down

0 comments on commit 3bd15c0

Please sign in to comment.