Skip to content

Commit

Permalink
Flag for disableing the organization and candidate update button (#378)
Browse files Browse the repository at this point in the history
* Add the ORG_EDITING_ENABLED flag to the context
* Prevent POSTing new candidate or org date if the flags are disabled

---------

Co-authored-by: Tudor Amariei <[email protected]>
  • Loading branch information
danniel and tudoramariei authored Dec 2, 2024
1 parent cd70155 commit 39c4104
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 52 deletions.
2 changes: 2 additions & 0 deletions backend/hub/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def hub_settings(_: HttpRequest) -> Dict[str, Any]:
candidate_confirmation_enabled = flags.get(FLAG_CHOICES.enable_candidate_confirmation, False)
results_enabled = flags.get(FLAG_CHOICES.enable_results_display, False)
org_approval_enabled = flags.get(FLAG_CHOICES.enable_org_approval, False)
org_editing_enabled = flags.get(FLAG_CHOICES.enable_org_editing, False)
org_registration_enabled = flags.get(FLAG_CHOICES.enable_org_registration, False)

return {
Expand All @@ -44,6 +45,7 @@ def hub_settings(_: HttpRequest) -> Dict[str, Any]:
"CANDIDATE_CONFIRMATION_ENABLED": candidate_confirmation_enabled,
"RESULTS_ENABLED": results_enabled,
"ORG_APPROVAL_ENABLED": org_approval_enabled,
"ORG_EDITING_ENABLED": org_editing_enabled,
"ORG_REGISTRATION_ENABLED": org_registration_enabled,
# Settings flags
"GLOBAL_SUPPORT_ENABLED": flags.get(SETTINGS_CHOICES.global_support_round, False),
Expand Down
20 changes: 11 additions & 9 deletions backend/hub/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,21 @@ def _set_fields_permissions(self):

# If registration is closed, updating the organization/candidate shouldn't be possible
# it should be possible if they have a registered candidate and the organization editing is enabled
if not (
hasattr(self.instance, "candidate")
and self.instance.candidate
and self.instance.candidate.is_proposed
and FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing)
) and not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_candidate_registration):
if (
not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing)
or not (
hasattr(self.instance, "candidate") and self.instance.candidate and self.instance.candidate.is_proposed
)
and not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_candidate_registration)
):
for field_name in self.fields:
self.fields[field_name].disabled = True

if "voting_domain" in self.fields:
self.fields["voting_domain"].disabled = self.instance.voting_domain is not None
if not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing):
self.fields["voting_domain"].disabled = True
else:
self.fields["voting_domain"].disabled = self.instance.voting_domain is not None

return

Expand Down Expand Up @@ -308,7 +312,6 @@ class Meta:


class CandidateRegisterForm(CandidateCommonForm):

class Meta(CandidateCommonForm.Meta):
widgets = {
"is_proposed": forms.HiddenInput(),
Expand Down Expand Up @@ -343,7 +346,6 @@ def clean(self):


class CandidateUpdateForm(CandidateCommonForm):

class Meta(CandidateCommonForm.Meta):
exclude: List[str] = ["org", "initial_org", "status", "status_changed"]

Expand Down
91 changes: 49 additions & 42 deletions backend/hub/templates/hub/ngo/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ <h2 class="title border-b uppercase">Profilul organizației</h2>
<br><br>
{% endif %}

{% if voting_domain_warning %}

<div class="message is-warning">
<div class="message-body">
<p>
<strong>
<i class="fas fa-exclamation-triangle"></i>
{% trans "Warning!" %}
</strong>
</p>
<p>
{{ voting_domain_warning }}
</p>
</div>
</div>

{% endif %}

<div class="container">
{% if messages %}
Expand All @@ -82,36 +65,56 @@ <h2 class="title border-b uppercase">Profilul organizației</h2>
</article>
{% endif %}

{% if not organization.is_fully_editable %}
<div class="message {{ update_button_class }}">
<div class="message-body flex-align-center">
<form
id="update-ngo-form"
method="post"
action="{% url 'ngo-update-post' organization.id %}?return_url={{ request.path }}">
{% csrf_token %}
<button
class="button {{ update_button_class }} is-small update-ngo-button"
type="submit"
title="{% trans 'Refresh NGO Information' %}">
<i class="fas fa-sync"></i>
</button>
</form>

{% if organization.status == "pending" %}
<h4 style="padding-right: 2rem" class="is-danger">
{% trans "Some data wasn't found on NGO Hub." %}
</h4>
{% endif %}

<p class="has-text-grey-dark">
{% if voting_domain_warning and ORG_EDITING_ENABLED %}
<div class="message is-warning">
<div class="message-body">
<p>
<strong>
{{ update_button_message }}
<i class="fas fa-exclamation-triangle"></i>
{% trans "Warning!" %}
</strong>
({{ update_button_description }})
</p>
<p>
{{ voting_domain_warning }}
</p>
</div>
</div>
{% endif %}

{% if not organization.is_fully_editable %}

{% if ORG_EDITING_ENABLED %}
<div class="message {{ update_button_class }}">
<div class="message-body flex-align-center">
<form
id="update-ngo-form"
method="post"
action="{% url 'ngo-update-post' organization.id %}?return_url={{ request.path }}">
{% csrf_token %}
<button
class="button {{ update_button_class }} is-small update-ngo-button"
type="submit"
title="{% trans 'Refresh NGO Information' %}">
<i class="fas fa-sync"></i>
</button>
</form>

{% if organization.status == "pending" %}
<h4 style="padding-right: 2rem" class="is-danger">
{% trans "Some data wasn't found on NGO Hub." %}
</h4>
{% endif %}

<p class="has-text-grey-dark">
<strong>
{{ update_button_message }}
</strong>
({{ update_button_description }})
</p>
</div>
</div>
{% endif %}

<form class="ces-form" method="post" enctype="multipart/form-data">
{% csrf_token %}
Expand All @@ -137,7 +140,11 @@ <h4 style="padding-right: 2rem" class="is-danger">
{{ form|crispy }}

<div class="has-text-right">
<input class="button is-success" type="submit" value='{% trans "Update organization" %}'>
{% if CANDIDATE_EDITING_ENABLED or ORG_EDITING_ENABLED %}
<input class="button is-success" type="submit" value='{% trans "Update organization" %}'>
{% else %}
<input class="button" disabled="disabled" value='{% trans "Update organization" %}'>
{% endif %}
</div>

</form>
Expand Down
12 changes: 11 additions & 1 deletion backend/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
OrganizationUpdateForm,
)
from hub.models import (
FLAG_CHOICES,
PHASE_CHOICES,
SETTINGS_CHOICES,
BlogPost,
Expand Down Expand Up @@ -505,7 +506,16 @@ def get_success_url(self):
return reverse("ngo-update", args=(self.object.id,))

def post(self, request, *args, **kwargs):
return super().post(request, *args, **kwargs)
if FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing) or FeatureFlag.flag_enabled(
FLAG_CHOICES.enable_candidate_editing
):
return super().post(request, *args, **kwargs)

ngo_id = self.kwargs.get("pk")
if not ngo_id:
return redirect("home")

return redirect(reverse("ngo-update", args=(ngo_id,)))


@permission_required_or_403("hub.approve_organization")
Expand Down

0 comments on commit 39c4104

Please sign in to comment.