Commit c08bccee authored by Birin Sanchez's avatar Birin Sanchez
Browse files

Add beta functionality using 'beta' LDAP group and BetaAccessMixin


Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent e7071c8e
Pipeline #53237 passed with stage
in 36 seconds
from django.contrib.auth.mixins import AccessMixin
from django.conf import settings
from django.urls import reverse
from django.http import HttpResponseRedirect
class BetaAccessMixin(AccessMixin):
"""
CBV mixin which verifies if the current user is member of beta
LDAP group. If is not member it redirecs the request to profile
page.
"""
def dispatch(self, request, *args, **kwargs):
if not request.user.is_ldap_member(settings.BETA_LDAP_GROUP):
return HttpResponseRedirect(reverse('profile'))
return super(BetaAccessMixin, self).dispatch(request, *args, **kwargs)
......@@ -297,3 +297,8 @@ EMAIL_USE_SSL = config('EMAIL_USE_SSL', False, cast=bool)
# This is the link to the subscribe page, used in different parts of the middleware
SUBSCRIBE_HREF = config('SUBSCRIBE_HREF')
#
# BETA FEATURES ACCESS
#
BETA_LDAP_GROUP = config("BETA_LDAP_GROUP", default='beta')
......@@ -143,6 +143,16 @@ class User(AbstractUser):
ldap_group.members.remove(ldap_person.build_dn())
ldap_group.save()
def is_ldap_member(self, group_id):
ldap_person = self.get_ldap()
try:
ldap_group = LdapGroup.objects.get(cn=group_id)
except LdapGroup.DoesNotExist:
logging.warning('LDAP group "{}" does not exist.'.format(group_id))
return False
u_dn = ldap_person.build_dn()
return u_dn in ldap_group.members
def woo_get_json(self, query):
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment