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

Why not get organization from session? #216

Closed aryaniyaps closed 3 years ago

aryaniyaps commented 3 years ago

Hey there @bennylope This project has been a great learning tool for me to have multi user accounts in my application. While studying it, I found out that the organization is obtained by an url kwarg.

I just thought, wouldn't it be better to get the Organization pk from the session? Because some requests might not necessarily have the Organization pk in the url.

What is a better implementation? Thanks a lot!

bennylope commented 3 years ago

I just thought, wouldn't it be better to get the Organization pk from the session? Because some requests might not necessarily have the Organization pk in the url.

There are probably a bunch of decisions in the app that are based on the original use case, ongoing use cases, and decisions about tradeoffs. I might rephrase this question, "Can I fetch organizations based on a session value or a request header instead of a URL path?" and the answer is "Yes!". The view mixins as currently implemented all demand an organization identifier in the path, but instead you could extract this from the session or a request header.

What is a better implementation?

None is better per se. I would argue the current implementation is the most straightforward, and is compatibility with the widest range of end-use implementation styles. I would not argue that there is some authoritatively superior way of implementing this.

If you have some ideas about extending the mixins to account for different ways of fetching the organization and/or organization identifier I'd be open to more details and considering some strategies to build out a PR.