DEV Community

Discussion on: Dynamic Group based LDAP authentication with django and RegEx

Collapse
 
arezazadeh profile image
Ahmad

question, if i want to attach the group name to user's session, so i can grab it in the template and use it to show or not show some content based on that, how do i accomplish that? today i can do it because i have local user in django db, but if i integrate with corporate AD, then i lose that flexibility. i wanna say, if you are part of this group you will not be able to see these content, or you will not be able to access these features, and so on.

Collapse
 
lquenti profile image
Lars Quentin

If I understand you correctly:

Hide Content:

  • Dynamically create the group as done above.
  • Pass the groups to the view renderer
  • Exclude the code based on conditionals with the django templating engine / Jinja2

Permit View:
Probably the cleanest way would be to create a decorator with functools.wraps.
In this decorator you'd get the group from the request and then permit or deny based on the group names.