Monday, May 26, 2014

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

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


On Sat, May 24, 2014 at 7:21 PM, Carlos Perche <carlosfelipeperche@gmail.com> wrote:

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

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CAFE1XCb3TzbjCQYo%2Bt_trECmsknyirxCpyOByKZjmb1svH_RHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment