nitely / Spirit

Spirit is a modern Python based forum built on top of Django framework
http://spirit.readthedocs.io
MIT License
1.16k stars 332 forks source link

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

Open sureshvv opened 11 months ago

sureshvv commented 11 months ago

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

nitely commented 11 months ago

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 commented 11 months ago

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.

sureshvv commented 11 months ago

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.

nitely commented 11 months ago

ye, one way is monkey patching this view

nitely commented 11 months ago

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.