bennylope / django-organizations

:couple: Multi-user accounts for Django projects
http://django-organizations.readthedocs.org/
BSD 2-Clause "Simplified" License
1.31k stars 212 forks source link

invite url field error #170

Closed bharatnc closed 5 years ago

bharatnc commented 5 years ago

What?

FieldError at /invite/22-NNMJeXMMU3-0/

Cannot resolve keyword 'is_active' into field. Choices are: active, admin, email, id, last_login, logentry, name, organizations_organization, organizations_organizationuser, password, social_auth, staff

How?

After following this https://django-organizations.readthedocs.io/en/latest/custom_usage.html#creating-the-backend and registering the urls for invite, when I try to load a url like http://localhost:8000/invite/22-NNMJeXMMU3-0/ I receive the above error.

Am I missing anything here? I have defined a custom backend for invitation and registration - as given in the documentation and also have registered the same. Using a Proxy Account and AccountUser model from AbstractOrganization and AbstractOrganizationUser.

Also:

        """
        View function that activates the given User by setting `is_active` to
        true if the provided information is verified.
        """
        try:
            user = self.user_model.objects.get(id=user_id, is_active=False) ...
        except self.user_model.DoesNotExist:
            raise Http404(_("Your URL may have expired."))
        if not RegistrationTokenGenerator().check_token(user, token):
            raise Http404(_("Your URL may have expired."))
        form = self.get_form(data=request.POST or None, instance=user)
        if form.is_valid():

This seems to be the code that django is not happy about . File is site-packages/organizations/backends/defaults.py Thanks!

bennylope commented 5 years ago

Hi Bharhat!

Likely the solution is that you're going to need to override the backend class.

It looks like your custom user model doesn't have a field named is_active, which the backend class looks for. If your model is not based on contrib.auth.models.AbstractUser it wouldn't inherit this field name.

bharatnc commented 5 years ago

@bennylope , thank you for the reply. What would you recommend if I were to use custom user model. Is there a specific solution that you would recommend?

bennylope commented 5 years ago

Yep, create a backend class of your own inheriting from the default class so you can override this.

Unfortunately the is_active attribute is used twice, once on line 130 and then again on line 140. Otherwise I'd just edit this right now myself to expose a separate "get_user" method you could override. And then configure this as your default backend (or use it explicitly).

At any rate, this is the recommended way of accommodating any kind of custom model or workflow in the invitation.

There is also a new model-based invitation backend in development, which is pre-release on PyPI (aside from what's in the source code there is very little documentation for this yet though).

bharatnc commented 5 years ago

Thank you @bennylope , I will take a look. :)