Commit a63a4480 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 72ee878b
Pipeline #52561 failed with stages
in 3 minutes and 11 seconds
......@@ -165,9 +165,12 @@ SPDX-License-Identifier: AGPL-3.0
{% if can_upgrade or pending_upgrade %}
<li><a href="{% url 'upgrade' %}">{% trans "Manage Subscription" %}</a></li>
{% endif %}
{% if beta_access %}
<li><a href="{% url 'storage' %}">{% trans "Storage" %}</a></li>
{% endif %}
</ul>
{% if beta_access %}
<h2>{% trans "Profile summary" %}</h2>
<ul>
......@@ -178,7 +181,7 @@ SPDX-License-Identifier: AGPL-3.0
{% endif %}
<li>{% trans "Status: " %} {% if locked %} {% trans "Locked" %} {% else %} {% trans "Active "%}{% endif %}</li>
</ul>
{% endif %}
</article>
<nav class="col-2">
<ul>
......
......@@ -89,7 +89,8 @@ def userlimit(request):
"can_upgrade": can_upgrade,
"pending_upgrade": len(pending_upgrade) >= 1,
"rma": request.user.rma,
"locked": request.user.is_locked
"locked": request.user.is_locked,
"beta_access": request.user.is_ldap_member(settings.BETA_LDAP_GROUP)
}
return render(request, 'limitmonitor/userlimit.html', render_data)
......
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)
......@@ -327,3 +327,8 @@ STORAGE_PURGE_DAY = config("STORAGE_FINAL_WARNING_DAY",
STORAGE_COST = config("STORAGE_COST", default=10)
STORAGE_POLICY_ENABLED = config("STORAGE_POLICY_ENABLED", False, cast=bool)
#
# BETA FEATURES ACCESS
#
BETA_LDAP_GROUP = config("BETA_LDAP_GROUP", default='beta')
......@@ -153,6 +153,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:
......
......@@ -24,6 +24,7 @@ from limitmonitor.common import delete_account, parse_order, OrderParseError, \
offends_storage_policy, calculate_rma, update_storage_subscription
from limitmonitor.subscription import SubscriptionManager, SubscriptionStatus
from purist.models import AccountType
from middleware.beta_access import BetaAccessMixin
class UserDetail(APIView):
......@@ -162,7 +163,7 @@ class DeleteAccountView(LoginRequiredMixin, FormView):
return context
class StorageView(LoginRequiredMixin, TemplateView):
class StorageView(LoginRequiredMixin, BetaAccessMixin, TemplateView):
template_name = "purist/storage.html"
def get_context_data(self, **kwargs):
......@@ -195,7 +196,7 @@ class StorageView(LoginRequiredMixin, TemplateView):
return context
class ActivatePAYGView(LoginRequiredMixin, RedirectView):
class ActivatePAYGView(LoginRequiredMixin, BetaAccessMixin, RedirectView):
pattern_name = 'storage'
def get_redirect_url(self, *args, **kwargs):
......@@ -215,7 +216,7 @@ class ActivatePAYGView(LoginRequiredMixin, RedirectView):
return super(ActivatePAYGView, self).get_redirect_url(*args, **kwargs)
class DeactivatePAYGView(LoginRequiredMixin, RedirectView):
class DeactivatePAYGView(LoginRequiredMixin, BetaAccessMixin, RedirectView):
pattern_name = 'storage'
def get_redirect_url(self, *args, **kwargs):
......
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