why I change url is showing other user's data?

24 views
Skip to first unread message

Carlos Perche

unread,
May 24, 2014, 7:21:52 PM5/24/14
to django...@googlegroups.com

for exemple, I have following url: http://tenant.com:8000/accounts/test1/edit/

when my user right authenticated is test1, but if I change the url tohttp://tenant.com:8000/accounts/admin/edit/, the data of user admin is showing in profile form and if I change and save this form the admin's data is update.

test1 is a simple user, no superuser nor staff, but have object permission for save, delete, change and view profile

how do I protect the other user's data?

sorry my english

Andromeda Yelton

unread,
May 26, 2014, 10:24:45 AM5/26/14
to django...@googlegroups.com
The urlpattern is telling your view (I assume a subclass of UpdateView?) which instance of your User model to edit, but that's all the urlpattern gets you - there's nothing built in about permissions. You need to write permission restrictions yourself.

There's a whole bunch of ways you can do this. Something I've done:

from django.core.exceptions import PermissionDenied

[...]

class UserUpdateView(UpdateView):
    [...]

    def dispatch(self, request, *args, **kwargs):
        if not self.request.user == self.object:
            raise PermissionDenied
        super(UserUpdateView, self).dispatch(request, *args, **kwargs)

I can think of a couple other things you might try and I don't know what's most stylish, but that'll work.

Andromeda Yelton
LITA Board of Directors, Director-at-Large, 2013-2016
@ThatAndromeda


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8025d812-6b2f-4a60-8538-6ea060b0fa34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages