diff --git a/app/api/partitions.py b/app/api/partitions.py index f46598b2..9af1fb30 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -359,6 +359,8 @@ def partition_create(formsemestre_id: int): partition_name = data.get("partition_name") if partition_name is None: return error_response(404, "missing partition_name or invalid data format") + if partition_name == scu.PARTITION_PARCOURS: + return error_response(404, f"invalid partition_name {scu.PARTITION_PARCOURS}") if not Partition.check_name(formsemestre, partition_name): return error_response(404, "invalid partition_name") numero = data.get("numero", 0) @@ -482,7 +484,10 @@ def partition_edit(partition_id: int): data = request.get_json(force=True) # may raise 400 Bad Request modified = False partition_name = data.get("partition_name") + # if partition_name is not None and partition_name != partition.partition_name: + if partition.is_parcours(): + return error_response(404, f"can't rename {scu.PARTITION_PARCOURS}") if not Partition.check_name( partition.formsemestre, partition_name, existing=True ): @@ -502,6 +507,8 @@ def partition_edit(partition_id: int): if value is not None and value != getattr(partition, boolean_field): if not isinstance(value, bool): return error_response(404, f"invalid type for {boolean_field}") + if boolean_field == "groups_editable" and partition.is_parcours(): + return error_response(404, f"can't change {scu.PARTITION_PARCOURS}") setattr(partition, boolean_field, value) modified = True diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index a5514200..316811c4 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -576,6 +576,7 @@ class FormSemestre(db.Model): formsemestre_id=self.id, partition_name=scu.PARTITION_PARCOURS, numero=-1, + groups_editable=False, ) db.session.add(partition) db.session.flush() # pour avoir un id diff --git a/app/models/groups.py b/app/models/groups.py index 8b890a6a..1a5dc257 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -38,7 +38,7 @@ class Partition(db.Model): show_in_lists = db.Column( db.Boolean(), nullable=False, default=True, server_default="true" ) - # Editable ? (faux pour les groupes de parcours) + # Editable (créer/renommer groupes) ? (faux pour les groupes de parcours) groups_editable = db.Column( db.Boolean(), nullable=False, default=True, server_default="true" ) @@ -80,7 +80,7 @@ class Partition(db.Model): return True def is_parcours(self) -> bool: - "Vrai s'il s'agit de la partitoon de parcours" + "Vrai s'il s'agit de la partition de parcours" return self.partition_name == scu.PARTITION_PARCOURS def to_dict(self, with_groups=False) -> dict: diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 2a9b4dac..1f759e2a 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -760,7 +760,7 @@ def setGroups( return response partition = get_partition(partition_id) - if not partition["groups_editable"]: + if not partition["groups_editable"] and (groupsToCreate or groupsToDelete): msg = "setGroups: partition non editable" log(msg) return xml_error(msg, code=403) @@ -998,51 +998,54 @@ def edit_partition_form(formsemestre_id=None): for p in partitions: if p["partition_name"] is not None: H.append( - '