mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-07 17:34:21 +00:00
Fixed wrong user being tagged due to tastypie API change
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
.gitignore~
|
||||
tags
|
||||
.tags
|
||||
.tags_sorted_by_file
|
||||
.idea
|
||||
*.pyc
|
||||
media/*
|
||||
|
||||
@@ -22,6 +22,7 @@ ADMINS = (
|
||||
|
||||
MANAGERS = ADMINS
|
||||
AUTH_PROFILE_MODULE = 'spa.UserProfile'
|
||||
|
||||
ALLOWED_HOSTS = localsettings.ALLOWED_HOSTS if hasattr(localsettings, 'ALLOWED_HOSTS') else []
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from django.conf.urls import url
|
||||
from tastypie.authentication import Authentication
|
||||
from tastypie.authorization import Authorization
|
||||
from tastypie.constants import ALL_WITH_RELATIONS
|
||||
from tastypie.constants import ALL, ALL_WITH_RELATIONS
|
||||
from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource
|
||||
from spa.models import UserProfile
|
||||
|
||||
|
||||
class UserResource(BackboneCompatibleResource):
|
||||
class Meta:
|
||||
queryset = UserProfile.objects.all()
|
||||
@@ -14,7 +14,15 @@ class UserResource(BackboneCompatibleResource):
|
||||
always_return_data = True
|
||||
filtering = {
|
||||
'user': ALL_WITH_RELATIONS,
|
||||
}
|
||||
'username': ALL,
|
||||
'id': ALL,
|
||||
}
|
||||
|
||||
def full_dehydrate(self, bundle, for_list=False):
|
||||
return super(UserResource, self).full_dehydrate(bundle, for_list)
|
||||
|
||||
def authorized_read_list(self, object_list, bundle):
|
||||
return object_list.filter(user_id=bundle.request.user.id)
|
||||
|
||||
def dehydrate(self, bundle):
|
||||
bundle.data['display_name'] = bundle.obj.display_name
|
||||
@@ -23,25 +31,27 @@ class UserResource(BackboneCompatibleResource):
|
||||
bundle.data['email'] = bundle.obj.email
|
||||
|
||||
if bundle.obj.activity_sharing is not None:
|
||||
bundle.data['activity_share_likes'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_LIKES) != 0;
|
||||
bundle.data['activity_share_favourites'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_FAVOURITES) != 0;
|
||||
bundle.data['activity_share_comments'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_COMMENTS) != 0;
|
||||
bundle.data['activity_share_likes'] = \
|
||||
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_LIKES) != 0
|
||||
bundle.data['activity_share_favourites'] = \
|
||||
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_FAVOURITES) != 0
|
||||
bundle.data['activity_share_comments'] = \
|
||||
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_COMMENTS) != 0
|
||||
else:
|
||||
bundle.data['activity_share_likes'] =0
|
||||
bundle.data['activity_share_favourites'] =0
|
||||
bundle.data['activity_share_comments'] =0
|
||||
bundle.data['activity_share_likes'] = 0
|
||||
bundle.data['activity_share_favourites'] = 0
|
||||
bundle.data['activity_share_comments'] = 0
|
||||
|
||||
if bundle.obj.activity_sharing_networks is not None:
|
||||
bundle.data['activity_share_networks_facebook'] = (bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_FACEBOOK) != 0;
|
||||
bundle.data['activity_share_networks_twitter'] = (bundle.obj.activity_sharing_networks& UserProfile.ACTIVITY_SHARE_NETWORK_TWITTER) != 0;
|
||||
bundle.data['activity_share_networks_facebook'] = \
|
||||
(bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_FACEBOOK) != 0
|
||||
bundle.data['activity_share_networks_twitter'] = \
|
||||
(bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_TWITTER) != 0
|
||||
else:
|
||||
bundle.data['activity_share_networks_facebook'] = 0
|
||||
bundle.data['activity_share_networks_facebook'] = 0
|
||||
return bundle
|
||||
|
||||
def apply_authorization_limits(self, request, object_list):
|
||||
if request.user is not None:
|
||||
return object_list.filter(user=request.user)
|
||||
return bundle
|
||||
|
||||
def hydrate_slug(self, bundle):
|
||||
if bundle.data['slug'] == '':
|
||||
|
||||
18
spa/api/v1/tests.py
Normal file
18
spa/api/v1/tests.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import datetime
|
||||
from django.contrib.auth.models import User
|
||||
from tastypie.test import ResourceTestCase
|
||||
|
||||
|
||||
class UserProfileResourceTest(ResourceTestCase):
|
||||
fixtures = ['test_entries.json']
|
||||
|
||||
def setUp(self):
|
||||
self.deteail_url = '/api/v1/user/'
|
||||
|
||||
def test_put_detail(self):
|
||||
# Grab the current data & modify it slightly.
|
||||
original_data = self.deserialize(self.api_client.get(self.detail_url, format='json', authentication=self.get_credentials()))
|
||||
new_data = original_data.copy()
|
||||
new_data['title'] = 'Updated: First Post'
|
||||
new_data['created'] = '2012-05-01T20:06:12'
|
||||
|
||||
@@ -57,11 +57,13 @@ class UserProfile(_BaseModel):
|
||||
|
||||
return super(UserProfile, self).save(force_insert, force_update, using)
|
||||
|
||||
"""
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
UserProfile.objects.create(user=instance)
|
||||
|
||||
post_save.connect(create_user_profile, sender=User)
|
||||
"""
|
||||
|
||||
def get_username(self):
|
||||
return self.user.username
|
||||
|
||||
@@ -354,6 +354,7 @@ div.event-content td {
|
||||
#sidebar-content-activity {
|
||||
font-size: 85%;
|
||||
}
|
||||
.no-click{
|
||||
cursor: pointer;
|
||||
[data-bypass="true"] {
|
||||
/* Styles */
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -10,8 +10,6 @@ var User = DSSModel.extend({
|
||||
urlRoot:com.podnoms.settings.urlRoot + "user/",
|
||||
isValid:function () {
|
||||
this.errors = {};
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
</form>
|
||||
<a data-bypass="true" style="cursor: hand; cursor: pointer;" id="header-logout-button" onclick="document.getElementById('logout-form').submit();">Logout <i class="icon-eject icon-black"></i>
|
||||
</a>
|
||||
<input type="hidden" name="user_id" value="{{ user.id }}" />
|
||||
</li>
|
||||
{% else %}
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user