jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.28k stars 618 forks source link

compatibility issues with linux #201

Closed ak-24 closed 9 years ago

ak-24 commented 9 years ago

i used django-push-notifications in windows , it was working fine , i used

router.register(r'device/gcm', GCMDeviceViewSet)

to add new devices and it was working fine but when i ported my app to a linux system the response i get is the device is sucessfully added but when i check device list nothing is added

Proper-Job commented 9 years ago

You're not providing many specifics that would help to diagnose the problem. I have django-push-notifications successfully deployed on Debian 7 "Wheezy". There are no Linux related issues AFAIK.

ak-24 commented 9 years ago

@Alp-Phone @jleclanche I am using rest api's in my app and when using the url " http://server_ip/device/gcm/ " i post json data to my app

{
    "name": "jjjjjjjjje",
     "registration_id": "fIy4VQKVchY:APA91bHkRYkaPs3alSE1Ve6l-NBXrzigjhaT43C6iMkjglR25y75GbZ4lRxZF2-9wpstbzKzF-cbce7rsMcozYF1QaNKptAoz3LwntR4ZjfemUkU0oBsLxN6K3339h9BIPBd9v6Pg_vX",
    "device_id": "77989",
    "active": "true"
}

i get a success response but when i check the devices list through admin panel nothing is added there.

jamaalscarlett commented 9 years ago

Have you tried adding the device using the browsable api? Try this curl command: curl http://**SERVER_IP**/gcm/ -u USERNAME:PASSWORD -d "name= jjjjjjjjje&registration_id=fIy4VQKVchY:APA91bHkRYkaPs3alSE1Ve6l-NBXrzigjhaT43C6iMkjglR25y75GbZ4lRxZF2-9wpstbzKzF-cbce7rsMcozYF1QaNKptAoz3LwntR4ZjfemUkU0oBsLxN6K3339h9BIPBd9v6Pg_vX&device_id= 77989&active=true"
the response should be: {"name":"jjjjjjjjje","registration_id":"fIy4VQKVchY:APA91bHkRYkaPs3alSE1Ve6l-NBXrzigjhaT43C6iMkjglR25y75GbZ4lRxZF2-9wpstbzKzF-cbce7rsMcozYF1QaNKptAoz3LwntR4ZjfemUkU0oBsLxN6K3339h9BIPBd9v6Pg_vX","device_id": 77989,"active":true,"date_created":"2015-09-02T13:33:10.255785Z"}

ak-24 commented 9 years ago

@jamaalscarlett in post request i am getting 201 created status and the response is { name: "jjjjjjjjje" registration_id: "fIy4VQKVchY:APA91bHkRYkaPs3alSE1Ve6l-NBXrzigjhaT43C6iMkjglR25y75GbZ4lRxZF2-9wpstbzKzF-cbce7rsMcozYF1QaNKptAoz3LwntR4ZjfemUkU0oBsLxN6K3339h9BIPBd9v6Pg_vX" device_id: 489865 active: true }

but it is not added in gcm devices list when i access the gcm devices list through admin panel

request url http://172.16.171.9/device/gcm/ post data { "name": "jjjjjjjjje", "registration_id": "fIy4VQKVchY:APA91bHkRYkaPs3alSE1Ve6l-NBXrzigjhaT43C6iMkjglR25y75GbZ4lRxZF2-9wpstbzKzF-cbce7rsMcozYF1QaNKptAoz3LwntR4ZjfemUkU0oBsLxN6K3339h9BIPBd9v6Pg_vX", "device_id": "77989", "active": "true" }

jamaalscarlett commented 9 years ago

What db backend are you using? Can you verify directly that the device has been entered? ie. pgadmin etc

ak-24 commented 9 years ago

@jamaalscarlett currently it is default db backend of django: sqlite

jamaalscarlett commented 9 years ago

Are you using the build in django-rest-framework implementation, or did you write your own?

ak-24 commented 9 years ago

@jamaalscarlett i am using it in django rest framework

jamaalscarlett commented 9 years ago

Right, but DRF viewsets were added to django-push-notifications in the last release. Are you using those or did you write your own implementation. If you wrote your own, I would need to see a code snippet to help diagnose your problem.

ak-24 commented 9 years ago

@jamaalscarlett yes i am using drf viewsets of last release

urls.py

from django.conf.urls import include, url from django.contrib import admin

from push_notifications.api.rest_framework import APNSDeviceViewSet, GCMDeviceViewSet from rest_framework.routers import DefaultRouter

router = DefaultRouter() router.register(r'device/apns', APNSDeviceViewSet) router.register(r'device/gcm', GCMDeviceViewSet)

urlpatterns = [ url(r'^', include(router.urls)),

url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^Login/', include('Login.urls')),

]

jamaalscarlett commented 9 years ago

I'm not sure that that is correct. If you are using the built in DRF viewsets, the response should contain the date_created

ak-24 commented 9 years ago

image image

ak-24 commented 9 years ago

@jamaalscarlett any files like settings.py or urls.py you want to check out ?

jamaalscarlett commented 9 years ago

screen shot 2015-09-02 at 11 01 34 am

jamaalscarlett commented 9 years ago

yes complete settings.py and urls.py. Are you installing django-push-notifications from pip or are you manually building and installing?

ak-24 commented 9 years ago

@jamaalscarlett I am installing django-push-notifications through pip

Can i get a link to your app so that i can trace out the mistake in my code or any in other way i could correct my code

jamaalscarlett commented 9 years ago

Unfortunately, it is from a project I am working on that is not open-source. But if you can give me access to your app code, I could take a look.

ak-24 commented 9 years ago

@jamaalscarlett Sending a link to my project in mail

jamaalscarlett commented 9 years ago

@ak-24 sounds good

jamaalscarlett commented 9 years ago

@ak-24 Have you sent the email, I have not received it.

ak-24 commented 9 years ago

Had some issues with my internet connection i have sent it now

JosephAMParker commented 9 years ago

Hey guys, any luck solving this problem? I'm getting the same thing, I recieve status code 201 and it says the object was created but nothing is added. Also the response doesn't contain the date_created.

I can however go to http://0.0.0.0:8000/device/gcm/ and create an object and post and it successfully puts it in the database. This only works though if I am logged into http://0.0.0.0:8000/admin, I think this might be a part of the problem. If I log out of http://0.0.0.0:8000/admin, then create and post a device at http://0.0.0.0:8000/device/gcm/, it says it's successful, but the response has no creation time and nothing is added to the database. I thought if you are using GCMDeviceViewSet the user doesn't need to be authenticated?

Proper-Job commented 9 years ago

That's correct, if you use GCMDeviceViewSet the user doesn't need to be authenticated. GCMDeviceAuthorizedViewSet requires the user to be logged in and will return a 403 FORBIDDEN if she's not. Are you both using Chrome's RestClient when the operation fails? @ak-24 have you tried creating a GCM from DRF's browsable API?

jamaalscarlett commented 9 years ago

I worked with @ak-24 last night and found that this bug was introduced with the initial django rest framework support. There was a fix check in here https://github.com/jleclanche/django-push-notifications/commit/06792931b5c23a9d5d85c908fcffd7c51259755b, but I'm not sure that is the right approach. The initial bug occurs because the viewset was requiring authentication to save the model to the db, but not returning any error if the user was authenticated. The fix changed the code to save the model even if the request user is not authenticated, which IMO breaks the original intent of the viewset. Currently there are two viewsets, one has no authentication, GCMDeviceViewSet, and one that only allows a user access to objects they created. I think a third viewset should be added in between the two, that requires an authenticated request user, and returns the proper error message when an anonymous request is sent.

ak-24 commented 9 years ago

half of my problem is solved my rest framework settings were wrong i had this: REST_FRAMEWORK = {

Use Django's standard django.contrib.auth permissions,

or allow read-only access for unauthenticated users.

'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.AllowAny' ] } I configured it for token authentication, but was never sending a token I added Session authentication like this: REST_FRAMEWORK = {

Use Django's standard django.contrib.auth permissions,

or allow read-only access for unauthenticated users.

'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.AllowAny' ] }

ak-24 commented 9 years ago

issue fully resolved one last thing needed was to pull latest version and build it

PS: special thanks to @jamaalscarlett he helped a lot and guided me at every step to resolve my issue.

Proper-Job commented 9 years ago

@jamaalscarlett I don't follow completely. Was @ak-24 issue a configuration issue? In my tests using GCMDeviceAuthorizedViewSet returns a 403 as it should for users that aren't logged in.

jamaalscarlett commented 9 years ago

It was a configuration issue. He was not using GCMDeviceAuthorizedViewSet, he was using GCMDeviceViewSet, which still required authentication to save the model, but did return any error when the request was not authenticated. He was also not using the latest from the master branch, he was running 1.3.1 from PyPi, which had the bug I referenced above.

Proper-Job commented 9 years ago

Are we talking about the difference between Authentication and Authorization? Did @ak-24 make an authenticated request, but the user wasn't authorized to create a GCMDevice object? Does the GCMDeviceAuthorizedViewSet simply check whether or not the user is logged in but not whether or not he has permissions to create a device object? Is that the problem?

jamaalscarlett commented 9 years ago

@ak-24 made an un-authenticated request to GCMDeviceViewSet. The viewset was not saving the model, but it was also not returning any error indicating that the request was un-authenticated. GCMDeviceAuthorizedViewSet requires both authentication and authorization. But this means that you could not have an endpoint that would return all devices, because only the devices you created would be returned. What I proposed was a third viewset that required authentication only, allowing accessing to all objects, not just the ones I have created.

Proper-Job commented 9 years ago

@jamaalscarlett I agree there should be a third endpoint that indiscriminately returns all devices belonging to all users once authentication has been established. As to @ak-24 original issue, do you think action is needed? He shouldn't have gotten a 201 Created since token authentication wasn't working. Or do we file this under configuration error?

jamaalscarlett commented 9 years ago

@ak-24's original issue has already been addressed. The latest code on master no longer has the problem.

Proper-Job commented 9 years ago

Ok, great. Sorry a bit slow on the uptake ; )

jamaalscarlett commented 9 years ago

NP. I was just looking over the DRF code, @matthewh, is there a reason you chose registration_id as the lookup field? I would think that using the id would provide faster lookup times.

matthewh commented 9 years ago

@jamaalscarlett I chose the registration_id as the lookup field because I didn't want clients to also need to track the id for updates. The registration_id and the id are both unique and the client already knows the registration_id.

After bringing myself up to speed on this thread I think an additional section in the documentation would help to address the various DRF configuration use cases. It is difficult to predict what combination of authenticated/authorized an application developer might desire. If you think it would be useful I can write something up.

jamaalscarlett commented 9 years ago

@matthewh I think a page on the wiki would be great.