From 1a4461cfb054628f6c305d0c8a502a846f56b484 Mon Sep 17 00:00:00 2001 From: Matthias Hartmann Date: Fri, 17 Jun 2022 20:10:09 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20Issue=20364=20:=20v=C3=A9rif=20group?= =?UTF-8?q?=5Fname=20d=C3=A9j=C3=A0=20existant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_groups.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 79ed91cad..6df63bef3 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -599,6 +599,11 @@ def XMLgetGroupsInPartition(partition_id): # was XMLgetGroupesTD response.headers["Content-Type"] = scu.XML_MIMETYPE return response +def check_group_name(group_name, partition): + """Raise ScoValueError if group_name exists in partition""" + exists = group_name in [g["group_name"] for g in get_partition_groups(partition)] + if exists: + raise ScoValueError("Le nom de groupe existe déjà dans la partition") def comp_origin(etud, cur_sem): """breve description de l'origine de l'étudiant (sem. precedent) @@ -1244,6 +1249,7 @@ def group_set_name(group_id, group_name, redirect=True): if not sco_permissions_check.can_change_groups(formsemestre_id): raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !") redirect = int(redirect) + check_group_name(group_name, get_partition(group['partition_id'])) cnx = ndb.GetDBConnexion() groupEditor.edit(cnx, {"group_id": group_id, "group_name": group_name}) @@ -1372,13 +1378,13 @@ def groups_auto_repartition(partition_id=None): # Crée les nouveaux groupes group_ids = [] for group_name in group_names: - # try: - # checkGroupName(group_name) - # except: - # H.append('

Nom de groupe invalide: %s

'%group_name) - # return '\n'.join(H) + tf[1] + html_sco_header.sco_footer() + try: + check_group_name(group_name, partition) + except: + H.append('

Nom de groupe invalide: %s

'%group_name) + return '\n'.join(H) + tf[1] + html_sco_header.sco_footer() group_ids.append(create_group(partition_id, group_name)) - # + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) identdict = nt.identdict # build: { civilite : liste etudids trie par niveau croissant } From d3226a32f4f3e27b82ed808ec9204869872cea03 Mon Sep 17 00:00:00 2001 From: Matthias Hartmann Date: Fri, 17 Jun 2022 20:36:02 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"Fix=20Issue=20364=20:=20v=C3=A9ri?= =?UTF-8?q?f=20group=5Fname=20d=C3=A9j=C3=A0=20existant"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1a4461cfb054628f6c305d0c8a502a846f56b484. --- app/scodoc/sco_groups.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 6df63bef3..79ed91cad 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -599,11 +599,6 @@ def XMLgetGroupsInPartition(partition_id): # was XMLgetGroupesTD response.headers["Content-Type"] = scu.XML_MIMETYPE return response -def check_group_name(group_name, partition): - """Raise ScoValueError if group_name exists in partition""" - exists = group_name in [g["group_name"] for g in get_partition_groups(partition)] - if exists: - raise ScoValueError("Le nom de groupe existe déjà dans la partition") def comp_origin(etud, cur_sem): """breve description de l'origine de l'étudiant (sem. precedent) @@ -1249,7 +1244,6 @@ def group_set_name(group_id, group_name, redirect=True): if not sco_permissions_check.can_change_groups(formsemestre_id): raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !") redirect = int(redirect) - check_group_name(group_name, get_partition(group['partition_id'])) cnx = ndb.GetDBConnexion() groupEditor.edit(cnx, {"group_id": group_id, "group_name": group_name}) @@ -1378,13 +1372,13 @@ def groups_auto_repartition(partition_id=None): # Crée les nouveaux groupes group_ids = [] for group_name in group_names: - try: - check_group_name(group_name, partition) - except: - H.append('

Nom de groupe invalide: %s

'%group_name) - return '\n'.join(H) + tf[1] + html_sco_header.sco_footer() + # try: + # checkGroupName(group_name) + # except: + # H.append('

Nom de groupe invalide: %s

'%group_name) + # return '\n'.join(H) + tf[1] + html_sco_header.sco_footer() group_ids.append(create_group(partition_id, group_name)) - + # nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) identdict = nt.identdict # build: { civilite : liste etudids trie par niveau croissant } From cf99d3c618036e4f54b801d8254f9307be3882ec Mon Sep 17 00:00:00 2001 From: Matthias Hartmann Date: Fri, 17 Jun 2022 20:42:45 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Fix=20Issue=20364=20:=20v=C3=A9rif=20group?= =?UTF-8?q?=5Fname=20d=C3=A9j=C3=A0=20existant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_groups.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 79ed91cad..4f984d0b1 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -263,6 +263,15 @@ def get_group_members(group_id, etat=None): return r +def check_group_name(group_name, partition, raiser=False): + """If groupe name exists in partition : if raiser -> Raise ScoValueError else-> return true""" + exists = group_name in [g["group_name"] for g in get_partition_groups(partition)] + if exists: + if raiser: + raise ScoValueError("Le nom de groupe existe déjà dans la partition") + else : + return True + return False; # obsolete: sco_groups_view.DisplayedGroupsInfos # def get_groups_members(group_ids, etat=None): @@ -798,7 +807,7 @@ def create_group(partition_id, group_name="", default=False) -> int: if not group_name and not default: raise ValueError("invalid group name: ()") # checkGroupName(group_name) - if group_name in [g["group_name"] for g in get_partition_groups(partition)]: + if check_group_name(group_name, partition): raise ValueError( "group_name %s already exists in partition" % group_name ) # XXX FIX: incorrect error handling (in AJAX) @@ -1246,7 +1255,7 @@ def group_set_name(group_id, group_name, redirect=True): redirect = int(redirect) cnx = ndb.GetDBConnexion() groupEditor.edit(cnx, {"group_id": group_id, "group_name": group_name}) - + check_group_name(group_name, get_partition(group["partition_id"]), True) # redirect to partition edit page: if redirect: return flask.redirect(