Skip to content

Commit

Permalink
Fix feature flag enabled check
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed Jul 5, 2024
1 parent 6b582be commit 6178628
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions backend/hub/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ def __init__(self, *args, **kwargs):

self.initial["org"] = self.user.orgs.first().id

if FeatureFlag.is_enabled("single_domain_round"):
if FeatureFlag.flag_enabled("single_domain_round"):
self.fields["domain"].widget.attrs["disabled"] = True
self.initial["domain"] = Domain.objects.first().id

def clean_org(self):
return self.user.orgs.first().id

def clean_domain(self):
if FeatureFlag.is_enabled("single_domain_round"):
if FeatureFlag.flag_enabled("single_domain_round"):
return Domain.objects.first()
return self.cleaned_data.get("domain")

Expand Down Expand Up @@ -227,7 +227,7 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if not FeatureFlag.is_enabled("enable_candidate_registration"):
if not FeatureFlag.flag_enabled("enable_candidate_registration"):
for key in self.fields.keys():
self.fields[key].widget.attrs["disabled"] = True

Expand All @@ -239,7 +239,7 @@ def __init__(self, *args, **kwargs):
self.fields[key].widget.attrs["required"] = True

def save(self, commit=True):
if not FeatureFlag.is_enabled("enable_candidate_registration"):
if not FeatureFlag.flag_enabled("enable_candidate_registration"):
# This should not happen unless someone messes with the form code
raise PermissionDenied

Expand Down
4 changes: 2 additions & 2 deletions backend/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __str__(self):
return f"{FLAG_CHOICES[self.flag]}"

@staticmethod
def is_enabled(flag: str) -> bool:
def flag_enabled(flag: str) -> bool:
"""
Check if the requested feature flag is enabled
"""
Expand Down Expand Up @@ -538,7 +538,7 @@ def save(self, *args, **kwargs):
if self.id and CandidateVote.objects.filter(candidate=self).exists():
raise ValidationError(_("Cannot update candidate after votes have been cast."))

if FeatureFlag.is_enabled("single_domain_round"):
if FeatureFlag.flag_enabled("single_domain_round"):
self.domain = Domain.objects.first()

# This covers the flow when a candidate is withdrawn as the official proposal or the organization, while
Expand Down
2 changes: 1 addition & 1 deletion backend/hub/social_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update_user_org(org: Organization, token: str, *, in_auth_flow: bool = False
redirect the user to a relevant error page.
"""

if not FeatureFlag.is_enabled("enable_org_registration"):
if not FeatureFlag.flag_enabled("enable_org_registration"):
if in_auth_flow:
raise ImmediateHttpResponse(redirect(reverse("error-org-registration-closed")))
else:
Expand Down
26 changes: 13 additions & 13 deletions backend/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ class OrganizationRegisterRequestCreateView(HubCreateView):
)

def get(self, request, *args, **kwargs):
if not settings.ENABLE_ORG_REGISTRATION_FORM or not FeatureFlag.is_enabled("enable_org_registration"):
if not settings.ENABLE_ORG_REGISTRATION_FORM or not FeatureFlag.flag_enabled("enable_org_registration"):
raise PermissionDenied
return super().get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
if not settings.ENABLE_ORG_REGISTRATION_FORM or not FeatureFlag.is_enabled("enable_org_registration"):
if not settings.ENABLE_ORG_REGISTRATION_FORM or not FeatureFlag.flag_enabled("enable_org_registration"):
raise PermissionDenied
return super().post(request, *args, **kwargs)

Expand Down Expand Up @@ -288,7 +288,7 @@ def post(self, request, *args, **kwargs):

@permission_required_or_403("hub.approve_organization", (Organization, "pk", "pk"))
def organization_vote(request, pk, action):
if not FeatureFlag.is_enabled("enable_org_approval"):
if not FeatureFlag.flag_enabled("enable_org_approval"):
raise PermissionDenied

try:
Expand Down Expand Up @@ -348,7 +348,7 @@ class CandidateListView(HubListView):
template_name = "candidate/list.html"

def get_qs(self):
if FeatureFlag.is_enabled("enable_candidate_voting"):
if FeatureFlag.flag_enabled("enable_candidate_voting"):
return Candidate.objects_with_org.filter(
org__status=Organization.STATUS.accepted, status=Candidate.STATUS.accepted, is_proposed=True
)
Expand Down Expand Up @@ -426,12 +426,12 @@ class CandidateRegisterRequestCreateView(LoginRequiredMixin, HubCreateView):
form_class = CandidateRegisterForm

def get(self, request, *args, **kwargs):
if not FeatureFlag.is_enabled("enable_candidate_registration"):
if not FeatureFlag.flag_enabled("enable_candidate_registration"):
raise PermissionDenied
return super().get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
if not FeatureFlag.is_enabled("enable_candidate_registration"):
if not FeatureFlag.flag_enabled("enable_candidate_registration"):
raise PermissionDenied
return super().post(request, *args, **kwargs)

Expand All @@ -455,7 +455,7 @@ def get_success_url(self):
return reverse("candidate-update", args=(self.object.id,))

def post(self, request, *args, **kwargs):
if FeatureFlag.is_enabled("enable_candidate_registration") or FeatureFlag.is_enabled(
if FeatureFlag.flag_enabled("enable_candidate_registration") or FeatureFlag.flag_enabled(
"enable_candidate_supporting"
):
return super().post(request, *args, **kwargs)
Expand All @@ -464,7 +464,7 @@ def post(self, request, *args, **kwargs):

@permission_required_or_403("hub.vote_candidate", (Candidate, "pk", "pk"))
def candidate_vote(request, pk):
if not FeatureFlag.is_enabled("enable_candidate_voting"):
if not FeatureFlag.flag_enabled("enable_candidate_voting"):
raise PermissionDenied

try:
Expand Down Expand Up @@ -498,7 +498,7 @@ def candidate_vote(request, pk):

@permission_required_or_403("hub.delete_candidate", (Candidate, "pk", "pk"))
def candidate_revoke(request, pk):
if not FeatureFlag.is_enabled("enable_candidate_supporting"):
if not FeatureFlag.flag_enabled("enable_candidate_supporting"):
raise PermissionDenied

candidate = get_object_or_404(Candidate, pk=pk)
Expand All @@ -516,7 +516,7 @@ def candidate_revoke(request, pk):

@permission_required_or_403("hub.support_candidate", (Candidate, "pk", "pk"))
def candidate_support(request, pk):
if not FeatureFlag.is_enabled("enable_candidate_supporting"):
if not FeatureFlag.flag_enabled("enable_candidate_supporting"):
raise PermissionDenied

candidate = get_object_or_404(Candidate, pk=pk, is_proposed=True)
Expand All @@ -537,9 +537,9 @@ def candidate_support(request, pk):
@permission_required_or_403("hub.approve_candidate", (Candidate, "pk", "pk"))
def candidate_status_confirm(request, pk):
if (
FeatureFlag.is_enabled("enable_candidate_registration")
or FeatureFlag.is_enabled("enable_candidate_supporting")
or FeatureFlag.is_enabled("enable_candidate_voting")
FeatureFlag.flag_enabled("enable_candidate_registration")
or FeatureFlag.flag_enabled("enable_candidate_supporting")
or FeatureFlag.flag_enabled("enable_candidate_voting")
):
raise PermissionDenied

Expand Down

0 comments on commit 6178628

Please sign in to comment.