Search code examples
pythondjangouser-profile

Django: userena edit profile forbidden


I've installed django-userena to manage user profiles and everything works fine except new registered users unable to edit/update their profiles and face just blank screen.

If I make the user a superuser then it can change/update profile.

Found that profile_edit view in django-userena decorated with @permission_required_or_403('change_profile', (get_profile_model(), 'user__username', 'username'))

Obviously need to add post_save signal to add necessary permission and nevertheless I was wondering if there any settings like USERENA_ALLOW_UPDATE_PROFILE can anyone help me on this?


Solution

  • Finally digging around django-userena and django-guardian sources I present my output of this little research, so if you want the users to be able to edit their profile you can use the following code

    User post save signal which adds 'change_profile' permission to new user objects

    @receiver(post_save, sender=User, dispatch_uid='user.created')
    def user_created(sender, instance, created, raw, using, **kwargs):
      """ Adds 'change_profile' permission to created user objects """
      if created:
        from guardian.shortcuts import assign
        assign('change_profile', instance, instance.get_profile())