This commit is contained in:
Emmanuel Viennet 2021-04-23 10:24:45 +02:00
parent 4a5d4adee1
commit 9e65fa7654
8 changed files with 133 additions and 30 deletions

View File

@ -251,8 +251,8 @@ class exUserFolder(Folder,BasicUserFolder,BasicGroupFolderMixin,
('Manager',)),
('View', ('manage_changePassword',
'manage_forgotPassword', 'docLogin','docLoginRedirect',
'docLogout', 'logout', 'DialogHeader',
'manage_forgotPassword','docLoginRedirect',
'logout', 'DialogHeader',
'DialogFooter', 'manage_signupUser',
'MessageDialog', 'redirectToLogin','manage_changeProps'),
('Anonymous', 'Authenticated', 'Manager')),
@ -269,7 +269,7 @@ class exUserFolder(Folder,BasicUserFolder,BasicGroupFolderMixin,
('Access contents information', ('hasProperty', 'propertyIds',
'propertyValues','propertyItems',
'getProperty', 'getPropertyType',
'propertyMap', 'docLogin','docLoginRedirect',
'propertyMap', 'docLoginRedirect',
'DialogHeader', 'DialogFooter',
'MessageDialog', 'redirectToLogin',),
('Anonymous', 'Authenticated', 'Manager')),

64
config/fix_bug70_db.py Normal file
View File

@ -0,0 +1,64 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""Fix bug #70
Utiliser comme:
scotests/scointeractive.sh DEPT config/fix_bug70_db.py
"""
context = context.Notes # pylint: disable=undefined-variable
REQUEST = REQUEST # pylint: disable=undefined-variable
import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error
import os
import sys
import sco_utils
import notesdb
import sco_formsemestre
import sco_formsemestre_edit
import sco_moduleimpl
G = sco_fake_gen.ScoFake(context.Notes)
def fix_formsemestre_formation_bug70(formsemestre_id):
"""Le bug #70 a pu entrainer des incohérences
lors du clonage avorté de semestres.
Cette fonction réassocie le semestre à la formation
à laquelle appartiennent ses modulesimpls.
2021-04-23
"""
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
cursor = notesdb.SimpleQuery(
context,
"""SELECT m.formation_id
FROM notes_modules m, notes_moduleimpl mi
WHERE mi.module_id = m.module_id
AND mi.formsemestre_id = %(formsemestre_id)s
""",
{"formsemestre_id": formsemestre_id},
)
modimpls_formations = set([x[0] for x in cursor])
if len(modimpls_formations) > 1:
# this is should not occur
G.log(
"Warning: fix_formsemestre_formation_bug70: modules from several formations in sem %s"
% formsemestre_id
)
elif len(modimpls_formations) == 1:
modimpls_formation_id = modimpls_formations.pop()
if modimpls_formation_id != sem["formation_id"]:
# Bug #70: fix
G.log("fix_formsemestre_formation_bug70: fixing %s" % formsemestre_id)
sem["formation_id"] = modimpls_formation_id
context.do_formsemestre_edit(sem, html_quote=False)
formsemestre_ids = [
x[0]
for x in notesdb.SimpleQuery(
context, "SELECT formsemestre_id FROM notes_formsemestre", {}
)
]
for formsemestre_id in formsemestre_ids:
fix_formsemestre_formation_bug70(formsemestre_id)

18
config/postupgrade.py Executable file → Normal file
View File

@ -11,15 +11,16 @@ _before_ upgrading the database.
E. Viennet, June 2008
Mar 2017: suppress upgrade of very old Apache configs
Aug 2020: move photos to .../var/scodoc/
Apr 2021: bug #70
"""
import os
import sys
import glob
import shutil
from scodocutils import log, SCODOC_DIR, SCODOC_VAR_DIR, SCODOC_LOGOS_DIR
from scodocutils import log, SCODOC_DIR, SCODOC_VAR_DIR, SCODOC_LOGOS_DIR, SCO_TMPDIR
if os.getuid() != 0:
log('postupgrade.py: must be run as root')
log("postupgrade.py: must be run as root")
sys.exit(1)
# ---
@ -54,6 +55,19 @@ for d in glob.glob( SCODOC_DIR + "/logos_*" ):
log("Moving %s to %s" % (d, SCODOC_LOGOS_DIR))
shutil.move(d, SCODOC_LOGOS_DIR)
# Fix bug #70
depts = [
os.path.splitext(os.path.basename(f))[0] for f in glob.glob(depts_dir + "/*.cfg")
]
for dept in depts:
fixed_filename = SCO_TMPDIR + "/.%s_bug70_fixed" % dept
if not os.path.exists(fixed_filename):
log("fixing #70 on %s" % dept)
os.system("../scotests/scointeractive.sh -x %s config/fix_bug70_db.py" % dept)
# n'essaie qu'une foixs, même en cas d'échec
f = open(fixed_filename, "a")
f.close()
# Continue here...
# ---

1
config/scodocutils.py Normal file → Executable file
View File

@ -30,6 +30,7 @@ SCODOC_VAR_DIR = os.environ.get("SCODOC_VAR_DIR", "")
if not SCODOC_VAR_DIR:
log("Error: environment variable SCODOC_VAR_DIR is not defined")
sys.exit(1)
SCO_TMPDIR = os.path.join(SCODOC_VAR_DIR, "tmp")
SCODOC_LOGOS_DIR = os.environ.get("SCODOC_LOGOS_DIR", "")

View File

@ -57,17 +57,19 @@ import sco_bulletins_xml
# Prend le premier departement comme context
def go(app, n=0):
def go(app, n=0, verbose=True):
context = app.ScoDoc.objectValues("Folder")[n].Scolarite
if verbose:
print("context in dept ", context.DeptId())
return context
def go_dept(app, dept):
def go_dept(app, dept, verbose=True):
objs = app.ScoDoc.objectValues("Folder")
for o in objs:
context = o.Scolarite
if context.DeptId() == dept:
if verbose:
print("context in dept ", context.DeptId())
return context
raise ValueError("dep %s not found" % dept)

View File

@ -1132,6 +1132,9 @@ class NotesTable:
def sem_has_decisions(self):
"""True si au moins une decision de jury dans ce semestre"""
if [x for x in self.decisions_jury_ues.values() if x]:
return True
return len([x for x in self.decisions_jury_ues.values() if x]) > 0
def etud_has_decision(self, etudid):

View File

@ -9,9 +9,10 @@
# le département via l'interface web (Zope)
usage() {
echo "Usage: $0 [-r] dept [script...]"
echo "Usage: $0 [-h] [-r] [-x] dept [script...]"
echo "Lance un environnement interactif python/ScoDoc"
echo " -r: supprime et recrée le département (attention: efface la base !)"
echo " -x: exit après exécution des scripts, donc mode non interactif"
exit 1
}
@ -20,24 +21,38 @@ cd /opt/scodoc/Products/ScoDoc || exit 2
source config/config.sh
source config/utils.sh
if [ $# -lt 1 ]
then
usage
fi
RECREATE_DEPT=0
PYTHON_INTERACTIVE="-i"
if [ "$1" = "-r" ]
then
while [ -n "$1" ]; do
PARAM="$1"
[ "${PARAM::1}" != "-" ] && break
case $PARAM in
-h | --help)
usage
exit 0
;;
-r)
RECREATE_DEPT=1
;;
-x)
PYTHON_INTERACTIVE=""
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
recreate_dept=1
else
recreate_dept=0
fi
done
DEPT="$1"
shift
if [ "$recreate_dept" = 1 ]
if [ "$RECREATE_DEPT" = 1 ]
then
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
if [ -e "$cfg_pathname" ]
@ -48,13 +63,17 @@ then
# systemctl start scodoc
fi
cmd="from __future__ import print_function;from Zope2 import configure;configure('/opt/scodoc/etc/zope.conf');import Zope2; app=Zope2.app();from debug import *;context = go_dept(app, '""$DEPT""');"
cmd="from __future__ import print_function;from Zope2 import configure;configure('/opt/scodoc/etc/zope.conf');import Zope2; app=Zope2.app();from debug import *;context = go_dept(app, '""$DEPT""', verbose=False);"
for f in "$@"
do
cmd="${cmd}exec(open(\"${f}\").read());"
done
/opt/zope213/bin/python -i -c "$cmd"
if [ -z "$PYTHON_INTERACTIVE" ]
then
/opt/zope213/bin/python -c "$cmd"
else
/opt/zope213/bin/python "$PYTHON_INTERACTIVE" -c "$cmd"
fi

View File

@ -11,7 +11,7 @@ Utiliser comme:
"""
# La variable context est définie par le script de lancement
# l'affecte ainsi pour évietr les warnins pylint:
# l'affecte ainsi pour éviter les warnings pylint:
context = context # pylint: disable=undefined-variable
import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error
import sco_utils