django-js-routes icon indicating copy to clipboard operation
django-js-routes copied to clipboard

Group routes

Open muarachmann opened this issue 3 years ago • 4 comments

Hi +1 for this package, While exposing the routes is a good thing, Is there a way one can group the routes exposed and show only some on some certain scenarios?

Imagine when you are not authenticated, and have a dashboard route, I won't want to expose this. How about we have @ellmetha let me know your thoughts on this, or rather if this package handles it in another way. Else I can send a PR for this.

JS_ROUTES_INCLUSION_LIST = [
    {
        'guest': ['home', 'about', 'privacy_policy' .... ]
    }, 
    {
        'auth': ['home', 'about', 'privacy_policy', 'dashboard.index', 'dashboard.posts' .... ]
    }, 
]

With this, a logic can be put on our front-ends as -

{% if user.is_authenticated %}
   {% js_routes group='auth' %}
{% else %}
   {% js_routes group='guest' %}
{% endif %}

muarachmann avatar Nov 13 '21 07:11 muarachmann

I think it makes a lot of sense. Perhaps we would need a JS_ROUTES_INCLUSION_LISTS setting for this though (since we would have many lists):

JS_ROUTES_INCLUSION_LISTS = {
  'guest': ['home', 'about', 'privacy_policy' .... ],
  'auth': ['home', 'about', 'privacy_policy', 'dashboard.index', 'dashboard.posts' .... ],
}

ellmetha avatar Dec 11 '21 21:12 ellmetha

I think it makes a lot of sense. Perhaps we would need a JS_ROUTES_INCLUSION_LISTS setting for this though (since we would have many lists):

JS_ROUTES_INCLUSION_LISTS = {
  'guest': ['home', 'about', 'privacy_policy' .... ],
  'auth': ['home', 'about', 'privacy_policy', 'dashboard.index', 'dashboard.posts' .... ],
}

Yes @ellmetha. Is this in the pipeline?

muarachmann avatar Dec 16 '21 08:12 muarachmann

Yes @ellmetha. Is this in the pipeline?

For now it's not as I don't have much time to allocate to this project. That being said, I will be happy to review any PRs regarding this! 😃

ellmetha avatar Dec 22 '21 21:12 ellmetha

I think this would be a very good feature to have, as it really removes some of the security concerns one could have otherwise. Are you working on a PR for this @muarachmann?

befocken avatar Oct 31 '22 10:10 befocken