Spirit icon indicating copy to clipboard operation
Spirit copied to clipboard

Have setting SPIRIT_AUTH_USER_MODEL (defaults to the AUTH_USER_MODEL) but can be overridden

Open sureshvv opened this issue 2 years ago • 5 comments

Don't want all users on my site to be spirit users

sureshvv avatar Aug 04 '23 07:08 sureshvv

I think there is no way to do that. If you share the DB between your site and Spirit, all users will be Spirit users. If you don't create a Spirit user profile, it won't matter, because the user is authenticated and assigned to request.user anyway. ~~You would only get an error about the profile not existing for the user when visiting the Spirit user profile.~~ on a second thought, if you point Spirit profile to some model other than the Django user model or a custom one defined as AUTH_USER_MODEL, Spirit won't work at all.

Not sure you can have two user models in Django.

nitely avatar Aug 04 '23 08:08 nitely

If you want to forbid some users from accessing the forum, you are better off creating a model with a OneToOneField to Django user model, and some is_forum_allowed field. Then use that field to check if the user can access the forum. The check can be done in a custom middleware similar to this one, but redirecting them to your site if they are not allowed.

nitely avatar Aug 04 '23 08:08 nitely

I have done that. Only thing is still all the users show up in spirit:admin:users.

I was looking for a non-intrusive way of listing only the spirit users.

sureshvv avatar Aug 04 '23 16:08 sureshvv

ye, one way is monkey patching this view

nitely avatar Aug 04 '23 16:08 nitely

probably something like this in a custom app:

from spirit.user.admin import views
org_index = views._index
def new_index(request, queryset, template):
    return org_index(request, queryset.filter(custom_user__has_forum_access=True), template)
views._index = new_index

Another way is overriding the template and filtering there.

nitely avatar Aug 04 '23 16:08 nitely