08/06/2025 - 16h30

Signed-off-by: Cherif <cbalde@mysy-training.com>
master_Elyos_FI
Cherif 2025-06-08 16:33:59 +02:00
parent e1c69a53d4
commit 31e23691f3
12 changed files with 6793 additions and 275 deletions

View File

@ -4,16 +4,19 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="qsd">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="07/06/2025 - 21h30">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/attached_file_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/attached_file_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Session_Formation_Sequence.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation_Sequence.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apprenant_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/base_class_calcul_note.py" beforeDir="false" afterPath="$PROJECT_DIR$/base_class_calcul_note.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/base_partner_catalog_config.py" beforeDir="false" afterPath="$PROJECT_DIR$/base_partner_catalog_config.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ent_student_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/ent_student_common.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/partner_order.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_order.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/user_session.py" beforeDir="false" afterPath="$PROJECT_DIR$/user_session.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -52,17 +55,17 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Python.main.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master__Elyos__FI",
"ignore.virus.scanning.warn.message": "true",
"last_opened_file_path": "C:/Users/Cherif/Documents/myclass.com/Siteweb/Elyos_Ftion_Initiale/Ela_back/Back_Office_FI",
"settings.editor.selected.configurable": "project.propVCSSupport.CommitDialog"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master__Elyos__FI&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Cherif/Documents/myclass.com/Siteweb/Elyos_Ftion_Initiale/Ela_back/Back_Office_FI&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;project.propVCSSupport.CommitDialog&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\billa\Documents\myclass.com\Siteweb\Production\Ela_back\Back_Office\tools_cherif" />
@ -455,7 +458,7 @@
<option name="project" value="LOCAL" />
<updated>1747251650255</updated>
</task>
<option name="localTasksCounter" value="471" />
<option name="localTasksCounter" value="472" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -497,7 +500,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="05/03/2025 - 18h" />
<MESSAGE value="10/03/2025 - 13h" />
<MESSAGE value="29/03/2025 - 9h" />
<MESSAGE value="29/03/2025 - 21h" />
@ -522,6 +524,7 @@
<MESSAGE value="05/06/2025 - 22h" />
<MESSAGE value="06/06/2025 - 20h" />
<MESSAGE value="qsd" />
<option name="LAST_COMMIT_MESSAGE" value="qsd" />
<MESSAGE value="07/06/2025 - 21h30" />
<option name="LAST_COMMIT_MESSAGE" value="07/06/2025 - 21h30" />
</component>
</project>

View File

@ -929,4 +929,11 @@ PARTNER_ACCOUNT_CONNEXION_CONTEXT_VALUES = ['mysy_session_display_view',
"""
Longueur maximale d'un commentaire dans l'historique
"""
HISTORIQUE_DESCRIPTION_LEN = 500
HISTORIQUE_DESCRIPTION_LEN = 500
"""
les modes d'animation des formations
0 = > Présentiel
1 = > Distanciel
2 = > Hybride
"""

File diff suppressed because it is too large Load Diff

View File

@ -63,7 +63,8 @@ def Add_Update_SessionFormation(diction):
'class_internal_url', 'session_status', 'date_debut_inscription', 'date_fin_inscription',
'attestation_certif', "distantiel", "presentiel", "prix_session", 'contenu_ftion', 'lms_class_code',
'session_ondemande', 'source', 'session_id', 'session_etape', 'pays', 'formateur_id',
'titre', 'location_type', 'is_bpf', 'site_formation_id', 'price_by', 'mode_animation', 'archive']
'titre', 'location_type', 'is_bpf', 'site_formation_id', 'price_by', 'mode_animation', 'archive',
'ent_account_automatic', 'lms_account_automatic']
incom_keys = diction.keys()
for val in incom_keys:
@ -205,6 +206,18 @@ def Add_Update_SessionFormation(diction):
else:
mydata['presentiel'] = "0"
if ("ent_account_automatic" in diction.keys()):
mydata['ent_account_automatic'] = str(mycommon.tryInt(str(diction['ent_account_automatic'])))
else:
mydata['presentiel'] = "0"
if ("lms_account_automatic" in diction.keys()):
mydata['lms_account_automatic'] = str(mycommon.tryInt(str(diction['lms_account_automatic'])))
else:
mydata['lms_account_automatic'] = "0"
"""
Pour le mode d'animation d'une session de formation, on a :
0 => Présentiel

View File

@ -56,7 +56,8 @@ def Add_Session_Sequence(diction):
Verification des input acceptés
"""
field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id' ]
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id',
'mode_animation']
incom_keys = diction.keys()
for val in incom_keys:
@ -220,6 +221,10 @@ def Add_Session_Sequence(diction):
if ("objectif" in diction.keys()):
objectif = str(diction['objectif'])
mode_animation = ""
if ("mode_animation" in diction.keys()):
mode_animation = str(diction['mode_animation'])
commentaire = ""
if ("commentaire" in diction.keys()):
commentaire = str(diction['commentaire'])
@ -294,6 +299,8 @@ def Add_Session_Sequence(diction):
my_data['objectif'] = objectif
my_data['commentaire'] = commentaire
my_data['mode_animation'] = mode_animation
my_data['grp_apprenant_id'] = grp_apprenant_id
my_data['ue_id'] = ue_id
my_data['unite_enseignement_planif_id'] = ue_planif_line_id
@ -301,8 +308,9 @@ def Add_Session_Sequence(diction):
my_data['valide'] = "1"
my_data['locked'] = "0"
my_data['partner_owner_recid'] = str(my_partner['recid'])
my_data['update_by'] = str(my_partner['_id'])
my_data['creation_date'] = str(datetime.now())
my_data['creation_by'] = str(my_partner['_id'])
local_retval = MYSY_GV.dbname['session_formation_sequence'].insert_one(my_data)
@ -354,7 +362,8 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction):
Verification des input acceptés
"""
field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id']
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id',
'mode_animation']
incom_keys = diction.keys()
for val in incom_keys:
@ -517,6 +526,10 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction):
if ("objectif" in diction.keys()):
objectif = str(diction['objectif'])
mode_animation = ""
if ("mode_animation" in diction.keys()):
mode_animation = str(diction['mode_animation'])
commentaire = ""
if ("commentaire" in diction.keys()):
commentaire = str(diction['commentaire'])
@ -590,6 +603,8 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction):
my_data['objectif'] = objectif
my_data['commentaire'] = commentaire
my_data['mode_animation'] = mode_animation
my_data['grp_apprenant_id'] = grp_apprenant_id
my_data['ue_id'] = ue_id
my_data['unite_enseignement_planif_id'] = ue_planif_line_id
@ -597,7 +612,9 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction):
my_data['valide'] = "1"
my_data['locked'] = "0"
my_data['partner_owner_recid'] = str(my_partner['recid'])
my_data['update_by'] = str(my_partner['_id'])
my_data['creation_date'] = str(datetime.now())
my_data['creation_by'] = str(my_partner['_id'])
local_retval = MYSY_GV.dbname['session_formation_sequence'].insert_one(my_data)
@ -1300,7 +1317,8 @@ def Update_Session_Sequence(diction):
Verification des input acceptés
"""
field_list = ['token', '_id', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id']
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id',
'mode_animation']
incom_keys = diction.keys()
for val in incom_keys:
@ -1357,8 +1375,6 @@ def Update_Session_Sequence(diction):
old_unite_enseignement_planif_id = is_existe_valide_session_sequence_id_data['unite_enseignement_planif_id']
# Verification de l'existence et de la session
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents({'_id':ObjectId(str(diction['session_id'])),
'partner_owner_recid':str(my_partner['recid']),
@ -1475,6 +1491,9 @@ def Update_Session_Sequence(diction):
update_data['objectif'] = str(diction['objectif'])
if ("mode_animation" in diction.keys()):
update_data['mode_animation'] = str(diction['mode_animation'])
if ("commentaire" in diction.keys()):
update_data['commentaire'] = str(diction['commentaire'])
@ -1525,14 +1544,11 @@ def Update_Session_Sequence(diction):
update_data['sequence_end'] = date_fin_seq
update_data['valide'] = "1"
update_data['locked'] = "0"
update_data['date_update'] = str(datetime.now())
update_data['update_by'] = str(my_partner['_id'])
print({'_id': ObjectId(str(diction['_id'])),
'valide': '1', 'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
@ -1679,7 +1695,8 @@ def Get_Session_Sequence_List(diction):
user['grp_apprenant_color'] = grp_apprenant_color
user['grp_apprenant_code'] = grp_apprenant_code
if ("mode_animation" not in user.keys()):
user['mode_animation'] = "0"
if ("ue_id" not in user.keys()):
user['ue_id'] = ""
@ -1747,6 +1764,17 @@ def Get_Given_Session_Sequence(diction):
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
if ("mode_animation" not in user.keys()):
user['mode_animation'] = "0"
if ("ue_id" not in user.keys()):
user['ue_id'] = ""
if ("unite_enseignement_planif_id" not in user.keys()):
user['unite_enseignement_planif_id'] = ""
RetObject.append(mycommon.JSONEncoder().encode(user))
return True, RetObject

View File

@ -889,7 +889,7 @@ def Get_Apprenant_List_Partner_with_filter(diction):
val['id'] = str(cpt)
cpt = cpt + 1
if ("date_naissance" not in val.keys() or str(val['user']) == ""):
if ("date_naissance" not in val.keys() or str(val['date_naissance']) == ""):
val['date_naissance'] = "01/01/1900"
RetObject.append(mycommon.JSONEncoder().encode(val))
@ -1008,14 +1008,27 @@ def Apprenant_Inscrire_Session(diction):
})
local_class_id = ""
if( "class_id" not in session_data.keys() ):
class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(session_data['class_internal_url']),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
tab_local_class_eu = []
list_local_class_eu = ""
if(class_data and '_id' in class_data.keys() ):
local_class_id = str(class_data['_id'])
class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(session_data['class_internal_url']),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if(class_data and '_id' in class_data.keys() ):
local_class_id = str(class_data['_id'])
if( "list_unite_enseignement" in class_data.keys()):
for class_ue in class_data['list_unite_enseignement']:
if('_id' in class_ue.keys()):
tab_local_class_eu.append(str(class_ue['_id']))
print(" ### tab_local_class_eu == ", tab_local_class_eu)
list_local_class_eu = ",".join(tab_local_class_eu)
print(" ### list_local_class_eu == ", list_local_class_eu)
new_data = {}
@ -1033,7 +1046,17 @@ def Apprenant_Inscrire_Session(diction):
new_data['class_internal_url'] = session_data['class_internal_url']
new_data['status'] = "1"
new_data['type_apprenant'] = str(type_apprenant)
new_data['tab_ue_ids'] = str(diction['tab_ue_ids'])
"""
Important : 08/06/2025
Si on ne fourni pas diction['tab_ue_ids'], on va aller regarder si la formation concernée
a des eu, auquel cas on les prends tous
"""
if( "tab_ue_ids" in diction.keys()):
new_data['tab_ue_ids'] = str(diction['tab_ue_ids'])
else:
new_data['tab_ue_ids'] = str(list_local_class_eu)
@ -1045,59 +1068,6 @@ def Apprenant_Inscrire_Session(diction):
if( local_status is False ):
return local_status, local_retval
"""
Vu que la fonction "AddStagiairetoClass" ne retroune pas l'_id, on va aller le recherche
"" "
qry = {'apprenant_id':str(str(apprenant_data['_id'])),
'session_id':str(session_data['_id']),
'class_id':str(local_class_id),
'email':apprenant_data['email']
}
new_inscrit_data = MYSY_GV.dbname['inscription'].find_one(qry)
"" "
Verfier si 'tab_ue_ids' contient des valeurs, si oui alors il faut inscrire les ue dans la collection inscription_liste_ue
"" "
my_ue_ids = ""
tab_ue_ids = []
if ("tab_ue_ids" in diction.keys()):
if diction['tab_ue_ids']:
my_ue_ids = diction['tab_ue_ids']
tab_ue_ids_work = str(my_ue_ids).split(",")
for tmp in tab_ue_ids_work:
if (tmp):
tab_ue_ids.append(tmp)
for ue in tab_ue_ids:
new_data = {}
new_data['inscription_id'] = str(new_inscrit_data['_id'])
new_data['class_id'] = str(local_class_id)
new_data['class_eu_id'] = str(ue)
new_data['date_update'] = str(datetime.now())
new_data['update_by'] = str(my_partner['_id'])
new_data['partner_owner_recid'] = str(my_partner['recid'])
new_data['valide'] = "1"
new_data['locked'] = "0"
key_data = {}
key_data['inscription_id'] = str(new_inscrit_data['_id'])
key_data['class_id'] = str(local_class_id)
key_data['class_eu_id'] = str(ue)
key_data['valide'] = "1"
key_data['partner_owner_recid'] = str(my_partner['recid'])
result = MYSY_GV.dbname['inscription_liste_ue'].find_one_and_update(
key_data,
{"$set": new_data},
upsert=True,
return_document=ReturnDocument.AFTER
)
if ("_id" not in result.keys()):
mycommon.myprint(
" Impossible de valider l'inscription pour la formation initiale (2) ")
return False, "Impossible de valider l'inscription pour la formation initiale (2) "
"""
## Add to log history
@ -1304,9 +1274,10 @@ def Apprenant_Inscrire_Session_List(diction):
local_diction['type_apprenant'] = diction['type_apprenant']
local_diction['modefinancement'] = diction['modefinancement']
local_diction['client_rattachement_id'] = client_rattachement_id
local_diction['tab_ue_ids'] = str(diction['tab_ue_ids'])
if( "tab_ue_ids" in diction.keys() ):
local_diction['tab_ue_ids'] = str(diction['tab_ue_ids'])
print(" ### local_diction = ", local_diction)
print(" ### local_diction inscription apprenant = ", local_diction)
local_status, local_retval = Apprenant_Inscrire_Session(local_diction)
if( local_status is False ):
@ -2717,5 +2688,352 @@ def Export_Apprenant_To_Excel_From_from_List_Id(diction):
return False, " Impossible d'exporter les apprenants "
"""
Cette fonction permet de créer un compte ENT pour un apprenant
"""
def ENT_Create_Apprenant_Account(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'tab_apprenant_ids']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'tab_apprenant_ids']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
return False, " Les informations fournies sont incorrectes",
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
tab_apprenant_ids_work = str(diction['tab_apprenant_ids']).split(",")
tab_apprenant_ids = []
for tmp in tab_apprenant_ids_work:
if( tmp ):
tab_apprenant_ids.append(tmp)
for val in tab_apprenant_ids :
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(val)),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( is_valide_apprenant != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " L'identifiant de l'apprenant "+str(val)+" est invalide ")
return False, " L'identifiant de l'apprenant "+str(val)+" est invalide "
"""
A présent tous les apprenants sont valides,
les comptes vont etre créer pour l'ENT
"""
nb_compte = 0
for val in tab_apprenant_ids:
local_apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id': ObjectId(str(val)),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(
my_partner['recid'])})
new_account = {}
new_account['nom'] = local_apprenant_data['nom']
new_account['prenom'] = local_apprenant_data['prenom']
new_account['civilite'] = local_apprenant_data['civilite']
new_account['email'] = local_apprenant_data['email']
new_account['mob_phone'] = local_apprenant_data['telephone']
new_account['adr_street'] = local_apprenant_data['adresse']
new_account['code_postal'] = local_apprenant_data['code_postal']
new_account['adr_city'] = local_apprenant_data['ville']
new_account['adr_country'] = local_apprenant_data['pays']
new_account['adr_country'] = local_apprenant_data['pays']
new_account['partner_owner_recid'] = local_apprenant_data['partner_owner_recid']
new_account['type'] = 'student'
new_account['apprenant_id'] = str(val)
new_account['active'] = '1'
new_account['locked'] = '0'
new_account['firstconnexion'] = '1'
new_account['creation_date'] = str(datetime.now())
new_account['creation_by'] = str(my_partner['_id'])
new_account['notification_send'] = "0"
new_account['pwd'] = str(secrets.token_urlsafe(8))
data_key = {}
data_key['type'] = 'student'
data_key['email'] = str(local_apprenant_data['email'])
data_key['apprenant_id'] = str(val)
data_key['partner_owner_recid'] = str( local_apprenant_data['partner_owner_recid'])
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
data_key,
{"$set": new_account},
upsert=True,
return_document=ReturnDocument.AFTER
)
nb_compte = nb_compte + 1
return True, str(nb_compte)+" compte(s) ENT créé(s) "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de créer les accès ENT "
"""
Cette fonction permet de desactiver un compte ENT d'une liste d'apprenant
"""
def ENT_Disable_Apprenant_Account(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'tab_apprenant_ids']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'tab_apprenant_ids']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
return False, " Les informations fournies sont incorrectes",
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
tab_apprenant_ids_work = str(diction['tab_apprenant_ids']).split(",")
tab_apprenant_ids = []
for tmp in tab_apprenant_ids_work:
if( tmp ):
tab_apprenant_ids.append(tmp)
for val in tab_apprenant_ids :
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(val)),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( is_valide_apprenant != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " L'identifiant de l'apprenant "+str(val)+" est invalide ")
return False, " L'identifiant de l'apprenant "+str(val)+" est invalide "
"""
A présent tous les apprenants sont valides,
les comptes vont etre créer pour l'ENT
"""
nb_compte = 0
for val in tab_apprenant_ids:
local_apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id': ObjectId(str(val)),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(
my_partner['recid'])})
new_account = {}
new_account['active'] = '0'
new_account['locked'] = '1'
new_account['date_update'] = str(datetime.now())
new_account['update_by'] = str(my_partner['_id'])
data_key = {}
data_key['type'] = 'student'
data_key['email'] = str(local_apprenant_data['email'])
data_key['apprenant_id'] = str(val)
data_key['partner_owner_recid'] = str( local_apprenant_data['partner_owner_recid'])
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
data_key,
{"$set": new_account},
upsert=False,
return_document=ReturnDocument.AFTER
)
nb_compte = nb_compte + 1
return True, str(nb_compte)+" compte(s) ENT désactivé(s) "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible désactiver les accès ENT "
"""
Cette fonction permet de Reativer un compte ENT d'une liste d'apprenant
# Dans le cadre d'une reactivation, on modifie le mot de passe.
"""
def ENT_Enable_Apprenant_Account(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'tab_apprenant_ids']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'tab_apprenant_ids']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
return False, " Les informations fournies sont incorrectes",
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
tab_apprenant_ids_work = str(diction['tab_apprenant_ids']).split(",")
tab_apprenant_ids = []
for tmp in tab_apprenant_ids_work:
if( tmp ):
tab_apprenant_ids.append(tmp)
for val in tab_apprenant_ids :
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(val)),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( is_valide_apprenant != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " L'identifiant de l'apprenant "+str(val)+" est invalide ")
return False, " L'identifiant de l'apprenant "+str(val)+" est invalide "
"""
A présent tous les apprenants sont valides,
les comptes vont etre créer pour l'ENT
"""
nb_compte = 0
for val in tab_apprenant_ids:
local_apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id': ObjectId(str(val)),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(
my_partner['recid'])})
new_account = {}
# Dans le cadre d'une reactivation, on modifie le mot de passe.
new_account['pwd'] = str(secrets.token_urlsafe(8))
new_account['active'] = '1'
new_account['locked'] = '0'
new_account['date_update'] = str(datetime.now())
new_account['update_by'] = str(my_partner['_id'])
data_key = {}
data_key['type'] = 'student'
data_key['email'] = str(local_apprenant_data['email'])
data_key['apprenant_id'] = str(val)
data_key['partner_owner_recid'] = str( local_apprenant_data['partner_owner_recid'])
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
data_key,
{"$set": new_account},
upsert=False,
return_document=ReturnDocument.AFTER
)
nb_compte = nb_compte + 1
return True, str(nb_compte)+" compte(s) ENT désactivé(s) "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible désactiver les accès ENT "

View File

@ -1525,7 +1525,6 @@ def Get_List_base_calcul_note_class_and_ue_With_Filter(diction):
data_cle['locked'] = "0"
data_cle['related_collection'] = {'$in':tab_related_collection_name_splited}
query = data_cle
RetObject = []

View File

@ -113,7 +113,8 @@ def Add_Update_Partner_Catalog_Pub_Config(diction):
'indicateur_2_txt', 'indicateur_2_taille', 'indicateur_2_color', 'indicateur_2_gras',
'indicateur_3_txt', 'indicateur_3_taille', 'indicateur_3_color', 'indicateur_3_gras',
'indicateur_4_txt', 'indicateur_4_taille', 'indicateur_4_color', 'indicateur_4_gras',
'cgv_pdf', 'cgu_pdf', 'mention_legale_pdf', 'contact_public_email', 'contact_public_telephone'
'cgv_pdf', 'cgu_pdf', 'mention_legale_pdf', 'contact_public_email', 'contact_public_telephone',
'partner_catalog_pub_url', 'partner_intranet_pub_url', 'partner_ent_student_url'
]
incom_keys = diction.keys()

View File

@ -511,7 +511,8 @@ def Get_Ent_Student_Session_Sequence_List(diction):
user['grp_apprenant_color'] = grp_apprenant_color
user['grp_apprenant_code'] = grp_apprenant_code
if ("mode_animation" not in user.keys()):
user['mode_animation'] = "0"
if ("ue_id" not in user.keys()):
user['ue_id'] = ""
@ -519,6 +520,8 @@ def Get_Ent_Student_Session_Sequence_List(diction):
if ("unite_enseignement_planif_id" not in user.keys()):
user['unite_enseignement_planif_id'] = ""
print(" ### user = ", user)
RetObject.append(mycommon.JSONEncoder().encode(user))
return True, RetObject
@ -1587,3 +1590,283 @@ def Get_Ent_Student_Stored_Downloaded_File(diction):
return False, False
"""
Mise à jour du compte de l'apprenant dans lespace ENT
"""
def Get_Ent_Student_update_user_account(diction):
try:
# Dictionnaire des champs utilisables
'''
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list.
'''
field_list = ['adr_street', 'adr_city', 'adr_zip', 'adr_country', 'mob_phone','link_facebook',
'link_twitter', 'token', 'prenom', 'nom', 'birthday','link_linkedin', 'apprenant_id']
incom_keys=diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '"+val+"' n'est pas autorisé ")
return False, "Impossible de mettre à jour le compte utilisateur"
'''
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
On controle que les champs obligatoires sont presents dans la liste
'''
field_list_obligatoire = ['token', 'apprenant_id']
for val in field_list_obligatoire :
if val not in diction:
mycommon.myprint(" La valeur '"+val+"' n'est pas presente dans la liste des arguments ")
return False, "Impossible de mettre à jour le compte utilisateur"
mycommon.myprint(" MAJ de diction "+str(diction))
"""
Verifier la validité de l'apprenant
"""
is_apprenant_valide_count = MYSY_GV.dbname['apprenant'].count_documents(
{'_id': ObjectId(str(diction['apprenant_id'])),
'valide': '1',
'locked': '0'})
if (is_apprenant_valide_count != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " L'identifiant de l'apprenant est invalide ")
return False, " L'identifiant de l'apprenant est invalide ",
apprenant_data = MYSY_GV.dbname['apprenant'].find_one(
{'_id': ObjectId(str(diction['apprenant_id'])),
'valide': '1',
'locked': '0'})
coll_name = MYSY_GV.dbname['user_account']
now = datetime.now()
dictionnary = {}
dictionnary['active'] = "1"
dictionnary['date_update'] = str(now)
mytoken =""
myemail = ""
if ("adr_street" in diction.keys()):
if( str(diction['adr_street']) ):
dictionnary['adr_street'] = str(diction['adr_street'])
if ("adr_city" in diction.keys()):
if (str(diction['adr_city'])):
dictionnary['adr_city'] = str(diction['adr_city'])
if( "adr_zip" in diction.keys() ):
if (str(diction['adr_zip'])):
dictionnary['adr_zip'] = str(diction['adr_zip'])
if ("adr_country" in diction.keys()):
if (str(diction['adr_country'])):
dictionnary['adr_country'] = str(diction['adr_country'])
if ("mob_phone" in diction.keys()):
if (str(diction['mob_phone'])):
dictionnary['mob_phone'] = str(diction['mob_phone'])
if ("link_facebook" in diction.keys()):
if (str(diction['link_facebook'])):
dictionnary['link_facebook'] = str(diction['link_facebook'])
if ("link_twitter" in diction.keys()):
if (str(diction['link_twitter'])):
dictionnary['link_twitter'] = str(diction['link_twitter'])
if ("token" in diction.keys()):
if (str(diction['token'])):
mytoken = str(diction['token'])
if ("email" in diction.keys()):
if (str(diction['email'])):
myemail = str(diction['email'])
if ("prenom" in diction.keys()):
if (str(diction['prenom'])):
dictionnary['prenom'] = str(diction['prenom'])
if ("nom" in diction.keys()):
if (str(diction['nom'])):
dictionnary['nom'] = str(diction['nom'])
if ("birthday" in diction.keys()):
if (str(diction['birthday'])):
dictionnary['birthday'] = str(diction['birthday'])
if ("link_linkedin" in diction.keys()):
if (str(diction['link_linkedin'])):
dictionnary['link_linkedin'] = str(diction['link_linkedin'])
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
mycommon.myprint(" dictionnary = "+str(dictionnary))
"""
23/12/2024 : Après avoir verifier la validité du token,
on va aller chercher l'_id dans la collection 'user_account'
"""
print(" ### QRY011 = ", {'token':str(diction['token']),
'active':'1', 'locked':'0',
'apprenant_id':diction['apprenant_id']})
is_token_valide_for_one_user = MYSY_GV.dbname['user_account'].count_documents({'token':str(diction['token']),
'active':'1', 'locked':'0',
'apprenant_id':diction['apprenant_id']})
if( is_token_valide_for_one_user != 1 ):
mycommon.myprint(str(inspect.stack()[0][3]) + " Le token correspond a plusieurs au aucun utilisateur de la collection 'user_account' ")
return False, "La session est invalide "
print(" ## qry == ", {'token':str(diction['token']),
'active':'1', 'locked':'0',
'apprenant_id':diction['apprenant_id']})
ret_val = coll_name.find_one_and_update({'token':str(diction['token']),
'active':'1', 'locked':'0',
'apprenant_id': diction['apprenant_id'],
},
{"$set": dictionnary },
return_document=ReturnDocument.AFTER
)
if (ret_val and ret_val['_id']):
mycommon.myprint(str(inspect.stack()[0][3]) + " -La modif a bien ete faite =" + str(ret_val['_id']))
return True, " Le compte utilisateur a ete mis à jour"
else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucune modif n'a été faite")
return False, "Impossible de mettre à jour le compte utilisateur"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible de mettre à jour le compte utilisateur"
'''
changement du mot de passe d'un user
'''
def Get_Ent_Student_change_user_pwd(diction):
try:
# Dictionnaire des champs utilisables
field_list = ['token', 'pwd', 'new_pwd', 'conf_new_pwd', 'apprenant_id']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(" Le champ '" + val + "' n'est pas autorisé, requete annulée")
return False, " Impossible de récupérer le user account"
'''
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
On controle que les champs obligatoires sont presents dans la liste
'''
field_list_obligatoire = ['token', 'pwd', 'new_pwd', 'conf_new_pwd', 'apprenant_id']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(" La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
return False, " Impossible de mettre à jour le mot de passe"
# recuperation des paramettre
email_value = ""
token_value = ""
pwd = ""
new_pwd = ""
conf_new_pwd = ""
mydata ={}
if ("pwd" in diction.keys()):
if diction['pwd']:
pwd = diction['pwd']
if ("conf_new_pwd" in diction.keys()):
if diction['conf_new_pwd']:
conf_new_pwd = diction['conf_new_pwd']
if ("token" in diction.keys()):
if diction['token']:
token_value = diction['token']
if ("new_pwd" in diction.keys()):
if diction['new_pwd']:
new_pwd = diction['new_pwd']
mydata['pwd'] = diction['new_pwd']
# Verification de la validité du token/mail dans le cas des user en mode connecté
if ( len(str(token_value)) <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " Le token est vide")
return False, "Le token est vide"
if ( len(str(pwd)) <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " Le mot de passe est vide")
return False, "Le mot de passe est vide"
if ( len(str(new_pwd)) <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " Le nouveau mot de passe est vide")
return False, "Le nouveau mot de passe est vide"
if (str(new_pwd) != str(conf_new_pwd)):
mycommon.myprint(str(inspect.stack()[0][3]) + " - Les mots de passe ne sont pas identiques. nouveau pass :'"+str(new_pwd) +"', la oonfirmation envoyées est "''+str(conf_new_pwd)+"' ")
return False, " Les mots de passe ne sont pas identiques "
"""
Verifier la validité de l'apprenant
"""
is_apprenant_valide_count = MYSY_GV.dbname['apprenant'].count_documents(
{'_id': ObjectId(str(diction['apprenant_id'])),
'valide': '1',
'locked': '0'})
if (is_apprenant_valide_count != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " L'identifiant de l'apprenant est invalide ")
return False, " L'identifiant de l'apprenant est invalide ",
apprenant_data = MYSY_GV.dbname['apprenant'].find_one(
{'_id': ObjectId(str(diction['apprenant_id'])),
'valide': '1',
'locked': '0'})
mydata['date_update'] = str(datetime.now())
coll_name = MYSY_GV.dbname['user_account']
#print(" le recid = "+user_recid+" mydata = "+str(mydata))
ret_val = coll_name.find_one_and_update({'apprenant_id': str(diction['apprenant_id']), 'locked': '0', 'active':'1', 'pwd':pwd},
{"$set": mydata},
return_document=ReturnDocument.AFTER
)
if (ret_val and ret_val['_id']):
mycommon.myprint(str(inspect.stack()[0][3]) + " Le mot de passe de l'utilisateur (apprenant_id) =" + str(diction['apprenant_id'])+" a été modifié")
return True, "Le mot de passe a bien été mise à jour "
else:
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de mettre à jour le password du user : apprenant_id = "+str(diction['apprenant_id']))
return False, "Impossible de mettre à jour le password"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible de mettre à jour le mot de passe"

86
main.py
View File

@ -199,11 +199,25 @@ cette API gere le login et la creation du token
def login():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### payload = ",payload)
print(" ### login payload = ",payload)
status, retval, firstconnexion = us.login(payload)
return jsonify(status=status, message=retval, firstconnexion=firstconnexion)
'''
API - Ent_Student gere le login et la creation du token pour l'espace ENT
'''
@app.route('/myclass/api/Ent_Student_login/', methods=['POST','GET'])
@crossdomain(origin='*')
def Ent_Student_login():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Ent_Student_login payload = ",payload)
status, retval, firstconnexion = us.Ent_Student_login(payload)
return jsonify(status=status, message=retval, firstconnexion=firstconnexion)
'''
cette API recupere les objectifs d'un utilisateur
@ -13094,7 +13108,7 @@ def Get_Ent_Student_Stored_Downloaded_File(token, file_name, apprenant_id):
"""
API pour publier des document dans l'espace ENT des apprenants
API - Gestion ENT Apprenant : pour publier des document dans l'espace ENT des apprenants
"""
@app.route('/myclass/api/Push_Document_To_ENT_For_Inscrit/', methods=['POST','GET'])
@crossdomain(origin='*')
@ -13116,6 +13130,74 @@ def Push_Document_To_ENT_For_Inscrit():
return jsonify(status=status, message=retval)
"""
API - Gestion ENT Apprenant : Mise à jour du compte utilisateur
"""
@app.route('/myclass/api/Get_Ent_Student_update_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def Get_Ent_Student_update_user_account():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Get_Ent_Student_update_user_account : payload = ",str(payload))
status, retval = ent_student_common.Get_Ent_Student_update_user_account( payload)
return jsonify(status=status, message=retval)
"""
API - Gestion ENT Apprenant : Mise à jour du mot de passe utilisateur
"""
@app.route('/myclass/api/Get_Ent_Student_change_user_pwd/', methods=['POST','GET'])
@crossdomain(origin='*')
def Get_Ent_Student_change_user_pwd():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Get_Ent_Student_change_user_pwd : payload = ",str(payload))
status, retval = ent_student_common.Get_Ent_Student_change_user_pwd( payload)
return jsonify(status=status, message=retval)
"""
API pour créer les comptes ENT pour les apprenants
"""
@app.route('/myclass/api/ENT_Create_Apprenant_Account/', methods=['POST','GET'])
@crossdomain(origin='*')
def ENT_Create_Apprenant_Account():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### ENT_Create_Apprenant_Account payload = ",payload)
status, retval = apprenant_mgt.ENT_Create_Apprenant_Account(payload)
return jsonify(status=status, message=retval)
"""
API pour desactiver un compte ENT d'une liste d'apprenant
"""
@app.route('/myclass/api/ENT_Disable_Apprenant_Account/', methods=['POST','GET'])
@crossdomain(origin='*')
def ENT_Disable_Apprenant_Account():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### ENT_Disable_Apprenant_Account payload = ",payload)
status, retval = apprenant_mgt.ENT_Disable_Apprenant_Account(payload)
return jsonify(status=status, message=retval)
"""
API pour Reativer un compte ENT d'une liste d'apprenant
# Dans le cadre d'une reactivation, on modifie le mot de passe.
"""
@app.route('/myclass/api/ENT_Enable_Apprenant_Account/', methods=['POST','GET'])
@crossdomain(origin='*')
def ENT_Enable_Apprenant_Account():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### ENT_Enable_Apprenant_Account payload = ",payload)
status, retval = apprenant_mgt.ENT_Enable_Apprenant_Account(payload)
return jsonify(status=status, message=retval)
if __name__ == '__main__':
print(" debut api")
context = SSL.Context(SSL.SSLv23_METHOD)

View File

@ -7615,7 +7615,8 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
try:
diction = strip_dictionary(diction)
field_list = ['token', 'list_email_dest', 'related_collection', 'list_inscription_id']
field_list = ['token', 'list_email_dest', 'related_collection', 'list_inscription_id',
'ent_push_doc_message_notif', 'session_id']
incom_keys = diction.keys()
for val in incom_keys:
@ -7624,7 +7625,7 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
3]) + " - Le champ '" + val + "' n'est pas autorisé")
return False, "Toutes les informations fournies ne sont pas valables"
field_list_obligatoire = ['token', 'list_email_dest', 'related_collection', 'list_inscription_id']
field_list_obligatoire = ['token', 'list_email_dest', 'related_collection', 'list_inscription_id', 'session_id']
for val in field_list_obligatoire:
if val not in diction:
@ -7650,6 +7651,23 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
# print(" #### list_inscription_id = ", list_inscription_id)
"""
Recuperer les données de la session de formation
"""
code_session_formation = ""
if ("session_id" in diction.keys() and diction['session_id']):
session_data = MYSY_GV.dbname['session_formation'].find_one({"_id":ObjectId(str(diction['session_id'])),
'valide':'1',
'partner_owner_recid':str(my_partner['recid'])}, {'_id':1, 'code_session':1})
if( session_data and 'code_session' in session_data.keys()):
code_session_formation = session_data['code_session']
"""
Verifier la validité "related_collection"
"""
@ -7744,7 +7762,6 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
tab_files_to_attache_to_mail.append(new_node)
local_diction = {}
local_diction['token'] = diction['token']
local_diction['tab_file_name'] = tab_saved_file_full_path
@ -7756,6 +7773,7 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
"""
Envoie des email de notification des apprenants
"""
# Recuperation des donnes SMTP
@ -7778,6 +7796,39 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
cpt_email_envoye = 0
# Creation du dictionnaire d'information à utiliser pour la creation du doc
convention_dictionnary_data = {}
new_diction = {}
new_diction['token'] = my_partner['token']
new_diction['list_stagiaire_id'] = []
new_diction['list_session_id'] = []
new_diction['list_class_id'] = []
new_diction['list_client_id'] = []
local_status, local_retval = Get_Dictionnary_data_For_Template(new_diction)
if (local_status is False):
return local_status, local_retval
convention_dictionnary_data = local_retval
convention_dictionnary_data['code_session_formation'] = code_session_formation
if( "ent_push_doc_message_notif" in diction.keys() and diction['ent_push_doc_message_notif']):
convention_dictionnary_data['ent_push_doc_message_notif'] = diction['ent_push_doc_message_notif']
# Recuperer l'url vers l'espace ENT
config_partner_catalog_data = MYSY_GV.dbname['config_partner_catalog'].find_one({'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'}, {'_id':1, 'partner_ent_student_url':1})
if( config_partner_catalog_data and "partner_ent_student_url" in config_partner_catalog_data.keys() and config_partner_catalog_data['partner_ent_student_url']):
convention_dictionnary_data['partner_ent_student_url'] = config_partner_catalog_data['partner_ent_student_url']
for user_id in tab_related_collection_id:
user_related_collection_data = MYSY_GV.dbname[str(related_collection)].find_one(
@ -7799,21 +7850,7 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
if ("email" in user_related_collection_data.keys()):
email = user_related_collection_data['email']
# Creation du dictionnaire d'information à utiliser pour la creation du doc
convention_dictionnary_data = {}
new_diction = {}
new_diction['token'] = my_partner['token']
new_diction['list_stagiaire_id'] = []
new_diction['list_session_id'] = []
new_diction['list_class_id'] = []
new_diction['list_client_id'] = []
local_status, local_retval = Get_Dictionnary_data_For_Template(new_diction)
if (local_status is False):
return local_status, local_retval
convention_dictionnary_data = local_retval
node = {}
convention_dictionnary_data['nom'] = nom
@ -7822,175 +7859,72 @@ def Push_Document_To_ENT_For_Inscrit(tab_files, Folder, diction):
"params": convention_dictionnary_data,
}
# Creation de l'email à enoyer zzzz
msg = MIMEMultipart("alternative")
html = '''
<!DOCTYPE html>
<html>
<body>
<h3> Nouveau document dans votre espace ENT </h3>
Bonjour {nom} {prenom}, <br/>
Vous avez un nouveau document dans votre espace ENT.
<br/>
</body>
</html>'''.format(nom=str(user_related_collection_data['nom']),
prenom=str(user_related_collection_data['prenom']))
html_mime = MIMEText(html, 'html')
local_diction = {}
local_diction['token'] = diction['token']
local_diction['partner_own_smtp_value'] = partner_own_smtp_value
local_diction['partner_SMTP_COUNT_smtpsrv'] = partner_SMTP_COUNT_smtpsrv
local_diction['partner_SMTP_COUNT_port'] = partner_SMTP_COUNT_port
local_diction['user_id'] = user_id
local_diction['related_collection'] = related_collection
local_diction['partner_SMTP_COUNT_From_User'] = partner_SMTP_COUNT_From_User
local_diction['tab_email_bcc'] = "contact@mysy-training.com"
local_diction['tab_files_to_attache_to_mail'] = tab_files_to_attache_to_mail
local_diction['email_sujet'] = "Nouveau document dans votre espace ENT"
local_diction['html_mime'] = html_mime
local_diction['email'] = email
local_diction['ref_interne'] = "ENT_PUSH_DOCUMENT_NOTIF"
local_diction['type_doc'] = "email"
local_diction['partner_owner_recid'] = str(my_partner['recid'])
if ("include_client" in diction.keys()):
local_diction['include_client'] = diction['include_client']
else:
local_diction['include_client'] = "0"
courrier_data_status, courrier_data_retval = Get_Courrier_Template_Include_Default_Data(
local_diction)
if (courrier_data_status is False):
myprint(
str(inspect.stack()[0][
3]) + " Impossible de récuperer le modèle de courrier 'ENT_PUSH_DOCUMENT_NOTIF' ")
return False, " Impossible de récuperer le modèle de courrier 'ENT_PUSH_DOCUMENT_NOTIF' "
if ("include_tuteur" in diction.keys()):
local_diction['include_tuteur'] = diction['include_tuteur']
else:
local_diction['include_tuteur'] = "0"
if ("corps_mail" not in courrier_data_retval.keys() or str(courrier_data_retval['corps_mail']) == ""):
myprint(
str(inspect.stack()[0][
3]) + " Le modèle de courrier 'ENT_PUSH_DOCUMENT_NOTIF' n'est pas correctement configuré ")
return False, " Le modèle de courrier 'ENT_PUSH_DOCUMENT_NOTIF' n'est pas correctement configuré"
# print(" ### local_diction = ", local_diction)
local_status, local_retval = send_invidual_email_for_ENT_Document_Notif(local_diction)
if (local_status is False):
return local_status, local_retval
# Traitement du sujet du mail
sujet_mail_Template = jinja2.Template(str(courrier_data_retval['sujet']))
sujetHtml = sujet_mail_Template.render(params=body["params"])
# Traitement du corps du mail
contenu_doc_Template = jinja2.Template(str(courrier_data_retval['corps_mail']))
corp_mailHtml = contenu_doc_Template.render(params=body["params"])
html_mime = MIMEText(corp_mailHtml, 'html')
# Creation de l'email à enoyer
msg = MIMEMultipart("alternative")
if (str(partner_own_smtp_value) == "1"):
msg.attach(html_mime)
msg['From'] = partner_SMTP_COUNT_From_User
msg['Bcc'] = "contact@mysy-training.com"
msg['Subject'] = sujetHtml
msg['to'] = str(email)
# Attacher l'eventuelle pièces jointes
for myfile in tab_files_to_attache_to_mail:
msg.attach(myfile['attached_file'])
val = smtpserver.send_message(msg)
print(" Email a envoyé " + str(email))
cpt_email_envoye = cpt_email_envoye + 1
else:
msg.attach(html_mime)
msg['From'] = partner_SMTP_COUNT_From_User
msg['Bcc'] = "contact@mysy-training.com"
msg['Subject'] = sujetHtml
msg['to'] = str(email)
val = smtpserver.send_message(msg)
print(" Email a envoyé " + str(email))
cpt_email_envoye = cpt_email_envoye + 1
print(" NB_email envoyé = ", cpt_email_envoye)
"""
smtpserver.close()
return True, " Les documents ont été publiés"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de publier les documents dans l'espace ENT "
"""
Envoie email de notif pour le partage de document sur l'ENT
"""
def send_invidual_email_for_ENT_Document_Notif(diction):
try:
diction = strip_dictionary(diction)
my_token = ""
if ("token" in diction.keys()):
if diction['token']:
my_token = diction['token']
local_status, my_partner = Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
smtpserver = None
partner_own_smtp_value = diction['partner_own_smtp_value']
partner_SMTP_COUNT_smtpsrv = diction['partner_SMTP_COUNT_smtpsrv']
partner_SMTP_COUNT_port = diction['partner_SMTP_COUNT_port']
partner_SMTP_COUNT_From_User = diction['partner_SMTP_COUNT_From_User']
if( "tab_email_cc" in diction.keys()):
tab_email_cc = diction['tab_email_cc']
else:
tab_email_cc=""
if( "tab_email_bcc" in diction.keys()):
tab_email_bcc = diction['tab_email_bcc']
else:
tab_email_bcc = ""
tab_files_to_attache_to_mail = diction['tab_files_to_attache_to_mail']
email_sujet = diction['email_sujet']
html_mime = diction['html_mime']
email = diction['email']
user_id = diction['user_id']
related_collection = diction['related_collection']
partner_owner_recid = diction['partner_owner_recid']
# Recuperer les données tuteurs
if(related_collection == "inscription" ):
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(user_id)),
'partner_owner_recid':str(partner_owner_recid)},
)
if (str(partner_own_smtp_value) == "1"):
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
else:
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
cpt_email_envoye = 0
"""
Envoie proprement-dit des emails
"""
# Creation de l'email à enoyer
msg = MIMEMultipart("alternative")
if (str(partner_own_smtp_value) == "1"):
msg.attach(html_mime)
msg['From'] = partner_SMTP_COUNT_From_User
msg['Cc'] = ",".join(tab_email_cc)
msg['Bcc'] = ",".join(tab_email_bcc)
msg['Subject'] = email_sujet
msg['to'] = str(email)
# Attacher l'eventuelle pièces jointes
for myfile in tab_files_to_attache_to_mail:
msg.attach(myfile['attached_file'])
val = smtpserver.send_message(msg)
print(" Email a envoyé " + str(email))
cpt_email_envoye = cpt_email_envoye + 1
else:
msg.attach(html_mime)
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
msg['Cc'] = ",".join(tab_email_cc)
msg['Bcc'] = ",".join(tab_email_bcc)
msg['Subject'] = email_sujet
msg['to'] = str(email)
# Attacher l'eventuelle pièces jointes
for myfile in tab_files_to_attache_to_mail:
msg.attach(myfile['attached_file'])
val = smtpserver.send_message(msg)
print(" Email a envoyé " + str(email))
cpt_email_envoye = cpt_email_envoye + 1
smtpserver.close()
return True, " Les emails ont été correctement envoyés"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer les emails "

View File

@ -181,6 +181,164 @@ def login(diction):
return False, " Impossible de se connecter, merci de contacter le support technique", False
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible de se connecter, merci de contacter le support technique", False
'''
Lorsqu'un user se logue, on recupere son RecId,
puis on enregiste dans table des token :
- le recid,
- le token
'''
def Ent_Student_login(diction):
try:
# Dictionnaire des champs utilisables
field_list = ['email', 'pwd', 'type']
incom_keys = diction.keys()
'''
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list.
'''
for val in incom_keys:
if str(val).lower() not in str(field_list).lower():
mycommon.myprint(str(inspect.stack()[0][3])+" Le champ '" + val + "' n'existe pas, MAJ annulée")
return False, " Impossible de se connecter, merci de contacter le support technique", False
'''
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
On controle que les champs obligatoires sont presents dans la liste
'''
field_list_obligatoire = ['email', 'pwd']
for val in field_list_obligatoire:
if str(val).lower() not in diction:
mycommon.myprint(str(inspect.stack()[0][3])+" La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
return False, " Impossible de se connecter, merci de contacter le support technique", False
query = {}
# recuperation des paramettre
if ("email" in diction.keys()):
if diction['email']:
email = diction['email']
query['email'] = diction['email']
if ("pwd" in diction.keys()):
if diction['pwd']:
pwd = diction['pwd']
query['pwd'] = diction['pwd']
if ("type" in diction.keys()):
if diction['type']:
type = diction['type']
query['type'] = diction['type']
query['active'] = '1'
query['locked'] = '0'
# Recuperation du RecId du user connecté
coll_name = MYSY_GV.dbname['user_account']
#print(" on recherche ici " + email)
# Verification si ce user existe (controle : login et passwd)
tmp = coll_name.count_documents(query)
if (tmp != 1):
mycommon.myprint(str(inspect.stack()[0][3])+" Login/mot de passe invalide " + str(query)+ " my_user.count() = "+str(tmp))
return False, " Login/mot de passe invalide, merci de verifier votre saisie. ", False
my_user = coll_name.find(query)
#recuperation du recid du user
user_recid = my_user[0]['partner_owner_recid']
user_firstconnexion = ""
if( "firstconnexion" in my_user[0].keys() ):
user_firstconnexion = my_user[0]['firstconnexion']
#print("#### user_recid = "+user_recid)
# A ce niveau le login et passe sont ok.
# il faut donc créer le token et renvoyer le token.
my_token = create_token_urlsafe()
# Enregistrement du token
token_collection = MYSY_GV.dbname['partner_token']
tokenfield = {}
tokenfield['token'] = my_token
tokenfield['email'] = email
tokenfield['recid'] = user_recid
tokenfield['date_update'] = str(datetime.now())
tokenfield['start_date'] = str(datetime.now())
tokenfield['valide'] = '1'
tokenfield['locked'] = '0'
tokenfield['type'] = 'user'
'''
Si il y a un token en cours de validité, il est mis à jour pr prolonger la durée
de vie du token
s'il n'y a pas de token valide, aloes on insert un.
'''
ret_val = token_collection.find_one_and_update({'recid': str(user_recid), 'valide': '1'},
{"$set": tokenfield},
upsert=True,
return_document=ReturnDocument.AFTER
)
if ret_val and ret_val['_id']:
mycommon.myprint(" Ajout Token OK, _id = "+str(ret_val['_id']))
now = str(datetime.now())
"""
Mise à jour du compte du partenaie
avec les info de last connexion et de token
"""
partner_update_data = {}
partner_update_data['lastconnexion'] = str(datetime.now())
partner_update_data['firstconnexion'] = "0"
partner_update_data['token'] = str(my_token)
partner_key_secrete_key = ""
# Verification que les informations sont juste
coll_name = MYSY_GV.dbname['user_account']
ret_val = coll_name.find_one_and_update(
{'email': str(email), 'pwd': str(pwd), 'active': '1', 'locked': '0'},
{"$set": partner_update_data},
upsert=False,
return_document=ReturnDocument.AFTER
)
if ("_id" not in ret_val.keys()):
mycommon.myprint(
str(inspect.stack()[0][3]) + " Impossible de récupérer les données de l'utilisateur (2)")
return False, " Impossible de récupérer les données de l'utilisateur (2) ", False
return True, str(my_token), str(user_firstconnexion)
else:
mycommon.myprint(str(inspect.stack()[0][3])+" Impossible d'enregistrer le token " + my_token)
return False, " Impossible de se connecter, merci de contacter le support technique", False
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))