bennylope / django-organizations

:couple: Multi-user accounts for Django projects

Home Page:http://django-organizations.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why not get organization from session?

aryaniyaps opened this issue · comments

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!

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.