Skip to content

Commit 39c4104

Browse files
Flag for disableing the organization and candidate update button (#378)
* 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]>
1 parent cd70155 commit 39c4104

File tree

4 files changed

+73
-52
lines changed

4 files changed

+73
-52
lines changed

backend/hub/context_processors.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def hub_settings(_: HttpRequest) -> Dict[str, Any]:
2323
candidate_confirmation_enabled = flags.get(FLAG_CHOICES.enable_candidate_confirmation, False)
2424
results_enabled = flags.get(FLAG_CHOICES.enable_results_display, False)
2525
org_approval_enabled = flags.get(FLAG_CHOICES.enable_org_approval, False)
26+
org_editing_enabled = flags.get(FLAG_CHOICES.enable_org_editing, False)
2627
org_registration_enabled = flags.get(FLAG_CHOICES.enable_org_registration, False)
2728

2829
return {
@@ -44,6 +45,7 @@ def hub_settings(_: HttpRequest) -> Dict[str, Any]:
4445
"CANDIDATE_CONFIRMATION_ENABLED": candidate_confirmation_enabled,
4546
"RESULTS_ENABLED": results_enabled,
4647
"ORG_APPROVAL_ENABLED": org_approval_enabled,
48+
"ORG_EDITING_ENABLED": org_editing_enabled,
4749
"ORG_REGISTRATION_ENABLED": org_registration_enabled,
4850
# Settings flags
4951
"GLOBAL_SUPPORT_ENABLED": flags.get(SETTINGS_CHOICES.global_support_round, False),

backend/hub/forms.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,21 @@ def _set_fields_permissions(self):
196196

197197
# If registration is closed, updating the organization/candidate shouldn't be possible
198198
# it should be possible if they have a registered candidate and the organization editing is enabled
199-
if not (
200-
hasattr(self.instance, "candidate")
201-
and self.instance.candidate
202-
and self.instance.candidate.is_proposed
203-
and FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing)
204-
) and not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_candidate_registration):
199+
if (
200+
not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing)
201+
or not (
202+
hasattr(self.instance, "candidate") and self.instance.candidate and self.instance.candidate.is_proposed
203+
)
204+
and not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_candidate_registration)
205+
):
205206
for field_name in self.fields:
206207
self.fields[field_name].disabled = True
207208

208209
if "voting_domain" in self.fields:
209-
self.fields["voting_domain"].disabled = self.instance.voting_domain is not None
210+
if not FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing):
211+
self.fields["voting_domain"].disabled = True
212+
else:
213+
self.fields["voting_domain"].disabled = self.instance.voting_domain is not None
210214

211215
return
212216

@@ -308,7 +312,6 @@ class Meta:
308312

309313

310314
class CandidateRegisterForm(CandidateCommonForm):
311-
312315
class Meta(CandidateCommonForm.Meta):
313316
widgets = {
314317
"is_proposed": forms.HiddenInput(),
@@ -343,7 +346,6 @@ def clean(self):
343346

344347

345348
class CandidateUpdateForm(CandidateCommonForm):
346-
347349
class Meta(CandidateCommonForm.Meta):
348350
exclude: List[str] = ["org", "initial_org", "status", "status_changed"]
349351

backend/hub/templates/hub/ngo/update.html

+49-42
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@ <h2 class="title border-b uppercase">Profilul organizației</h2>
5353
<br><br>
5454
{% endif %}
5555

56-
{% if voting_domain_warning %}
57-
58-
<div class="message is-warning">
59-
<div class="message-body">
60-
<p>
61-
<strong>
62-
<i class="fas fa-exclamation-triangle"></i>
63-
{% trans "Warning!" %}
64-
</strong>
65-
</p>
66-
<p>
67-
{{ voting_domain_warning }}
68-
</p>
69-
</div>
70-
</div>
71-
72-
{% endif %}
7356

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

85-
{% if not organization.is_fully_editable %}
86-
<div class="message {{ update_button_class }}">
87-
<div class="message-body flex-align-center">
88-
<form
89-
id="update-ngo-form"
90-
method="post"
91-
action="{% url 'ngo-update-post' organization.id %}?return_url={{ request.path }}">
92-
{% csrf_token %}
93-
<button
94-
class="button {{ update_button_class }} is-small update-ngo-button"
95-
type="submit"
96-
title="{% trans 'Refresh NGO Information' %}">
97-
<i class="fas fa-sync"></i>
98-
</button>
99-
</form>
100-
101-
{% if organization.status == "pending" %}
102-
<h4 style="padding-right: 2rem" class="is-danger">
103-
{% trans "Some data wasn't found on NGO Hub." %}
104-
</h4>
105-
{% endif %}
10668

107-
<p class="has-text-grey-dark">
69+
{% if voting_domain_warning and ORG_EDITING_ENABLED %}
70+
<div class="message is-warning">
71+
<div class="message-body">
72+
<p>
10873
<strong>
109-
{{ update_button_message }}
74+
<i class="fas fa-exclamation-triangle"></i>
75+
{% trans "Warning!" %}
11076
</strong>
111-
({{ update_button_description }})
77+
</p>
78+
<p>
79+
{{ voting_domain_warning }}
11280
</p>
11381
</div>
11482
</div>
83+
{% endif %}
84+
85+
{% if not organization.is_fully_editable %}
86+
87+
{% if ORG_EDITING_ENABLED %}
88+
<div class="message {{ update_button_class }}">
89+
<div class="message-body flex-align-center">
90+
<form
91+
id="update-ngo-form"
92+
method="post"
93+
action="{% url 'ngo-update-post' organization.id %}?return_url={{ request.path }}">
94+
{% csrf_token %}
95+
<button
96+
class="button {{ update_button_class }} is-small update-ngo-button"
97+
type="submit"
98+
title="{% trans 'Refresh NGO Information' %}">
99+
<i class="fas fa-sync"></i>
100+
</button>
101+
</form>
102+
103+
{% if organization.status == "pending" %}
104+
<h4 style="padding-right: 2rem" class="is-danger">
105+
{% trans "Some data wasn't found on NGO Hub." %}
106+
</h4>
107+
{% endif %}
108+
109+
<p class="has-text-grey-dark">
110+
<strong>
111+
{{ update_button_message }}
112+
</strong>
113+
({{ update_button_description }})
114+
</p>
115+
</div>
116+
</div>
117+
{% endif %}
115118

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

139142
<div class="has-text-right">
140-
<input class="button is-success" type="submit" value='{% trans "Update organization" %}'>
143+
{% if CANDIDATE_EDITING_ENABLED or ORG_EDITING_ENABLED %}
144+
<input class="button is-success" type="submit" value='{% trans "Update organization" %}'>
145+
{% else %}
146+
<input class="button" disabled="disabled" value='{% trans "Update organization" %}'>
147+
{% endif %}
141148
</div>
142149

143150
</form>

backend/hub/views.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
OrganizationUpdateForm,
4444
)
4545
from hub.models import (
46+
FLAG_CHOICES,
4647
PHASE_CHOICES,
4748
SETTINGS_CHOICES,
4849
BlogPost,
@@ -505,7 +506,16 @@ def get_success_url(self):
505506
return reverse("ngo-update", args=(self.object.id,))
506507

507508
def post(self, request, *args, **kwargs):
508-
return super().post(request, *args, **kwargs)
509+
if FeatureFlag.flag_enabled(FLAG_CHOICES.enable_org_editing) or FeatureFlag.flag_enabled(
510+
FLAG_CHOICES.enable_candidate_editing
511+
):
512+
return super().post(request, *args, **kwargs)
513+
514+
ngo_id = self.kwargs.get("pk")
515+
if not ngo_id:
516+
return redirect("home")
517+
518+
return redirect(reverse("ngo-update", args=(ngo_id,)))
509519

510520

511521
@permission_required_or_403("hub.approve_organization")

0 commit comments

Comments
 (0)