diff --git a/backend/hub/context_processors.py b/backend/hub/context_processors.py index 603b35ac..12fd7cc6 100644 --- a/backend/hub/context_processors.py +++ b/backend/hub/context_processors.py @@ -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 { @@ -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), diff --git a/backend/hub/forms.py b/backend/hub/forms.py index 937c551c..4916bf02 100644 --- a/backend/hub/forms.py +++ b/backend/hub/forms.py @@ -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 @@ -308,7 +312,6 @@ class Meta: class CandidateRegisterForm(CandidateCommonForm): - class Meta(CandidateCommonForm.Meta): widgets = { "is_proposed": forms.HiddenInput(), @@ -343,7 +346,6 @@ def clean(self): class CandidateUpdateForm(CandidateCommonForm): - class Meta(CandidateCommonForm.Meta): exclude: List[str] = ["org", "initial_org", "status", "status_changed"] diff --git a/backend/hub/templates/hub/ngo/update.html b/backend/hub/templates/hub/ngo/update.html index c934699a..03790c0c 100644 --- a/backend/hub/templates/hub/ngo/update.html +++ b/backend/hub/templates/hub/ngo/update.html @@ -53,23 +53,6 @@

Profilul organizației



{% endif %} - {% if voting_domain_warning %} - -
-
-

- - - {% trans "Warning!" %} - -

-

- {{ voting_domain_warning }} -

-
-
- - {% endif %}
{% if messages %} @@ -82,36 +65,56 @@

Profilul organizației

{% endif %} - {% if not organization.is_fully_editable %} -
-
-
- {% csrf_token %} - -
- - {% if organization.status == "pending" %} -

- {% trans "Some data wasn't found on NGO Hub." %} -

- {% endif %} -

+ {% if voting_domain_warning and ORG_EDITING_ENABLED %} +

+
+

- {{ update_button_message }} + + {% trans "Warning!" %} - ({{ update_button_description }}) +

+

+ {{ voting_domain_warning }}

+ {% endif %} + + {% if not organization.is_fully_editable %} + + {% if ORG_EDITING_ENABLED %} +
+
+
+ {% csrf_token %} + +
+ + {% if organization.status == "pending" %} +

+ {% trans "Some data wasn't found on NGO Hub." %} +

+ {% endif %} + +

+ + {{ update_button_message }} + + ({{ update_button_description }}) +

+
+
+ {% endif %}
{% csrf_token %} @@ -137,7 +140,11 @@

{{ form|crispy }}
- + {% if CANDIDATE_EDITING_ENABLED or ORG_EDITING_ENABLED %} + + {% else %} + + {% endif %}
diff --git a/backend/hub/views.py b/backend/hub/views.py index 2b037d82..52b45593 100644 --- a/backend/hub/views.py +++ b/backend/hub/views.py @@ -43,6 +43,7 @@ OrganizationUpdateForm, ) from hub.models import ( + FLAG_CHOICES, PHASE_CHOICES, SETTINGS_CHOICES, BlogPost, @@ -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")