16/01/2025 - 16h30

master
cherif 2025-01-16 16:44:07 +01:00
parent 7c9e7b832e
commit 005926cc98
8 changed files with 19182 additions and 19 deletions

View File

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="03/01/2025 - 17h30">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="04/01/2025 - 14h48">
<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$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" 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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/partner_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_client.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/partners.py" beforeDir="false" afterPath="$PROJECT_DIR$/partners.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -76,13 +80,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00378" summary="21/08/2024 - 13h55">
<created>1724240924909</created>
<option name="number" value="00378" />
<option name="presentableId" value="LOCAL-00378" />
<option name="project" value="LOCAL" />
<updated>1724240924910</updated>
</task>
<task id="LOCAL-00379" summary="ss">
<created>1724424786372</created>
<option name="number" value="00379" />
@ -419,7 +416,14 @@
<option name="project" value="LOCAL" />
<updated>1735921643830</updated>
</task>
<option name="localTasksCounter" value="427" />
<task id="LOCAL-00427" summary="04/01/2025 - 14h48">
<created>1735999170270</created>
<option name="number" value="00427" />
<option name="presentableId" value="LOCAL-00427" />
<option name="project" value="LOCAL" />
<updated>1735999170271</updated>
</task>
<option name="localTasksCounter" value="428" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -461,7 +465,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="sdfsdsdsd" />
<MESSAGE value="05/10/2024 - 12h" />
<MESSAGE value="05/10/2024 - 18h30" />
<MESSAGE value="07/10/2024 - 20h30" />
@ -486,6 +489,7 @@
<MESSAGE value="sdfdd" />
<MESSAGE value="31/12/2024 - 12h30" />
<MESSAGE value="03/01/2025 - 17h30" />
<option name="LAST_COMMIT_MESSAGE" value="03/01/2025 - 17h30" />
<MESSAGE value="04/01/2025 - 14h48" />
<option name="LAST_COMMIT_MESSAGE" value="04/01/2025 - 14h48" />
</component>
</project>

View File

@ -873,3 +873,7 @@ Annulation d'un ordre de vocal
VOICE_INSTRUCTION_ANNULATION = ["annuler", "annulle", "refus", "refuser"]
"""
Gestion du context de connexion d'un partenaire
"""
PARTNER_ACCOUNT_CONNEXION_CONTEXT_VALUES = ['mysy_session_display_view', 'mysy_menu_gauche_reduit']

File diff suppressed because it is too large Load Diff

View File

@ -3306,8 +3306,6 @@ def Create_Automatic_Sequence_From_Week_Model(diction):
" est postérieure à la date de fin de formation " + str(diction['planif_date_fin'])[0:10] + " "
semaine_tab_event = diction['semaine_tab_event']
semaine_tab_event_JSON = ast.literal_eval(semaine_tab_event)

35
main.py
View File

@ -3443,8 +3443,6 @@ def Enable_MySy_LMS_User():
return jsonify(status=localStatus, message=message)
@app.route('/myclass/api/email_validation_mairies/', methods=['POST','GET'])
@crossdomain(origin='*')
def email_validation_mairies():
@ -3454,6 +3452,22 @@ def email_validation_mairies():
localStatus, message= tools_cherif.email_validation_mairies()
return jsonify(status=localStatus, message=message )
"""
API qui test le site est Up ou KO
"""
@app.route('/myclass/api/check_if_site_is_up/', methods=['POST','GET'])
@crossdomain(origin='*')
def check_if_site_is_up():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### check_if_site_is_up : payload = ",payload)
localStatus, message= tools_cherif.check_if_site_is_up(payload)
return jsonify(status=localStatus, message=message )
@app.route('/myclass/api/email_validation_hopitaux_ehpad/', methods=['POST','GET'])
@crossdomain(origin='*')
def email_validation_hopitaux_ehpad():
@ -5664,6 +5678,23 @@ def Lock_partner_account_From_Rh_Id():
return jsonify(status=status, message=retval)
"""
Cette API permet de mettre à jour le contexte de connexion
d'une personne (partenair_account) connectée
"""
@app.route('/myclass/api/Update_Context_Partner_Account/', methods=['POST','GET'])
@crossdomain(origin='*')
def Update_Context_Partner_Account():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Update_Context_Partner_Account payload = ",payload)
status, retval = pa.Update_Context_Partner_Account(payload)
return jsonify(status=status, message=retval)
"""
Cette API reactive le compte utilisateur d'un employé
"""

View File

@ -361,7 +361,7 @@ def Add_Partner_Client(diction):
list_adress = ast.literal_eval(diction['address'])
data['address'] = list_adress
for adress_val in list_adress :
print(" ### adress_val = ", adress_val)
#print(" ### adress_val = ", adress_val)
address = adress_val
data['address'][line]['recid'] = mycommon.create_user_recid()
line = line + 1

View File

@ -8,6 +8,7 @@ exemple :
- creation d'une api de desactivation d'une formation
'''
import ast
from pymongo import MongoClient
import pymongo
@ -1516,7 +1517,7 @@ def partner_login(diction):
RetObject = []
print(" #### partner_login : return_data = ", return_data)
#print(" #### partner_login : return_data = ", return_data)
RetObject.append(JSONEncoder().encode(return_data))
@ -1855,3 +1856,141 @@ def UnLock_partner_account(diction):
return False, "Impossible de réactiver le compte utilisateur "
"""
Cette fonction permet de gerer le context de session d'un partenaire
Par exemple :
- menu gauche reduit ou deplié
- affichage des sessions en mode kanban, list ou pipeline
- etc
Un certain de nombre de variables seront stockés en mode Json dans une context
ex :
context = [{val1: value}, {val2:value}, ....]
Cette information sera retounée à chaque connexion
"""
def Update_Context_Partner_Account(diction):
try:
field_list = ['token', 'partner_id', 'tab_context_json']
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é, Creation partenaire annulée")
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
"""
Verification de la liste des champs obligatoires
"""
field_list_obligatoire = ['token', 'partner_id', 'tab_context_json']
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 liste ")
return False, "Toutes les informations necessaires n'ont pas été fournies"
# Recuperation du recid du partner
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
# Verifier que le compte existe
is_partner_account_valide = MYSY_GV.dbname['partnair_account'].count_documents({'_id':ObjectId(str(diction['partner_id'])),
'recid':my_partner['recid']})
if( is_partner_account_valide != 1 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant du compte est invalide ")
return False, " L'identifiant du compte est invalide "
tab_context = diction['tab_context_json']
tab_context_JSON = ast.literal_eval(tab_context)
for context in tab_context_JSON :
for key, value in context.items():
if (key not in MYSY_GV.PARTNER_ACCOUNT_CONNEXION_CONTEXT_VALUES):
mycommon.myprint(
str(inspect.stack()[0][3]) + " La clé de context " + str(key) + " est invalide ")
return False, " La clé de context " + str(key) + " est invalide "
update_qry = {'_id': ObjectId(str(diction['partner_id'])),
'active': '1',
'locked': '0',
'list_connexion_context.code': str(key)}
"""
Verifier si j'ai une telle variable de stocké deja
"""
is_context_exist = "0"
for tmp in MYSY_GV.dbname['partnair_account'].find({'list_connexion_context.code':str(key)}):
is_context_exist = "1"
if( is_context_exist == "0"):
# L'utilisateur n'a pas cette veleur de context, il faut la créer
#print(" ### L'utilisateur n'a pas cette veleur de context, il faut la créer")
new_data = {}
new_data['valide'] = "1"
new_data['locked'] = "0"
new_data['date_create'] = str(datetime.now())
new_data['code'] = str(key)
new_data['code_value'] = str(value)
create = MYSY_GV.dbname['partnair_account'].update_one({
'_id': ObjectId(str(diction['partner_id'])),
'active': '1',
'locked': '0',
},
{
'$push': {
"list_connexion_context": {
'$each': [new_data]
}
}
},
)
else:
# L'utilisateur 1 a DEJA Cette veleur de context, il faut faire une mise à jour
#print(" ### L'utilisateur 1 a DEJA Cette veleur de context, il faut faire une mise à jour ")
update = MYSY_GV.dbname['partnair_account'].update_one({'_id': ObjectId(str(diction['partner_id'])),
'active': '1',
'locked': '0',
'list_connexion_context.code': str(key)},
{'$set':
{
'list_connexion_context.$[xxx].code_value': str(value),
'list_connexion_context.$[xxx].date_update': str(datetime.now())
}
},
upsert=False,
array_filters=[
{"xxx.code": str(key)}
]
)
print(" ### update = ", update)
return True, "Le contexte de connexion a été correctement mis à jour"
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 contexte de connexion "

View File

@ -1,4 +1,7 @@
import ast
import ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import pymongo
import zeep
@ -18,9 +21,84 @@ from math import isnan
import GlobalVariable as MYSY_GV
import ela_index_bdd_classes as eibdd
import email_mgt as email
import urllib.request
from validate_email import validate_email
import jinja2
"""
Cette fonction monitore un siteweb.
si Ko, alors il envoie un email
à cherif.
c'est une version degradée
"""
def check_if_site_is_up(diction):
try:
print(' ### diction = ', diction)
URL = diction['url']
site_status = False
try:
response = requests.head(URL)
except Exception as e:
print(f"NOT OK: {str(e)}")
site_status = False
else:
if response.status_code == 200:
print("OK")
site_status = True
else:
print(f"NOT OK: HTTP response code {response.status_code}")
site_status = False
if( site_status is True):
return site_status, " Site OKKK"
else:
""" Envoyer un email """
html = '''
<!DOCTYPE html>
<html>
<body>
<h2> Votre Site mysy-training.com est KO </h2>
Bonjour, <br/>
Merci de verifier l'état de votre site MySy-Traning.com
<br/>
</body>
</html>'''
html_mime = MIMEText(html, 'html')
msg = MIMEMultipart("alternative")
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
msg.attach(html_mime)
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
msg['Bcc'] = 'contact@mysy-training.com'
msg['Subject'] = " IMPORTANT : Votre site mysy-training.com est KO"
msg['To'] = "cherif.balde@yahoo.fr, cbalde@mysy-training.com"
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
val = smtpserver.send_message(msg)
smtpserver.close()
print(" Email envoyé " + str(val))
html_mime = MIMEText(html, 'html')
return site_status, " Site KOOO"
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 récupérer la formation"
def email_validation():
try: