15/01/2024 - 17h00
parent
c50156fe99
commit
99603f883e
|
@ -3,10 +3,11 @@
|
|||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="12/01/24 - 16h30">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Dashbord_queries/ressources_humaines_tbd_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/ressources_humaines_tbd_qries.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$/class_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/class_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" beforeDir="false" afterPath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partners.py" beforeDir="false" afterPath="$PROJECT_DIR$/partners.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ressources_humaines.py" beforeDir="false" afterPath="$PROJECT_DIR$/ressources_humaines.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
3203
Log/log_file.log
3203
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -58,7 +58,7 @@ def test_connexion_php_myadmin():
|
|||
|
||||
|
||||
"""
|
||||
Cette fonction créer un utilisateur (editeur de formation) lms mysy, donc dans chamilo
|
||||
Cette fonction créer un utilisateur (compte principale) lms mysy, donc dans chamilo
|
||||
"""
|
||||
def Create_MySy_LMS_User(diction):
|
||||
try:
|
||||
|
@ -96,24 +96,13 @@ def Create_MySy_LMS_User(diction):
|
|||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
partner_recid = ""
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
if (len(str(my_token)) > 0):
|
||||
retval = mycommon.check_partner_token_validity("", my_token)
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - La session de connexion n'est pas valide")
|
||||
return False, " Impossible de créer le compte LMS", False
|
||||
partner_recid = str(my_partner['recid'])
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if partner_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le token du partenaire")
|
||||
return False, " Impossible de récupérer le token du partenaire", False
|
||||
|
||||
if (len(str(my_token)) <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||
return False, " Impossible de créer le compte LMS", False
|
||||
|
||||
lastname = ""
|
||||
if ("lastname" in diction.keys()):
|
||||
|
@ -248,8 +237,10 @@ def Create_MySy_LMS_User(diction):
|
|||
hashed_pwd) + "', " \
|
||||
"enabled='1', " \
|
||||
"expired='0', " \
|
||||
"mysy_recid='"+str(partner_recid)+"', " \
|
||||
"locked = '0', " \
|
||||
"mysy_recid='"+str(my_partner['_id'])+"', " \
|
||||
"mysy_partner_owner_recid='" + str(
|
||||
my_partner['recid']) + "', " \
|
||||
"locked = '0', " \
|
||||
"auth_source = 'platform'," \
|
||||
"roles = 'a:0:{}', " \
|
||||
"language = 'french'," \
|
||||
|
@ -269,8 +260,9 @@ def Create_MySy_LMS_User(diction):
|
|||
"lastname = '"+lastname+"', " \
|
||||
"firstname = '"+firstname+"', " \
|
||||
"username = '"+username+"', " \
|
||||
"mysy_recid='" + str(partner_recid) + "', " \
|
||||
"salt = '"+str(salt)+"'," \
|
||||
"mysy_recid='" +str(my_partner['_id']) + "', " \
|
||||
"mysy_partner_owner_recid='" + str(my_partner['recid']) + "', " \
|
||||
"salt = '"+str(salt)+"'," \
|
||||
" registration_date = '"+registration_date+"'," \
|
||||
" credentials_expired='0', " \
|
||||
"enabled='1', " \
|
||||
|
@ -399,9 +391,11 @@ def Create_MySy_LMS_User(diction):
|
|||
|
||||
# Crementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||
|
||||
#print(" ### current_seq_value = ", current_seq_value)
|
||||
print(" ### current_seq_value = ", current_seq_value)
|
||||
new_sequence_value = int(mycommon.tryInt(current_seq_value))+1
|
||||
|
||||
#print(" ### New_current_seq_value = ", current_seq_value)
|
||||
|
||||
mydata = {'current_val':new_sequence_value}
|
||||
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'related_mysy_object':'lms_user_id', 'valide':'1'},
|
||||
{"$set": mydata},
|
||||
|
@ -1724,7 +1718,7 @@ def Remove_User_From_LMS_Class(diction):
|
|||
Cette fonction permet de créer un apprenant.
|
||||
use case :
|
||||
Lorsqu'une inscription est validée sur mysy, on va créer le user apprenant
|
||||
:!\ : a ne pas confondre avec la creation d'un utilisateur enseignat """
|
||||
:!\ : a ne pas confondre avec la creation d'un utilisateur enseignant """
|
||||
def Create_MySy_LMS_Apprenant(diction):
|
||||
try:
|
||||
|
||||
|
@ -1832,8 +1826,7 @@ def Create_MySy_LMS_Apprenant(diction):
|
|||
registration_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object':'lms_user_id', 'valide':'1'})
|
||||
|
||||
|
||||
|
||||
mypasswd = password.encode('UTF-8')
|
||||
|
@ -1846,11 +1839,31 @@ def Create_MySy_LMS_Apprenant(diction):
|
|||
salt = salt.decode("UTF-8")
|
||||
hashed_pwd = hashed_pwd.decode("UTF-8")
|
||||
|
||||
"""
|
||||
"""
|
||||
mysy_sequence_id = ""
|
||||
|
||||
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'lms_user_id', 'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (retval is None or "current_val" not in retval.keys()):
|
||||
mycommon.myprint(" Impossible de récupérer la sequence 'mysy_sequence' ")
|
||||
return False, "Impossible de récupérer la sequence 'mysy_sequence'",False
|
||||
|
||||
# Il n'a pas de sequence pour ce partenaire, verifier s'il ya une sequence par defaut
|
||||
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'lms_user_id', 'valide': '1',
|
||||
'partner_owner_recid': "default"})
|
||||
|
||||
if (retval is None or "current_val" not in retval.keys()):
|
||||
mycommon.myprint(" Aucune séquence 'lms_user_id' n'est paramétré dans le système ")
|
||||
return False, " Aucune séquence 'lms_user_id' n'est paramétré dans le système ", False
|
||||
|
||||
# on stock l'id trouvé
|
||||
mysy_sequence_id = str(retval['_id'])
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
new_lms_user_id = str(retval['prefixe'])+str(retval['current_val'])
|
||||
local_status, local_val = mycommon.IsInt(new_lms_user_id)
|
||||
|
@ -1954,6 +1967,7 @@ def Create_MySy_LMS_Apprenant(diction):
|
|||
my_query_access_url_rel_user = "INSERT INTO access_url_rel_user SET access_url_id='"+str(lms_virtualhost_id)+"' , user_id='" + str(
|
||||
new_lms_user_id) + "' "
|
||||
print(" ### my_query_access_url_rel_user = ", my_query_access_url_rel_user)
|
||||
|
||||
try:
|
||||
|
||||
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||
|
@ -1973,7 +1987,7 @@ def Create_MySy_LMS_Apprenant(diction):
|
|||
new_sequence_value = int(mycommon.tryInt(current_seq_value))+1
|
||||
|
||||
mydata = {'current_val':new_sequence_value}
|
||||
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'related_mysy_object':'lms_user_id', 'valide':'1'},
|
||||
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'_id':ObjectId(str(mysy_sequence_id))},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert= False,
|
||||
|
@ -2033,6 +2047,12 @@ def LMS_Get_Partner_Data(diction):
|
|||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
local_status, connected_user_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, connected_user_data
|
||||
|
||||
|
||||
print(" #### connected_user_data = ", connected_user_data)
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if (partner_recid is False):
|
||||
|
@ -2072,10 +2092,12 @@ def LMS_Get_Partner_Data(diction):
|
|||
lms_virtualhost_url = ""
|
||||
lms_url = ""
|
||||
if( lms_account == "1"):
|
||||
lms_user_id = my_partner['mysy_lms_user_id']
|
||||
lms_user_id = connected_user_data['mysy_lms_user_id']
|
||||
lms_user_name = my_partner['email']
|
||||
lms_pwd_mask = my_partner['pwd']
|
||||
lms_part_recid = my_partner['recid']
|
||||
#lms_pwd_mask = my_partner['pwd']
|
||||
#lms_part_recid = my_partner['recid']
|
||||
lms_part_recid = str(connected_user_data['_id'])
|
||||
lms_pwd_mask = str(connected_user_data['pwd'])
|
||||
lms_virtualhost_url = my_partner['lms_virtualhost_url']
|
||||
lms_url = MYSY_GV.MYSY_LMS_URL
|
||||
|
||||
|
@ -2092,7 +2114,7 @@ def LMS_Get_Partner_Data(diction):
|
|||
"""
|
||||
|
||||
day_on_2_digit = '{:02d}'.format(datetime.now().day)
|
||||
lms_pwd_mask = "mSyt"+str(lms_user_id)+str(day_on_2_digit)+str(my_partner['pwd'])
|
||||
lms_pwd_mask = "mSyt"+str(lms_user_id)+str(day_on_2_digit)+str(connected_user_data['pwd'])
|
||||
|
||||
val_tmp = {}
|
||||
val_tmp['lms_account'] = lms_account
|
||||
|
@ -3806,3 +3828,417 @@ def Push_Class_To_MySy_LMS(diction):
|
|||
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 mettre à jour la formation sur la plateforme de E-Learning "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de créer proprement
|
||||
un enseignant rattaché à un compte partenaire
|
||||
"""
|
||||
def Create_MySy_LMS_Enseignant_Account(diction):
|
||||
try:
|
||||
|
||||
'''
|
||||
# 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 = ['token', 'lastname', 'firstname', 'email', 'password', 'locked', 'official_code', 'username', 'rh_partner_account_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, " Le champ '" + val + "' n'est pas autorisé", 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 = ['token', 'lastname', 'firstname', 'email', 'password', 'locked', 'official_code', 'rh_partner_account_id']
|
||||
|
||||
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 obligatoire n'ont pas été fournies", False
|
||||
|
||||
# recuperation des paramettre
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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, False
|
||||
|
||||
partner_recid = str(my_partner['recid'])
|
||||
|
||||
# recuperation des paramettre
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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, False
|
||||
|
||||
partner_recid = str(my_partner['recid'])
|
||||
|
||||
|
||||
lastname = ""
|
||||
if ("lastname" in diction.keys()):
|
||||
if diction['lastname']:
|
||||
local_status, lastname = mycommon.RemoveAllNonAlphaNumeric(diction['lastname'])
|
||||
|
||||
firstname = ""
|
||||
if ("firstname" in diction.keys()):
|
||||
if diction['firstname']:
|
||||
local_status, firstname = mycommon.RemoveAllNonAlphaNumeric(diction['firstname'])
|
||||
|
||||
password = ""
|
||||
if ("password" in diction.keys()):
|
||||
if diction['password']:
|
||||
password = diction['password']
|
||||
|
||||
email = ""
|
||||
if ("email" in diction.keys()):
|
||||
if diction['email']:
|
||||
email = diction['email']
|
||||
|
||||
locked = ""
|
||||
if ("locked" in diction.keys()):
|
||||
if diction['email']:
|
||||
locked = diction['locked']
|
||||
|
||||
official_code = ""
|
||||
if ("official_code" in diction.keys()):
|
||||
if diction['official_code']:
|
||||
official_code = diction['official_code']
|
||||
|
||||
username = ""
|
||||
if ("username" in diction.keys()):
|
||||
if diction['username']:
|
||||
local_status, username = mycommon.RemoveAllNonAlphaNumeric(diction['username'])
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner_data = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire", False
|
||||
|
||||
# On affecte le lms_virtualhost_id par defaut à la racine, donc le site principale.
|
||||
# Si le propritaire de la formation à un 'lms_virtualhost_id' dédié, on remplace le principale par celui du proprio
|
||||
lms_virtualhost_id = "1"
|
||||
if ("lms_virtualhost_id" in my_partner_data.keys()):
|
||||
if my_partner_data['lms_virtualhost_id']:
|
||||
lms_virtualhost_id = my_partner_data['lms_virtualhost_id']
|
||||
|
||||
nom_partner = ""
|
||||
if ("nom" not in my_partner_data.keys()):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le nom du partenaire est vide ")
|
||||
return False, str(inspect.stack()[0][3]) + " - Le nom du partenaire est vide "
|
||||
|
||||
nom_partner = mycommon.remove_non_ascii(str(my_partner_data['nom']))
|
||||
|
||||
local_status, nom_partner = mycommon.local_Remove_Ponct_Special_Caractere(nom_partner)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Le nom du partenaire : local_Remove_Ponct_Special_Caractere ")
|
||||
return False, str(
|
||||
inspect.stack()[0][3]) + " - Le nom du partenaire : local_Remove_Ponct_Special_Caractere ", False
|
||||
|
||||
suffix_nom_partner = str(nom_partner)[0:3]
|
||||
|
||||
username = str(str(username) + "_" + str(suffix_nom_partner)).lower()
|
||||
local_status, username = mycommon.RemoveAllNonAlphaNumeric(unidecode(username))
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - erreur : RemoveAllNonAlphaNumeric ")
|
||||
return False, str(
|
||||
inspect.stack()[0][3]) + " - erreur : RemoveAllNonAlphaNumeric ", False
|
||||
|
||||
# print(" ### username = ",username)
|
||||
registration_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
mysy_sequence_id = ""
|
||||
|
||||
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'lms_user_id', 'valide': '1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (retval is None or "current_val" not in retval.keys()):
|
||||
|
||||
# Il n'a pas de sequence pour ce partenaire, verifier s'il ya une sequence par defaut
|
||||
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'lms_user_id', 'valide': '1',
|
||||
'partner_owner_recid': "default"})
|
||||
|
||||
if (retval is None or "current_val" not in retval.keys()):
|
||||
mycommon.myprint(" Aucune séquence 'lms_user_id' n'est paramétré dans le système ")
|
||||
return False, " Aucune séquence 'lms_user_id' n'est paramétré dans le système ", False
|
||||
|
||||
# on stock l'id trouvé
|
||||
mysy_sequence_id = str(retval['_id'])
|
||||
|
||||
|
||||
new_lms_user_id = str(retval['prefixe']) + str(retval['current_val'])
|
||||
|
||||
|
||||
|
||||
local_status, local_val = mycommon.IsInt(new_lms_user_id)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" Impossible de generer l'ID du user LMS. La valeur actuelle est ", new_lms_user_id)
|
||||
return False, " Impossible de generer l'ID du user LMS", False
|
||||
|
||||
|
||||
current_seq_value = str(retval['current_val'])
|
||||
|
||||
mypasswd = password.encode('UTF-8')
|
||||
|
||||
salt = bcrypt.gensalt()
|
||||
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
|
||||
|
||||
if (type(salt) is bytes):
|
||||
salt = salt.decode("UTF-8")
|
||||
hashed_pwd = hashed_pwd.decode("UTF-8")
|
||||
|
||||
conn = mariadb.connect(
|
||||
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||
database=MYSY_GV.MYSY_LMS_BDD
|
||||
)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Verification d'abord si le compte exite.
|
||||
query_compte_exist = " Select count(*), user_id From user WHERE username = '" + username + "' "
|
||||
print(" ### query_compte_exist = ", query_compte_exist)
|
||||
query_compte_exist_exec = cur.execute(query_compte_exist)
|
||||
|
||||
|
||||
|
||||
query_compte_exist_exec = ""
|
||||
query_compte_exist_exec_val = "0"
|
||||
for query_compte_exist_exec in cur:
|
||||
query_compte_exist_exec_val = query_compte_exist_exec[0]
|
||||
if (int(mycommon.tryInt(query_compte_exist_exec_val)) > 0):
|
||||
new_lms_user_id = query_compte_exist_exec[1]
|
||||
conn.commit()
|
||||
|
||||
|
||||
if( int(mycommon.tryInt(query_compte_exist_exec_val)) > 0 ):
|
||||
# Le compte existe, il faut donc faire une mise à jour
|
||||
my_query = "UPDATE user SET salt = '" + str(salt) + "', credentials_expired='0', " \
|
||||
"updated_at='" + str(registration_date) + " ', " \
|
||||
"password = '" + str(
|
||||
hashed_pwd) + "', " \
|
||||
"enabled='1', " \
|
||||
"expired='0', " \
|
||||
"mysy_recid='"+str(diction['rh_partner_account_id'])+"', " \
|
||||
"mysy_partner_owner_recid='" + str(my_partner['recid']) + "', " \
|
||||
"mysy_partner_owner_lms_user_id='" + str( my_partner['mysy_lms_user_id']) + "', " \
|
||||
"locked = '0', " \
|
||||
"auth_source = 'platform'," \
|
||||
"roles = 'a:0:{}', " \
|
||||
"language = 'french'," \
|
||||
"username_canonical = '" + username + "', " \
|
||||
" email_canonical = '" + email + "', " \
|
||||
"email = '" + email + "'," \
|
||||
" official_code = '" + official_code + "', " \
|
||||
"active = '1' WHERE username='" + str(
|
||||
email) + "' ;"
|
||||
else:
|
||||
# Le compte n'existe pas, il faut le créer
|
||||
|
||||
|
||||
# insert information
|
||||
my_query = "INSERT INTO user SET id='"+str(new_lms_user_id)+"' , " \
|
||||
"user_id='"+str(new_lms_user_id)+"' , " \
|
||||
"lastname = '"+lastname+"', " \
|
||||
"firstname = '"+firstname+"', " \
|
||||
"username = '"+username+"', " \
|
||||
"mysy_recid='"+str(diction['rh_partner_account_id'])+"', " \
|
||||
"mysy_partner_owner_recid='" + str(my_partner['recid']) + "', " \
|
||||
"mysy_partner_owner_lms_user_id='" + str(
|
||||
my_partner['mysy_lms_user_id']) + "', " \
|
||||
" salt = '"+str(salt)+"'," \
|
||||
" registration_date = '"+registration_date+"'," \
|
||||
" credentials_expired='0', " \
|
||||
"enabled='1', " \
|
||||
"expired='0', " \
|
||||
"created_at='" + str( registration_date) + "'," \
|
||||
" updated_at='" + str( registration_date) + "', " \
|
||||
" status = '1', " \
|
||||
"password = '"+str(hashed_pwd)+"', " \
|
||||
"locked = '0', " \
|
||||
"username_canonical = '"+username+"', " \
|
||||
" email_canonical = '"+email+"', " \
|
||||
"email = '"+email+"'," \
|
||||
" official_code = '"+official_code+"', " \
|
||||
"creator_id = '1', " \
|
||||
"auth_source = 'platform'," \
|
||||
"roles = 'a:0:{}', " \
|
||||
"language = 'french'," \
|
||||
"active = '1';"
|
||||
|
||||
try:
|
||||
print(" ### my_query aaa = ", my_query)
|
||||
#cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||
cur.execute(my_query)
|
||||
except mariadb.Error as e:
|
||||
#print(f"Error: {e}")
|
||||
mycommon.myprint(" Impossible de créer l'enseignant LMS "+str({e}))
|
||||
return False, "Impossible de créer l'enseignant LMS "+str({e}), False
|
||||
|
||||
conn.commit()
|
||||
|
||||
lastrowid = cur.lastrowid
|
||||
|
||||
my_query_access_url_rel_user = "INSERT INTO access_url_rel_user SET access_url_id='" + str(lms_virtualhost_id) + "' , user_id='" + str(new_lms_user_id) + "' "
|
||||
print(" ### my_query_access_url_rel_user = ", my_query_access_url_rel_user)
|
||||
try:
|
||||
|
||||
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||
cur.execute(my_query_access_url_rel_user)
|
||||
except mariadb.Error as e:
|
||||
# print(f"Error: {e}")
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " WARNING - impossible d'ajouter le user '" + str(
|
||||
new_lms_user_id) + "' à la table access_url_rel_user pour la recheche et l'envoi des email")
|
||||
|
||||
conn.commit()
|
||||
|
||||
conn.close()
|
||||
# InCrementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||
|
||||
print(" ### current_seq_value = ", current_seq_value)
|
||||
new_sequence_value = int(mycommon.tryInt(current_seq_value)) + 1
|
||||
print(" ### new_sequence_value = ", new_sequence_value)
|
||||
|
||||
mydata = {'current_val': new_sequence_value}
|
||||
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update(
|
||||
{'_id':ObjectId(mysy_sequence_id)},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
return True, " Creation du compte Enseignant LMS OK. l'id = " + str(new_lms_user_id), str(new_lms_user_id)
|
||||
|
||||
|
||||
|
||||
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 le compte enseignant dans le LMS", False
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de desactivier le compte d'un utilisateur (enseignant ou
|
||||
apprenant) dans MySy-LMS
|
||||
"""
|
||||
def Disable_MySy_LMS_Account(diction):
|
||||
try:
|
||||
|
||||
'''
|
||||
# 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 = ['token', 'rh_id_to_disable']
|
||||
|
||||
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, " Le champ '" + val + "' n'est pas autorisé"
|
||||
|
||||
'''
|
||||
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', 'rh_id_to_disable']
|
||||
|
||||
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 obligatoire n'ont pas été fournies"
|
||||
|
||||
# recuperation des paramettre
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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, False
|
||||
|
||||
|
||||
is_valide_acount_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(diction['rh_id_to_disable'])),
|
||||
'valide':'1',
|
||||
'partner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_valide_acount_data is None):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du compte à désactiver est invalide ")
|
||||
return False, " L'identifiant du compte à désactiver est invalide "
|
||||
|
||||
account_partner_id = ""
|
||||
if( "account_partner_id" not in is_valide_acount_data.keys() ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du compte à désactiver est invalide (2) ")
|
||||
return False, " L'identifiant du compte à désactiver est invalide (2) "
|
||||
|
||||
account_to_disable_data = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(str(is_valide_acount_data['account_partner_id'])),
|
||||
'recid':str(my_partner['recid'])})
|
||||
|
||||
if( account_to_disable_data is None or "mysy_lms_user_id" not in account_to_disable_data.keys() ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du compte à désactiver est invalide (3) ")
|
||||
return False, " L'identifiant du compte à désactiver est invalide (3) "
|
||||
|
||||
conn = mariadb.connect(
|
||||
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||
database=MYSY_GV.MYSY_LMS_BDD
|
||||
)
|
||||
cur = conn.cursor()
|
||||
registration_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
my_query = "UPDATE user SET locked='1' , updated_at='" + str(registration_date) + " ', WHERE user_id='" + str(account_to_disable_data['mysy_lms_user_id']) + "' and mysy_partner_owner_recid = '"+ str(my_partner['recid']) +"' ;"
|
||||
|
||||
try:
|
||||
print(" ### my_query aaa = ", my_query)
|
||||
|
||||
cur.execute(my_query)
|
||||
except mariadb.Error as e:
|
||||
#print(f"Error: {e}")
|
||||
mycommon.myprint(" Impossible de créer l'enseignant LMS "+str({e}))
|
||||
return False, "Impossible de créer l'enseignant LMS "+str({e})
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
update_account = {}
|
||||
update_account['date_update'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
update_account['update_by'] = str(my_partner['_id'])
|
||||
update_account['lms_account_disable'] = "1"
|
||||
|
||||
# Mettre à jour le compte dans mysy-search pour dire que le compte lms est desactivé
|
||||
MYSY_GV.dbname['partnair_account'].find_one_and_update({'mysy_lms_user_id':str(account_to_disable_data['mysy_lms_user_id']),
|
||||
'recid':str(my_partner['recid'])},
|
||||
{'$set':update_account})
|
||||
|
||||
return True, " Le compte a été correctement désactivé"
|
||||
|
||||
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 désactiver le compte "
|
||||
|
|
23
main.py
23
main.py
|
@ -4875,8 +4875,31 @@ def Get_Type_Contrat_List():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour créer un compte enseignant dans le LMS
|
||||
"""
|
||||
@app.route('/myclass/api/HR_Create_LMS_Trainer_Account/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def HR_Create_LMS_Trainer_Account():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### HR_Create_LMS_Trainer_Account payload = ",payload)
|
||||
status, retval = ressources_humaines.HR_Create_LMS_Trainer_Account(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API qui desactive le compte LMS d'un employé, en parant du rh_id
|
||||
"""
|
||||
@app.route('/myclass/api/Disable_MySy_LMS_Account/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Disable_MySy_LMS_Account():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Disable_MySy_LMS_Account payload = ",payload)
|
||||
status, retval = mysy_lms.Disable_MySy_LMS_Account(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
|
55
partners.py
55
partners.py
|
@ -365,31 +365,12 @@ def update_partner_pwd(diction):
|
|||
if diction['token']:
|
||||
mytoken = diction['token']
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||
if( partner_recid is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
partner_account_id = ""
|
||||
if ("partner_account_id" in diction.keys()):
|
||||
partner_account_id = diction['partner_account_id']
|
||||
|
||||
# Verification de la validité du compte
|
||||
is_count_valide = MYSY_GV.dbname['partnair_account'].count_documents(
|
||||
{'_id': ObjectId(partner_account_id), 'active': '1', 'locked': '0',
|
||||
'recid': partner_recid})
|
||||
if (is_count_valide <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " est invalide")
|
||||
return False, " Le compte partner_account_id :" + str(partner_account_id) + " est invalide "
|
||||
|
||||
if (is_count_valide > 1):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs (" + str(is_count_valide) + ")")
|
||||
return False, " Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs "
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
partner_recid = my_partner['recid']
|
||||
|
||||
mypwd=""
|
||||
if ("pwd" in diction.keys()):
|
||||
|
@ -427,7 +408,7 @@ def update_partner_pwd(diction):
|
|||
coll_name = MYSY_GV.dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||||
{'_id':ObjectId(str(my_partner['_id'])), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||||
{"$set": mydata},
|
||||
upsert= False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
|
@ -439,19 +420,13 @@ def update_partner_pwd(diction):
|
|||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le mot de passe du partenaire recid= : " +str(partner_recid) )
|
||||
return False, " Impossible de mettre à jour le mot de passe du partenaire"
|
||||
return False, " Impossible de mettre à jour le mot de passe. Vérifiez les informations saisies"
|
||||
|
||||
"""
|
||||
pres la modification du mot de passe dans Mysy, il faut voir si le partenaire
|
||||
a un compte LMS. Si c'est le cas, alors il faut mettre à jour le mot de passe dans le compte LMS aussi.
|
||||
"""
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire"
|
||||
|
||||
|
||||
if ("mysy_lms_user_id" in my_partner.keys()):
|
||||
if my_partner['mysy_lms_user_id']:
|
||||
|
@ -1091,6 +1066,24 @@ def get_partner_account(diction):
|
|||
is_first_connexion = False
|
||||
|
||||
user = retVal
|
||||
|
||||
lms_virtualhost_url = ""
|
||||
if( "lms_virtualhost_url" in retVal.keys() ):
|
||||
lms_virtualhost_url = retVal['lms_virtualhost_url']
|
||||
user['lms_virtualhost_url'] = lms_virtualhost_url
|
||||
|
||||
lms_username = ""
|
||||
if ("lms_username" in retVal.keys()):
|
||||
lms_username = retVal['lms_username']
|
||||
user['lms_username'] = lms_username
|
||||
|
||||
mysy_lms_user_id = ""
|
||||
if ("mysy_lms_user_id" in retVal.keys()):
|
||||
mysy_lms_user_id = retVal['mysy_lms_user_id']
|
||||
user['mysy_lms_user_id'] = mysy_lms_user_id
|
||||
|
||||
|
||||
|
||||
RetObject.append(JSONEncoder().encode(user))
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import GlobalVariable as MYSY_GV
|
|||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import email_inscription_mgt as email_inscription_mgt
|
||||
import lms_chamilo.mysy_lms as mysy_lms
|
||||
"""
|
||||
Cette fonction crée le compte employé administrateur.
|
||||
Ceci est fait à l'activation du compte, donc à ce moment il n'y pas de token de connexion.
|
||||
|
@ -978,7 +979,8 @@ def Update_Ressource_Humaine(diction):
|
|||
|
||||
|
||||
"""
|
||||
Suppression d'une ressource humaine
|
||||
Suppression d'une ressource humaine.
|
||||
|
||||
"""
|
||||
|
||||
def Delete_Ressource_Humaine(diction):
|
||||
|
@ -1453,6 +1455,31 @@ def Get_List_Ressource_Humaine_with_filter(diction):
|
|||
else:
|
||||
user['telephone'] = ""
|
||||
|
||||
if ("adr_adresse" in New_retVal.keys()):
|
||||
user['adr_adresse'] = New_retVal['adr_adresse']
|
||||
else:
|
||||
user['adr_adresse'] = ""
|
||||
|
||||
if ("adr_code_postal" in New_retVal.keys()):
|
||||
user['adr_code_postal'] = New_retVal['adr_code_postal']
|
||||
else:
|
||||
user['adr_code_postal'] = ""
|
||||
|
||||
if ("adr_ville" in New_retVal.keys()):
|
||||
user['adr_ville'] = New_retVal['adr_ville']
|
||||
else:
|
||||
user['adr_ville'] = ""
|
||||
|
||||
if ("adr_pays" in New_retVal.keys()):
|
||||
user['adr_pays'] = New_retVal['adr_pays']
|
||||
else:
|
||||
user['adr_pays'] = ""
|
||||
|
||||
if ("date_naissance" in New_retVal.keys()):
|
||||
user['date_naissance'] = New_retVal['date_naissance']
|
||||
else:
|
||||
user['date_naissance'] = "01/01/1900"
|
||||
|
||||
if ("ismanager" in New_retVal.keys()):
|
||||
user['ismanager'] = New_retVal['ismanager']
|
||||
else:
|
||||
|
@ -1518,6 +1545,52 @@ def Get_List_Ressource_Humaine_with_filter(diction):
|
|||
for retval in MYSY_GV.dbname['ressource_humaine'].find(find_qry):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
|
||||
if ("prenom" in retval.keys()):
|
||||
user['prenom'] = retval['prenom']
|
||||
else:
|
||||
user['prenom'] = ""
|
||||
|
||||
if ("civilite" in retval.keys()):
|
||||
user['civilite'] = retval['civilite']
|
||||
else:
|
||||
user['civilite'] = ""
|
||||
|
||||
if ("telephone" in retval.keys()):
|
||||
user['telephone'] = retval['telephone']
|
||||
else:
|
||||
user['telephone'] = ""
|
||||
|
||||
if ("adr_adresse" in retval.keys()):
|
||||
user['adr_adresse'] = retval['adr_adresse']
|
||||
else:
|
||||
user['adr_adresse'] = ""
|
||||
|
||||
if ("adr_code_postal" in retval.keys()):
|
||||
user['adr_code_postal'] = retval['adr_code_postal']
|
||||
else:
|
||||
user['adr_code_postal'] = ""
|
||||
|
||||
if ("adr_ville" in retval.keys()):
|
||||
user['adr_ville'] = retval['adr_ville']
|
||||
else:
|
||||
user['adr_ville'] = ""
|
||||
|
||||
if ("adr_pays" in retval.keys()):
|
||||
user['adr_pays'] = retval['adr_pays']
|
||||
else:
|
||||
user['adr_pays'] = ""
|
||||
|
||||
if ("date_naissance" in retval.keys()):
|
||||
user['date_naissance'] = retval['date_naissance']
|
||||
else:
|
||||
user['date_naissance'] = "01/01/1900"
|
||||
|
||||
if ("ismanager" in retval.keys()):
|
||||
user['ismanager'] = retval['ismanager']
|
||||
else:
|
||||
user['ismanager'] = ""
|
||||
|
||||
val_tmp = val_tmp + 1
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
|
@ -1598,9 +1671,55 @@ def Get_List_Ressource_Humaine_no_filter(diction):
|
|||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
for retval in MYSY_GV.dbname['ressource_humaine'].find(find_qry):
|
||||
for retval in MYSY_GV.dbname['ressource_humaine'].find(find_qry).sort([("_id", pymongo.DESCENDING), ]):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
if ("prenom" in retval.keys()):
|
||||
user['prenom'] = retval['prenom']
|
||||
else:
|
||||
user['prenom'] = ""
|
||||
|
||||
if ("civilite" in retval.keys()):
|
||||
user['civilite'] = retval['civilite']
|
||||
else:
|
||||
user['civilite'] = ""
|
||||
|
||||
if ("telephone" in retval.keys()):
|
||||
user['telephone'] = retval['telephone']
|
||||
else:
|
||||
user['telephone'] = ""
|
||||
|
||||
if ("adr_adresse" in retval.keys()):
|
||||
user['adr_adresse'] = retval['adr_adresse']
|
||||
else:
|
||||
user['adr_adresse'] = ""
|
||||
|
||||
if ("adr_code_postal" in retval.keys()):
|
||||
user['adr_code_postal'] = retval['adr_code_postal']
|
||||
else:
|
||||
user['adr_code_postal'] = ""
|
||||
|
||||
if ("adr_ville" in retval.keys()):
|
||||
user['adr_ville'] = retval['adr_ville']
|
||||
else:
|
||||
user['adr_ville'] = ""
|
||||
|
||||
if ("adr_pays" in retval.keys()):
|
||||
user['adr_pays'] = retval['adr_pays']
|
||||
else:
|
||||
user['adr_pays'] = ""
|
||||
|
||||
if ("date_naissance" in retval.keys()):
|
||||
user['date_naissance'] = retval['date_naissance']
|
||||
else:
|
||||
user['date_naissance'] = "01/01/1900"
|
||||
|
||||
if ("ismanager" in retval.keys()):
|
||||
user['ismanager'] = retval['ismanager']
|
||||
else:
|
||||
user['ismanager'] = ""
|
||||
|
||||
|
||||
val_tmp = val_tmp + 1
|
||||
is_admin_account_count = MYSY_GV.dbname['partnair_account'].count_documents({'ressource_humaine_id':str(retval['_id']), 'is_partner_admin_account':'1'}) # exclure les comptes admin
|
||||
if( is_admin_account_count <= 0 ):
|
||||
|
@ -1726,6 +1845,35 @@ def Get_Given_Ressource_Humaine(diction):
|
|||
|
||||
user['groupe_prix_achat_code'] = groupe_prix_achat_code
|
||||
|
||||
# Recuperer les info necessaire sur le compte (login) de l'employe
|
||||
if( "account_partner_id" in retval.keys() and retval['account_partner_id']):
|
||||
|
||||
account_data = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(str(retval['account_partner_id'])),
|
||||
'recid':str(my_partner['recid'])
|
||||
}, {'lms_virtualhost_url':1, 'mysy_lms_user_id':1,
|
||||
'lms_username':1, 'lms_account_disable':1})
|
||||
|
||||
lms_virtualhost_url = ""
|
||||
if(account_data and "lms_virtualhost_url" in account_data.keys() ):
|
||||
lms_virtualhost_url = account_data['lms_virtualhost_url']
|
||||
user['lms_virtualhost_url'] = lms_virtualhost_url
|
||||
|
||||
mysy_lms_user_id = ""
|
||||
if (account_data and "mysy_lms_user_id" in account_data.keys()):
|
||||
mysy_lms_user_id = account_data['mysy_lms_user_id']
|
||||
user['mysy_lms_user_id'] = mysy_lms_user_id
|
||||
|
||||
lms_username = ""
|
||||
if (account_data and "lms_username" in account_data.keys()):
|
||||
lms_username = account_data['lms_username']
|
||||
user['lms_username'] = lms_username
|
||||
|
||||
lms_account_disable = ""
|
||||
if (account_data and "lms_account_disable" in account_data.keys()):
|
||||
lms_account_disable = account_data['lms_account_disable']
|
||||
user['lms_account_disable'] = lms_account_disable
|
||||
|
||||
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
|
@ -1736,7 +1884,7 @@ def Get_Given_Ressource_Humaine(diction):
|
|||
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 personne "
|
||||
return False, " Impossible de récupérer les données de la personne "
|
||||
|
||||
"""
|
||||
Cette fonction ajoute une image de profil d'un employé
|
||||
|
@ -3406,14 +3554,22 @@ def Add_Update_Employee_Login_Pass(diction):
|
|||
mydata['nb_formation'] = str(my_partner['nb_formation'])
|
||||
mydata['stripe_account_id'] = str(my_partner['stripe_account_id'])
|
||||
mydata['stripe_paymentmethod_id'] = str(my_partner['stripe_paymentmethod_id'])
|
||||
mydata['lms_username'] = str(my_partner['lms_username'])
|
||||
|
||||
mydata['lms_virtualhost_id'] = str(my_partner['lms_virtualhost_id'])
|
||||
mydata['mysy_lms_user_id'] = str(my_partner['mysy_lms_user_id'])
|
||||
|
||||
mydata['recid'] = str(my_partner['recid'])
|
||||
mydata['is_partner_admin_account'] = '0'
|
||||
mydata['ispending'] = '0'
|
||||
mydata['update_by'] = str(my_partner['_id'])
|
||||
|
||||
"""
|
||||
14/01/2024 : Update : Chaque enseignant a son propre compte
|
||||
utilisateur dans le LMS
|
||||
"""
|
||||
mydata['lms_username'] = ""
|
||||
mydata['mysy_lms_user_id'] = ""
|
||||
mydata['date_update'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
|
||||
|
||||
mydata['active'] = '1'
|
||||
mydata['locked'] = '0'
|
||||
|
@ -4316,3 +4472,154 @@ def Get_Type_Contrat_List(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer la liste des types de contrat"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction créé ou met à jour un compte enseignant dans le LMS
|
||||
"""
|
||||
def HR_Create_LMS_Trainer_Account(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'rh_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, " Les informations fournies sont incorrectes",
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'rh_id']
|
||||
|
||||
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, " 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
|
||||
|
||||
|
||||
# Verifier la valididé de l'employé enseignant
|
||||
is_rh_valide = MYSY_GV.dbname['ressource_humaine'].count_documents({'_id':ObjectId(str(diction['rh_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_recid':str(my_partner['recid']),
|
||||
'is_partner_admin_account':'0'})
|
||||
|
||||
|
||||
if( is_rh_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant de l'enseignant est invalide ")
|
||||
return False, " L'identifiant de l'enseignant est invalide ",
|
||||
|
||||
is_rh_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(diction['rh_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_recid':str(my_partner['recid']),
|
||||
'is_partner_admin_account':'0'})
|
||||
|
||||
if( "account_partner_id" not in is_rh_data.keys() ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Cet enseignant n'a pas de compte utilisateur ")
|
||||
return False, " Cet enseignant n'a pas de compte utilisateur ",
|
||||
|
||||
|
||||
|
||||
# Recuperation des info qui sont sur compte utilisation (partner_account liée eu RH account)
|
||||
rh_partner_account = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(str(is_rh_data['account_partner_id'])),
|
||||
'active':'1',
|
||||
'recid':str(my_partner['recid'])})
|
||||
|
||||
if( rh_partner_account is None ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Le compte utilisateur associé à l'enseignant est invalide ")
|
||||
return False, " Le compte utilisateur associé à l'enseignant est invalide ",
|
||||
|
||||
|
||||
mew_diction = {}
|
||||
mew_diction['token'] = diction['token']
|
||||
mew_diction['rh_partner_account_id'] = str(rh_partner_account['_id'])
|
||||
mew_diction['lastname'] = is_rh_data['nom']
|
||||
mew_diction['firstname'] = is_rh_data['prenom']
|
||||
mew_diction['email'] = is_rh_data['email']
|
||||
mew_diction['password'] = rh_partner_account['pwd']
|
||||
mew_diction['locked'] = "0"
|
||||
mew_diction['official_code'] = ""
|
||||
|
||||
split_mail_tab = str(is_rh_data['email']).split('@')
|
||||
local_status, username = mycommon.RemoveAllNonAlphaNumeric(split_mail_tab[0])
|
||||
if( local_status is False ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Impossible de créer le 'username' de l'enseignant dans le LMS ")
|
||||
return False, " Impossible de créer le 'username' de l'enseignant dans le LMS "
|
||||
|
||||
mew_diction['username'] = username
|
||||
|
||||
|
||||
local_status, local_retval, local_retval2 = mysy_lms.Create_MySy_LMS_Enseignant_Account(mew_diction)
|
||||
if(local_status is False ):
|
||||
return local_status, local_retval
|
||||
|
||||
new_lms_user_id = local_retval2
|
||||
|
||||
print(" # le compte enseignant a été créé dans le lms avec le new_lms_user_id = ", new_lms_user_id)
|
||||
|
||||
"""
|
||||
### Mettre à jour le compte enseignant avec les data :
|
||||
new_lms_user_id,
|
||||
lms_username
|
||||
lms_theme_name
|
||||
lms_virtualhost_url
|
||||
lms_virtualhost_id
|
||||
"""
|
||||
qry = { 'new_lms_user_id':str(new_lms_user_id),
|
||||
'lms_username':str(username),
|
||||
'lms_theme_name':str(my_partner['lms_theme_name']),
|
||||
'lms_virtualhost_url': str(my_partner['lms_virtualhost_url']),
|
||||
'lms_virtualhost_id': str(my_partner['lms_virtualhost_id']),
|
||||
}
|
||||
|
||||
print(" #### qry meee = ", qry)
|
||||
MYSY_GV.dbname['partnair_account'].update_one({'_id':ObjectId(str(is_rh_data['account_partner_id'])),
|
||||
'active':'1',
|
||||
'recid':str(my_partner['recid'])},
|
||||
{'$set':
|
||||
{
|
||||
'mysy_lms_user_id':str(new_lms_user_id),
|
||||
'lms_username':str(username),
|
||||
'lms_theme_name':str(my_partner['lms_theme_name']),
|
||||
'lms_virtualhost_url': str(my_partner['lms_virtualhost_url']),
|
||||
'lms_virtualhost_id': str(my_partner['lms_virtualhost_id']),
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
return True, " Les acceès ont été créée dans le LMS"
|
||||
|
||||
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 acces LMS "
|
||||
|
|
Loading…
Reference in New Issue