3101 lines
129 KiB
Python
3101 lines
129 KiB
Python
'''
|
||
|
||
Ce fichier definit la gestion des partners - client.
|
||
exemple :
|
||
- creation et modification des compte client
|
||
- connexion pour l'obtention d'un token
|
||
- creation d'une api d'ajout/mise d'une formation
|
||
- creation d'une api de desactivation d'une formation
|
||
|
||
'''
|
||
import ast
|
||
|
||
from pymongo import MongoClient
|
||
import pymongo
|
||
import json
|
||
from flask import Flask, request, jsonify
|
||
#from flask_mongoengine import MongoEngine
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
import numpy as np
|
||
|
||
import Activite
|
||
import ela_index_bdd_classes as ela_index
|
||
import email_mgt as mail
|
||
from datetime import datetime
|
||
import logging
|
||
import prj_common as mycommon
|
||
import secrets
|
||
import inspect
|
||
import sys, os
|
||
from pymongo import ReturnDocument
|
||
from datetime import datetime
|
||
import GlobalVariable as MYSY_GV
|
||
import strype_payement as Stripe
|
||
import lms_chamilo.mysy_lms as mysy_lms
|
||
import ressources_humaines as ressources_humaines
|
||
import module_editique as module_editique
|
||
|
||
class JSONEncoder(json.JSONEncoder):
|
||
def default(self, o):
|
||
if isinstance(o, ObjectId):
|
||
return str(o)
|
||
return json.JSONEncoder.default(self, o)
|
||
|
||
|
||
'''
|
||
Ajout d'un partenaire
|
||
'''
|
||
def add_partner_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 = ['nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country','link_linkedin','link_facebook','link_twitter',
|
||
'email','pwd', 'telephone','contact_nom','contact_prenom','contact_tel','contact_mail', 'pack_service',
|
||
'subdomaine_catalog_pub']
|
||
|
||
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, "Impossible de créer le partenaire. Toutes les informations fournies ne sont pas valables"
|
||
|
||
'''
|
||
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 = ['nom', 'email','pwd', 'telephone','contact_nom','contact_prenom','contact_tel','contact_mail']
|
||
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, "Impossible de créer le partenaire, Toutes les informations necessaires n'ont pas été fournies"
|
||
|
||
# recuperation des paramettre
|
||
mydata = {}
|
||
|
||
mydata['invoice_vat_num'] = ""
|
||
mydata['invoice_taux_vat'] = "20"
|
||
|
||
if ("nom" in diction.keys()):
|
||
if diction['nom']:
|
||
mydata['nom'] = diction['nom']
|
||
mydata['invoice_nom'] = diction['nom']
|
||
|
||
|
||
if ("subdomaine_catalog_pub" in diction.keys()):
|
||
mydata['subdomaine_catalog_pub'] = diction['subdomaine_catalog_pub']
|
||
|
||
|
||
|
||
if ("adr_street" in diction.keys()):
|
||
if diction['adr_street']:
|
||
mydata['adr_street'] = diction['adr_street']
|
||
mydata['invoice_adr_street'] = diction['adr_street']
|
||
|
||
if ("adr_city" in diction.keys()):
|
||
if diction['adr_city']:
|
||
mydata['adr_city'] = diction['adr_city']
|
||
mydata['invoice_adr_city'] = diction['adr_city']
|
||
|
||
if ("adr_zip" in diction.keys()):
|
||
if diction['adr_zip']:
|
||
mydata['adr_zip'] = diction['adr_zip']
|
||
mydata['invoice_adr_zip'] = diction['adr_zip']
|
||
|
||
if ("adr_country" in diction.keys()):
|
||
if diction['adr_country']:
|
||
mydata['adr_country'] = diction['adr_country']
|
||
mydata['invoice_adr_country'] = diction['adr_country']
|
||
|
||
if ("email" in diction.keys()):
|
||
if diction['email']:
|
||
mydata['email'] = diction['email']
|
||
mydata['invoice_email'] = diction['email']
|
||
if (mycommon.isEmailValide(diction['email']) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'adresse email " + str(diction['email']) + " n'est pas valide")
|
||
|
||
return False, " L'adresse email " + str(diction['email']) + " n'est pas valide "
|
||
|
||
|
||
if ("telephone" in diction.keys()):
|
||
if diction['telephone']:
|
||
mydata['telephone'] = diction['telephone']
|
||
mydata['invoice_telephone'] = diction['telephone']
|
||
|
||
if ("pwd" in diction.keys()):
|
||
if diction['pwd']:
|
||
mydata['pwd'] = diction['pwd']
|
||
|
||
if ("contact_nom" in diction.keys()):
|
||
if diction['contact_nom']:
|
||
mydata['contact_nom'] = diction['contact_nom']
|
||
|
||
if ("contact_prenom" in diction.keys()):
|
||
if diction['contact_prenom']:
|
||
mydata['contact_prenom'] = diction['contact_prenom']
|
||
|
||
if ("contact_tel" in diction.keys()):
|
||
if diction['contact_tel']:
|
||
mydata['contact_tel'] = diction['contact_tel']
|
||
|
||
if ("contact_mail" in diction.keys()):
|
||
if diction['contact_mail']:
|
||
mydata['contact_mail'] = diction['contact_mail']
|
||
|
||
|
||
if ("link_linkedin" in diction.keys()):
|
||
if diction['link_linkedin']:
|
||
mydata['link_linkedin'] = diction['link_linkedin']
|
||
|
||
if ("link_facebook" in diction.keys()):
|
||
if diction['link_facebook']:
|
||
mydata['link_facebook'] = diction['link_facebook']
|
||
|
||
if ("link_twitter" in diction.keys()):
|
||
if diction['link_twitter']:
|
||
mydata['link_twitter'] = diction['link_twitter']
|
||
|
||
if ("pack_service" in diction.keys()):
|
||
if diction['pack_service']:
|
||
mydata['pack_service'] = diction['pack_service']
|
||
|
||
|
||
# Creation du RecId du user
|
||
mydata['recid'] = mycommon.create_user_recid()
|
||
|
||
# Creation de la clé d'insertion
|
||
mydata['insert_key'] = mycommon.create_user_recid()
|
||
|
||
# Creation des champs pour VIDE pour stripe
|
||
mydata['stripe_account_id'] = ""
|
||
mydata['stripe_paymentmethod_id'] = ""
|
||
|
||
mydata['active'] = '0'
|
||
mydata['locked'] = '0'
|
||
mydata['ispending'] = "0"
|
||
|
||
# 12/04/205 :
|
||
mydata['firstconnexion'] = '1'
|
||
mydata['is_partner_admin_account'] = '1'
|
||
|
||
# 20/12/2025 - Par defaut, on le met en formation initiale pour voir toutes les fonctionalité
|
||
mydata['formation_initiale'] = '1'
|
||
|
||
#print(str(datetime.now()) + " webservice : diction = "+str(mydata))
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
coll_name_user_account = MYSY_GV.dbname['user_account']
|
||
|
||
# Verification que cette adresse email n'existe pas. Ceci que soit entant que user ou entant que partner
|
||
#tmp = coll_name.find({'email': str(mydata['email']) }).count()
|
||
tmp = coll_name.count_documents({'email': str(mydata['email']), 'active':'1' })
|
||
|
||
#logging.info(" TMP = "+str(tmp))
|
||
if( tmp > 0 ):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - l'adresse email '"+str(mydata['email'])+"' existe deja, impossible de créer le compte partenaire ")
|
||
return False, "l'adresse email '"+str(mydata['email'])+"' est deja utilisée, impossible de créer le compte partenaire "
|
||
|
||
tmp = coll_name_user_account.count_documents({'email': str(mydata['email']), 'active':'1'})
|
||
logging.info(" TMP = " + str(tmp))
|
||
if (tmp > 0):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - l'adresse email '" + str(
|
||
mydata['email']) + "' existe deja (utilisé comme compte user), impossible de créer le compte partenaire ")
|
||
return False, "l'adresse email '" + str(
|
||
mydata['email']) + "' est deja utilisée, impossible de créer le compte partenaire "
|
||
|
||
print(" ### create compt mydata = ", mydata)
|
||
|
||
ret_val = coll_name.insert_one(mydata)
|
||
mail.send_partner_account_mail(ret_val.inserted_id, str(mydata['email']))
|
||
return True, "Le compte utilisateur a été correctement créé. Vous allez recevoir un email avec les informations de connexion."
|
||
|
||
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 créer le compte utilisateur"
|
||
|
||
|
||
|
||
'''
|
||
partner Securité :
|
||
Cette fonction met à jour l'adresse email du partenaire
|
||
'''
|
||
def update_partner_main_mail(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 = ['token', 'mail', 'new_mail', 'conf_new_mail', '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, " Creation partner account : Le champ '" + val + "' n'est pas accepté "
|
||
|
||
'''
|
||
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', 'mail', 'new_mail', 'conf_new_mail']
|
||
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
||
|
||
# Recuperation du recid du partner
|
||
mydata = {}
|
||
mytoken = ""
|
||
if ("token" in diction.keys()):
|
||
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 :" + 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 : " + str(
|
||
partner_account_id) + " correspond à plusieurs utilisateurs. Veuillez contacter votre administrateur pour résoudre le problème. "
|
||
|
||
|
||
|
||
mymail=""
|
||
if ("mail" in diction.keys()):
|
||
if diction['mail']:
|
||
mymail = diction['mail']
|
||
|
||
|
||
newmail = ""
|
||
if ("new_mail" in diction.keys()):
|
||
if diction['new_mail']:
|
||
newmail = diction['new_mail']
|
||
mydata['email'] = diction['new_mail']
|
||
|
||
|
||
confnewmail = ""
|
||
if ("conf_new_mail" in diction.keys()):
|
||
if diction['conf_new_mail']:
|
||
confnewmail = diction['conf_new_mail']
|
||
|
||
|
||
if ( len(newmail) <= 0 ):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - le nouvel email est vide")
|
||
return False, " Impossible de mettre à jour l'adresse email du partenaire "
|
||
|
||
if( str(newmail) != str(confnewmail)) :
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Les emails ne sont pas identiques")
|
||
return False, " Les emails ne sont pas identiques"
|
||
|
||
|
||
mydata['update_date'] = str(datetime.now())
|
||
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
ret_val = coll_name.find_one_and_update(
|
||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'email':mymail},
|
||
{"$set": mydata},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
|
||
if (ret_val and ret_val['_id']):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + "L'adresse mail du partenaire a bien ete mis à jour =" + str(ret_val['_id']))
|
||
return True, "Adresse e-mail du compte mise à jour avec succès."
|
||
else:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour l'adresse mail du partenaire recid= : " +str(partner_recid) )
|
||
return False, " Impossible de mettre à jour l'adresse mail du compte"
|
||
|
||
|
||
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 l'adresse mail du compte"
|
||
|
||
|
||
|
||
|
||
|
||
'''
|
||
partner Securité :
|
||
Cette fonction met à jour le mot de passe du partenaire
|
||
'''
|
||
def update_partner_pwd(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 = ['token', 'pwd', 'new_pwd', 'conf_new_pwd', '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 accepté "
|
||
|
||
'''
|
||
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']
|
||
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
||
|
||
# Recuperation du recid du partner
|
||
mydata = {}
|
||
mytoken = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
mytoken = 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
|
||
|
||
print(" ### update_partner_pwd my_partner = ", my_partner)
|
||
|
||
partner_recid = my_partner['recid']
|
||
|
||
mypwd=""
|
||
if ("pwd" in diction.keys()):
|
||
if diction['pwd']:
|
||
mypwd = diction['pwd']
|
||
|
||
|
||
newpwd = ""
|
||
if ("new_pwd" in diction.keys()):
|
||
if diction['new_pwd']:
|
||
newpwd = diction['new_pwd']
|
||
mydata['pwd'] = diction['new_pwd']
|
||
|
||
|
||
confnewpwd = ""
|
||
if ("conf_new_pwd" in diction.keys()):
|
||
if diction['conf_new_pwd']:
|
||
confnewpwd = diction['conf_new_pwd']
|
||
|
||
|
||
if ( len(newpwd) <= 0 ):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - le nouveau mot de passe est vide")
|
||
return False, " Impossible de mettre à jour le mot de passe "
|
||
|
||
if( str(newpwd) != str(confnewpwd)) :
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Les mots de passe ne sont pas identiques")
|
||
return False, " Les mots de passe ne sont pas identiques "
|
||
|
||
|
||
mydata['update_date'] = str(datetime.now())
|
||
|
||
#print(" ### QRY for update_partner_pwd ", {'_id':ObjectId(str(my_partner['_id'])), 'locked': '0', 'active': '1', 'pwd':mypwd})
|
||
|
||
#print(" ### update_partner_pwd ", mydata)
|
||
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
ret_val = coll_name.find_one_and_update(
|
||
{'_id':ObjectId(str(my_partner['_id'])), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||
{"$set": mydata},
|
||
upsert= False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
|
||
if (ret_val and ret_val['_id']):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " Le mot de passe du partenaire a bien ete mis à jour dans Mysy =" + str(ret_val['_id']))
|
||
|
||
else:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le mot de passe du partenaire recid= : " +str(partner_recid) )
|
||
return False, " Le mot de passe n’a pas pu être mis à jour. Merci de vérifier les informations renseignées et de réessayer.s"
|
||
|
||
"""
|
||
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.
|
||
"""
|
||
|
||
print("### my_partner = ", my_partner)
|
||
|
||
|
||
if ("mysy_lms_user_id" in my_partner.keys()):
|
||
print(" ### update my_partner = ", my_partner)
|
||
if my_partner['mysy_lms_user_id']:
|
||
|
||
new_diction = {}
|
||
new_diction['token'] = my_partner['token']
|
||
new_diction['new_password'] = confnewpwd
|
||
new_diction['lms_user_id'] = my_partner['mysy_lms_user_id']
|
||
|
||
local_status, message, rowid = mysy_lms.Update_Passwd_MySy_LMS_User(new_diction)
|
||
if( local_status is False ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - WARNING : impossible de mettre le mot de passe à jour dans le LMS")
|
||
else:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " - La mise à jour du mot de passe dans le LMS a été faite également ")
|
||
|
||
|
||
return True, " Mot de passe mis à jour avec succès."
|
||
|
||
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, "Le mot de passe n’a pas pu être mis à jour. Merci de vérifier les informations renseignées et de réessayer."
|
||
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction permet de mettre à jour la clé d'insertion.
|
||
Cette clé est utilisée pour permettre de rattacher une collaborateur à une entreprise
|
||
"""
|
||
def update_partner_insert_key(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 = ['token', 'current_insert_key', 'new_insert_key', 'conf_insert_key', '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 accepté "
|
||
|
||
'''
|
||
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', 'current_insert_key', 'new_insert_key', 'conf_insert_key']
|
||
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
||
|
||
# Recuperation du recid du partner
|
||
mydata = {}
|
||
mytoken = ""
|
||
if ("token" in diction.keys()):
|
||
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 la clé d'insertion "
|
||
|
||
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 "
|
||
|
||
is_partner_admin_account = "0"
|
||
if ("is_partner_admin_account" in diction.keys()):
|
||
partner_account_id = diction['is_partner_admin_account']
|
||
|
||
mykey=""
|
||
if ("current_insert_key" in diction.keys()):
|
||
if diction['current_insert_key']:
|
||
mykey = diction['current_insert_key']
|
||
|
||
|
||
newkey = ""
|
||
if ("new_insert_key" in diction.keys()):
|
||
if diction['new_insert_key']:
|
||
newkey = diction['new_insert_key']
|
||
mydata['insert_key'] = diction['new_insert_key']
|
||
|
||
|
||
confkey = ""
|
||
if ("conf_insert_key" in diction.keys()):
|
||
if diction['conf_insert_key']:
|
||
confkey = diction['conf_insert_key']
|
||
|
||
|
||
if ( len(newkey) <= 0 ):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - la nouvelle clé d'insertion est vide")
|
||
return False, " Impossible de mettre à jour la clé d'insertion "
|
||
|
||
if( str(newkey) != str(confkey)) :
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - La nouvelle clé et la confirmation ne sont pas identiques")
|
||
return False, "La nouvelle clé et la confirmation ne sont pas identiques"
|
||
|
||
|
||
mydata['update_date'] = str(datetime.now())
|
||
|
||
#print(mydata)
|
||
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
ret_val = coll_name.find_one_and_update(
|
||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'insert_key':mykey},
|
||
{"$set": mydata},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
|
||
if (ret_val and ret_val['_id']):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + "La clé d'insertion du partenaire a bien ete mise à jour =" + str(ret_val['_id']))
|
||
return True, "La clé d'insertion a bien été mise à jour"
|
||
else:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la clé d'insertion du partenaire recid= : " +str(partner_recid) )
|
||
return False, " Impossible de mettre à jour la clé d'insertion"
|
||
|
||
|
||
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 la clé d'insertion "
|
||
|
||
|
||
|
||
'''
|
||
MAJ d'un partenaire.
|
||
la clé est l'adresse email principale
|
||
'''
|
||
def update_partner_account(file_logo=None, file_cachet=None, Folder=None, diction=None):
|
||
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 = ['nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country', 'link_linkedin',
|
||
'email', 'pwd', 'telephone', 'contact_nom', 'contact_prenom', 'contact_tel',
|
||
'contact_mail', 'token', 'link_facebook', 'link_twitter', 'invoice_vat_num',
|
||
'invoice_nom', 'invoice_adr_street', 'invoice_adr_city', 'invoice_adr_zip',
|
||
'invoice_adr_country', 'invoice_email', 'invoice_telephone',
|
||
'siret', 'num_nda', 'iscertitrace', 'isdatadock', 'isqualiopi', 'website',
|
||
'isbureaucertitrace', 'iscertifvoltaire', 'file_logo_recid', 'file_cachet_recid',
|
||
'partner_account_id', 'invoice_taux_vat', 'subdomaine_catalog_pub', ]
|
||
|
||
|
||
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 accepté "
|
||
|
||
'''
|
||
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']
|
||
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
||
|
||
# recuperation des paramettre
|
||
my_email = ""
|
||
my_token = ""
|
||
|
||
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
my_token = diction['token']
|
||
|
||
|
||
# Verifier la validité du token
|
||
retval = mycommon.check_partner_token_validity("", my_token)
|
||
|
||
if retval is False :
|
||
return False, " La session de connexion n'est pas valide"
|
||
# Recuperation du recid de l'utilisateur
|
||
|
||
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
||
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 "
|
||
|
||
|
||
is_partner_admin_account = "0"
|
||
if ("is_partner_admin_account" in diction.keys()):
|
||
partner_account_id = diction['is_partner_admin_account']
|
||
|
||
|
||
#print(" #### partner_account_id = ", partner_account_id)
|
||
|
||
mydata = {}
|
||
if ("nom" in diction.keys()):
|
||
mydata['nom'] = diction['nom']
|
||
|
||
if ("subdomaine_catalog_pub" in diction.keys()):
|
||
mydata['subdomaine_catalog_pub'] = diction['subdomaine_catalog_pub']
|
||
|
||
|
||
if ("adr_street" in diction.keys()):
|
||
mydata['adr_street'] = diction['adr_street']
|
||
|
||
if ("adr_city" in diction.keys()):
|
||
mydata['adr_city'] = diction['adr_city']
|
||
|
||
if ("adr_zip" in diction.keys()):
|
||
mydata['adr_zip'] = diction['adr_zip']
|
||
|
||
if ("adr_country" in diction.keys()):
|
||
mydata['adr_country'] = diction['adr_country']
|
||
|
||
if ("siret" in diction.keys()):
|
||
mydata['siret'] = diction['siret']
|
||
|
||
if ("num_nda" in diction.keys()):
|
||
mydata['num_nda'] = diction['num_nda']
|
||
|
||
if ("iscertitrace" in diction.keys()):
|
||
mydata['iscertitrace'] = diction['iscertitrace']
|
||
|
||
if ("isbureaucertitrace" in diction.keys()):
|
||
mydata['isbureaucertitrace'] = diction['isbureaucertitrace']
|
||
|
||
if ("iscertifvoltaire" in diction.keys()):
|
||
mydata['iscertifvoltaire'] = diction['iscertifvoltaire']
|
||
|
||
if ("isdatadock" in diction.keys()):
|
||
mydata['isdatadock'] = diction['isdatadock']
|
||
|
||
if ("isqualiopi" in diction.keys()):
|
||
mydata['isqualiopi'] = diction['isqualiopi']
|
||
|
||
if ("website" in diction.keys()):
|
||
mydata['website'] = diction['website']
|
||
|
||
if ("email" in diction.keys()):
|
||
my_email = diction['email']
|
||
|
||
if ("telephone" in diction.keys()):
|
||
mydata['telephone'] = diction['telephone']
|
||
|
||
if ("pwd" in diction.keys()):
|
||
mydata['pwd'] = diction['pwd']
|
||
|
||
if ("contact_nom" in diction.keys()):
|
||
mydata['contact_nom'] = diction['contact_nom']
|
||
|
||
if ("contact_prenom" in diction.keys()):
|
||
mydata['contact_prenom'] = diction['contact_prenom']
|
||
|
||
if ("contact_tel" in diction.keys()):
|
||
mydata['contact_tel'] = diction['contact_tel']
|
||
|
||
if ("contact_mail" in diction.keys()):
|
||
mydata['contact_mail'] = diction['contact_mail']
|
||
|
||
|
||
|
||
if ("link_linkedin" in diction.keys()):
|
||
mydata['link_linkedin'] = diction['link_linkedin']
|
||
|
||
if ("link_facebook" in diction.keys()):
|
||
mydata['link_facebook'] = diction['link_facebook']
|
||
|
||
if ("link_twitter" in diction.keys()):
|
||
mydata['link_twitter'] = diction['link_twitter']
|
||
|
||
if ("invoice_vat_num" in diction.keys()):
|
||
mydata['invoice_vat_num'] = diction['invoice_vat_num']
|
||
|
||
if ("invoice_taux_vat" in diction.keys()):
|
||
mydata['invoice_taux_vat'] = diction['invoice_taux_vat']
|
||
|
||
if ("invoice_nom" in diction.keys()):
|
||
mydata['invoice_nom'] = diction['invoice_nom']
|
||
|
||
if ("invoice_adr_street" in diction.keys()):
|
||
mydata['invoice_adr_street'] = diction['invoice_adr_street']
|
||
|
||
if ("invoice_adr_city" in diction.keys()):
|
||
mydata['invoice_adr_city'] = diction['invoice_adr_city']
|
||
|
||
if ("invoice_adr_zip" in diction.keys()):
|
||
mydata['invoice_adr_zip'] = diction['invoice_adr_zip']
|
||
|
||
if ("invoice_adr_zip" in diction.keys()):
|
||
mydata['invoice_adr_country'] = diction['invoice_adr_country']
|
||
|
||
if ("invoice_email" in diction.keys()):
|
||
mydata['invoice_email'] = diction['invoice_email']
|
||
|
||
if ("invoice_telephone" in diction.keys()):
|
||
mydata['invoice_telephone'] = diction['invoice_telephone']
|
||
|
||
mydata['update_date'] = str(datetime.now())
|
||
|
||
#print(str(datetime.now()) + " webservice : diction = " + str(mydata))
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
"""
|
||
Si le compte partenaire n'as pas de compte de payement stripe, alors on profite de cette mise à jour pour le faire
|
||
"""
|
||
tmp = coll_name.find({'_id':ObjectId(partner_account_id), 'active':'1', 'locked':'0',
|
||
'recid':partner_recid})
|
||
|
||
is_admin_account = "0"
|
||
if( "is_partner_admin_account" in tmp[0].keys()):
|
||
is_admin_account = tmp[0]['is_partner_admin_account']
|
||
|
||
if( is_admin_account == "1"):
|
||
partnair_stripe_id = ""
|
||
if ("stripe_account_id" in tmp[0].keys()):
|
||
if tmp[0]['stripe_account_id']:
|
||
partnair_stripe_id = tmp[0]['stripe_account_id']
|
||
|
||
if ( partnair_stripe_id is None or len(partnair_stripe_id) < 5):
|
||
print('### le partenaire = ' + str(tmp[0]['nom']) + " n'as pas de compte Stripe. on va le créer")
|
||
"""
|
||
Creation du compte de payement Stripe
|
||
"""
|
||
|
||
my_stripe_data = {}
|
||
my_stripe_data['email'] = str(tmp[0]['email'])
|
||
my_stripe_data['name'] = str(tmp[0]['nom'])
|
||
|
||
my_stripe_data['city'] = ""
|
||
if ("adr_city" in tmp[0].keys()):
|
||
if tmp[0]['adr_city']:
|
||
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
||
|
||
my_stripe_data['country'] = ""
|
||
if ("adr_country" in tmp[0].keys()):
|
||
if tmp[0]['adr_country']:
|
||
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
||
|
||
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
||
mydata['stripe_account_id'] = part_stripe_account_id
|
||
mydata['stripe_paymentmethod_id'] = ""
|
||
|
||
if (local_status is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client " + str(
|
||
tmp[0]['nom']))
|
||
|
||
|
||
|
||
ret_val = coll_name.find_one_and_update(
|
||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1'},
|
||
{"$set": mydata},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if( ret_val is None or '_id' not in ret_val.keys()):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le partenaire recid= : " + str(
|
||
partner_recid))
|
||
return False, " Impossible de mettre à jour le partenaire"
|
||
|
||
|
||
"""
|
||
A present que le partenaire est mis à jour / créé, on va mettre à jour les image logo et image cachet s'il y en a.
|
||
Mais seulement pour les comptes admin
|
||
"""
|
||
|
||
if( is_admin_account == "1" and file_logo ):
|
||
recordimage_diction = {}
|
||
recordimage_diction['token'] = diction['token']
|
||
recordimage_diction['related_collection'] = "partnair_account"
|
||
recordimage_diction['type_img'] = "logo"
|
||
recordimage_diction['related_collection_recid'] = str(partner_recid)
|
||
recordimage_diction['image_recid'] = diction['file_logo_recid']
|
||
#print(" ### recordimage_diction 1 = ", recordimage_diction)
|
||
local_status, local_message = mycommon.recordClassImage_v2(file_logo, MYSY_GV.upload_folder, recordimage_diction)
|
||
if( local_status is False):
|
||
return local_status, local_message
|
||
|
||
if( is_admin_account == "1" and file_cachet ):
|
||
recordimage_diction = {}
|
||
recordimage_diction['token'] = diction['token']
|
||
recordimage_diction['related_collection'] = "partnair_account"
|
||
recordimage_diction['type_img'] = "cachet"
|
||
recordimage_diction['related_collection_recid'] = str(partner_recid)
|
||
recordimage_diction['image_recid'] = diction['file_cachet_recid']
|
||
#print(" ### recordimage_diction 2 = ", recordimage_diction)
|
||
local_status, local_message = mycommon.recordClassImage_v2(file_cachet, MYSY_GV.upload_folder, recordimage_diction)
|
||
if (local_status is False):
|
||
return local_status, local_message
|
||
|
||
|
||
"""
|
||
Update du 28/09/2023 :
|
||
On verifie le compte a un 'ressource_humaine_id', si ce n'est pas le cas,
|
||
cela veut dire le compte RH associé au compte admin n'a pas été crée.
|
||
Il faut donc le faire.
|
||
|
||
"""
|
||
is_valide_rh_compte = False
|
||
Parnter_Data = MYSY_GV.dbname['partnair_account'].find_one( {'recid': str(partner_recid), 'locked': '0', 'active': '1'},)
|
||
if( "ressource_humaine_id" in Parnter_Data.keys() ):
|
||
if(len(str(Parnter_Data['ressource_humaine_id'])) > 2 ):
|
||
is_valide_rh_compte = True
|
||
|
||
|
||
if( is_valide_rh_compte is False):
|
||
data_employe_admin = {}
|
||
data_employe_admin['partner_recid'] = str(Parnter_Data['recid'])
|
||
data_employe_admin['nom'] = str(Parnter_Data['nom'])
|
||
data_employe_admin['email'] = str(Parnter_Data['email'])
|
||
data_employe_admin['comment'] = "Compte Administrateur"
|
||
data_employe_admin['is_partner_admin_account'] = "1"
|
||
data_employe_admin['account_partner_id'] = str(Parnter_Data['_id'])
|
||
|
||
print(" #### data_employe_admin = ", str(data_employe_admin))
|
||
local_status, local_retval_inserted_id = ressources_humaines.Add_Partner_Admin_Ressource_Humaine_No_Toke(
|
||
data_employe_admin)
|
||
|
||
|
||
|
||
return True, "Le partenaire a bien ete mise à 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 partenaire"
|
||
|
||
|
||
'''
|
||
MAJ d'un partenaire.
|
||
la clé est l'adresse email principale
|
||
'''
|
||
|
||
|
||
def update_partner_account_employee_account(diction=None):
|
||
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 = ['contact_nom', 'contact_prenom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country', 'link_linkedin',
|
||
'email', 'pwd', 'telephone', 'token', 'link_facebook', 'link_twitter',
|
||
'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 accepté "
|
||
|
||
'''
|
||
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']
|
||
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
||
|
||
# recuperation des paramettre
|
||
my_email = ""
|
||
my_token = ""
|
||
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
my_token = diction['token']
|
||
|
||
# Verifier la validité du token
|
||
retval = mycommon.check_partner_token_validity("", my_token)
|
||
|
||
if retval is False:
|
||
return False, " La session de connexion n'est pas valide"
|
||
# Recuperation du recid de l'utilisateur
|
||
|
||
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
||
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 "
|
||
|
||
is_partner_admin_account = "0"
|
||
if ("is_partner_admin_account" in diction.keys()):
|
||
partner_account_id = diction['is_partner_admin_account']
|
||
|
||
# print(" #### partner_account_id = ", partner_account_id)
|
||
|
||
mydata = {}
|
||
if ("nom" in diction.keys()):
|
||
mydata['nom'] = diction['nom']
|
||
|
||
if ("subdomaine_catalog_pub" in diction.keys()):
|
||
mydata['subdomaine_catalog_pub'] = diction['subdomaine_catalog_pub']
|
||
|
||
if ("adr_street" in diction.keys()):
|
||
mydata['adr_street'] = diction['adr_street']
|
||
|
||
if ("adr_city" in diction.keys()):
|
||
mydata['adr_city'] = diction['adr_city']
|
||
|
||
if ("adr_zip" in diction.keys()):
|
||
mydata['adr_zip'] = diction['adr_zip']
|
||
|
||
if ("adr_country" in diction.keys()):
|
||
mydata['adr_country'] = diction['adr_country']
|
||
|
||
if ("siret" in diction.keys()):
|
||
mydata['siret'] = diction['siret']
|
||
|
||
if ("num_nda" in diction.keys()):
|
||
mydata['num_nda'] = diction['num_nda']
|
||
|
||
if ("iscertitrace" in diction.keys()):
|
||
mydata['iscertitrace'] = diction['iscertitrace']
|
||
|
||
if ("isbureaucertitrace" in diction.keys()):
|
||
mydata['isbureaucertitrace'] = diction['isbureaucertitrace']
|
||
|
||
if ("iscertifvoltaire" in diction.keys()):
|
||
mydata['iscertifvoltaire'] = diction['iscertifvoltaire']
|
||
|
||
if ("isdatadock" in diction.keys()):
|
||
mydata['isdatadock'] = diction['isdatadock']
|
||
|
||
if ("isqualiopi" in diction.keys()):
|
||
mydata['isqualiopi'] = diction['isqualiopi']
|
||
|
||
if ("website" in diction.keys()):
|
||
mydata['website'] = diction['website']
|
||
|
||
if ("email" in diction.keys()):
|
||
my_email = diction['email']
|
||
|
||
if ("telephone" in diction.keys()):
|
||
mydata['telephone'] = diction['telephone']
|
||
|
||
if ("pwd" in diction.keys()):
|
||
mydata['pwd'] = diction['pwd']
|
||
|
||
if ("contact_nom" in diction.keys()):
|
||
mydata['contact_nom'] = diction['contact_nom']
|
||
|
||
if ("contact_prenom" in diction.keys()):
|
||
mydata['contact_prenom'] = diction['contact_prenom']
|
||
|
||
if ("contact_tel" in diction.keys()):
|
||
mydata['contact_tel'] = diction['contact_tel']
|
||
|
||
if ("contact_mail" in diction.keys()):
|
||
mydata['contact_mail'] = diction['contact_mail']
|
||
|
||
if ("link_linkedin" in diction.keys()):
|
||
mydata['link_linkedin'] = diction['link_linkedin']
|
||
|
||
if ("link_facebook" in diction.keys()):
|
||
mydata['link_facebook'] = diction['link_facebook']
|
||
|
||
if ("link_twitter" in diction.keys()):
|
||
mydata['link_twitter'] = diction['link_twitter']
|
||
|
||
if ("invoice_vat_num" in diction.keys()):
|
||
mydata['invoice_vat_num'] = diction['invoice_vat_num']
|
||
|
||
if ("invoice_taux_vat" in diction.keys()):
|
||
mydata['invoice_taux_vat'] = diction['invoice_taux_vat']
|
||
|
||
if ("invoice_nom" in diction.keys()):
|
||
mydata['invoice_nom'] = diction['invoice_nom']
|
||
|
||
if ("invoice_adr_street" in diction.keys()):
|
||
mydata['invoice_adr_street'] = diction['invoice_adr_street']
|
||
|
||
if ("invoice_adr_city" in diction.keys()):
|
||
mydata['invoice_adr_city'] = diction['invoice_adr_city']
|
||
|
||
if ("invoice_adr_zip" in diction.keys()):
|
||
mydata['invoice_adr_zip'] = diction['invoice_adr_zip']
|
||
|
||
if ("invoice_adr_zip" in diction.keys()):
|
||
mydata['invoice_adr_country'] = diction['invoice_adr_country']
|
||
|
||
if ("invoice_email" in diction.keys()):
|
||
mydata['invoice_email'] = diction['invoice_email']
|
||
|
||
if ("invoice_telephone" in diction.keys()):
|
||
mydata['invoice_telephone'] = diction['invoice_telephone']
|
||
|
||
mydata['update_date'] = str(datetime.now())
|
||
|
||
# print(str(datetime.now()) + " webservice : diction = " + str(mydata))
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
"""
|
||
Si le compte partenaire n'as pas de compte de payement stripe, alors on profite de cette mise à jour pour le faire
|
||
"""
|
||
tmp = coll_name.find({'_id': ObjectId(partner_account_id), 'active': '1', 'locked': '0',
|
||
'recid': partner_recid})
|
||
|
||
is_admin_account = "0"
|
||
if ("is_partner_admin_account" in tmp[0].keys()):
|
||
is_admin_account = tmp[0]['is_partner_admin_account']
|
||
|
||
if (is_admin_account == "1"):
|
||
partnair_stripe_id = ""
|
||
if ("stripe_account_id" in tmp[0].keys()):
|
||
if tmp[0]['stripe_account_id']:
|
||
partnair_stripe_id = tmp[0]['stripe_account_id']
|
||
|
||
if (partnair_stripe_id is None or len(partnair_stripe_id) < 5):
|
||
print('### le partenaire = ' + str(tmp[0]['nom']) + " n'as pas de compte Stripe. on va le créer")
|
||
"""
|
||
Creation du compte de payement Stripe
|
||
"""
|
||
|
||
my_stripe_data = {}
|
||
my_stripe_data['email'] = str(tmp[0]['email'])
|
||
my_stripe_data['name'] = str(tmp[0]['nom'])
|
||
|
||
my_stripe_data['city'] = ""
|
||
if ("adr_city" in tmp[0].keys()):
|
||
if tmp[0]['adr_city']:
|
||
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
||
|
||
my_stripe_data['country'] = ""
|
||
if ("adr_country" in tmp[0].keys()):
|
||
if tmp[0]['adr_country']:
|
||
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
||
|
||
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
||
mydata['stripe_account_id'] = part_stripe_account_id
|
||
mydata['stripe_paymentmethod_id'] = ""
|
||
|
||
if (local_status is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " - WARNING : Impossible de créer le compte STRIPE du Client " + str(
|
||
tmp[0]['nom']))
|
||
|
||
ret_val = coll_name.find_one_and_update(
|
||
{'_id': ObjectId(partner_account_id), 'locked': '0', 'active': '1'},
|
||
{"$set": mydata},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (ret_val is None or '_id' not in ret_val.keys()):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le partenaire recid= : " + str(
|
||
partner_recid))
|
||
return False, " Impossible de mettre à jour le partenaire"
|
||
|
||
"""
|
||
A present que le partenaire est mis à jour / créé, on va mettre à jour les image logo et image cachet s'il y en a.
|
||
Mais seulement pour les comptes admin
|
||
"""
|
||
|
||
if (is_admin_account == "1" and file_logo):
|
||
recordimage_diction = {}
|
||
recordimage_diction['token'] = diction['token']
|
||
recordimage_diction['related_collection'] = "partnair_account"
|
||
recordimage_diction['type_img'] = "logo"
|
||
recordimage_diction['related_collection_recid'] = str(partner_recid)
|
||
recordimage_diction['image_recid'] = diction['file_logo_recid']
|
||
# print(" ### recordimage_diction 1 = ", recordimage_diction)
|
||
local_status, local_message = mycommon.recordClassImage_v2(file_logo, MYSY_GV.upload_folder,
|
||
recordimage_diction)
|
||
if (local_status is False):
|
||
return local_status, local_message
|
||
|
||
if (is_admin_account == "1" and file_cachet):
|
||
recordimage_diction = {}
|
||
recordimage_diction['token'] = diction['token']
|
||
recordimage_diction['related_collection'] = "partnair_account"
|
||
recordimage_diction['type_img'] = "cachet"
|
||
recordimage_diction['related_collection_recid'] = str(partner_recid)
|
||
recordimage_diction['image_recid'] = diction['file_cachet_recid']
|
||
# print(" ### recordimage_diction 2 = ", recordimage_diction)
|
||
local_status, local_message = mycommon.recordClassImage_v2(file_cachet, MYSY_GV.upload_folder,
|
||
recordimage_diction)
|
||
if (local_status is False):
|
||
return local_status, local_message
|
||
|
||
"""
|
||
Update du 28/09/2023 :
|
||
On verifie le compte a un 'ressource_humaine_id', si ce n'est pas le cas,
|
||
cela veut dire le compte RH associé au compte admin n'a pas été crée.
|
||
Il faut donc le faire.
|
||
|
||
"""
|
||
is_valide_rh_compte = False
|
||
Parnter_Data = MYSY_GV.dbname['partnair_account'].find_one(
|
||
{'recid': str(partner_recid), 'locked': '0', 'active': '1'}, )
|
||
if ("ressource_humaine_id" in Parnter_Data.keys()):
|
||
if (len(str(Parnter_Data['ressource_humaine_id'])) > 2):
|
||
is_valide_rh_compte = True
|
||
|
||
if (is_valide_rh_compte is False):
|
||
data_employe_admin = {}
|
||
data_employe_admin['partner_recid'] = str(Parnter_Data['recid'])
|
||
data_employe_admin['nom'] = str(Parnter_Data['nom'])
|
||
data_employe_admin['email'] = str(Parnter_Data['email'])
|
||
data_employe_admin['comment'] = "Compte Administrateur"
|
||
data_employe_admin['is_partner_admin_account'] = "1"
|
||
data_employe_admin['account_partner_id'] = str(Parnter_Data['_id'])
|
||
|
||
print(" #### data_employe_admin = ", str(data_employe_admin))
|
||
local_status, local_retval_inserted_id = ressources_humaines.Add_Partner_Admin_Ressource_Humaine_No_Toke(
|
||
data_employe_admin)
|
||
|
||
return True, "Le partenaire a bien ete mise à 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 partenaire"
|
||
|
||
|
||
|
||
'''
|
||
cette fonction valide un compte partenaire
|
||
La modification ne s'effectue que si le compte n'est pas verrouillé.
|
||
'locked'=0
|
||
|
||
|
||
Important : Juste apres la validation, le compte de payement est créé dans Stripe
|
||
|
||
cette fonction initialise / initialisation des paramettre par defaut de chaque partenaire
|
||
'''
|
||
def valide_partnair_account(value):
|
||
try:
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
tmp_count = coll_name.count_documents({'_id':ObjectId(str(value)), 'active':'1'})
|
||
if (tmp_count > 0):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce compte a deja été activé")
|
||
return False, "Ce compte a deja été activé "
|
||
|
||
|
||
tmp_count = coll_name.count_documents({'_id':ObjectId(str(value)), 'active':'0'})
|
||
|
||
if( tmp_count <= 0 ):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - il n'y aucun compte à activer")
|
||
return False, "Impossible de valider ce compte "
|
||
|
||
tmp = coll_name.find({'_id': ObjectId(str(value)), 'active': '0'})
|
||
partner_email = tmp[0]['email']
|
||
|
||
|
||
# A ce niveau le login et passe sont ok.
|
||
# il faut donc créer le token et renvoyer le token.
|
||
my_token = mycommon.create_token_urlsafe()
|
||
|
||
"""
|
||
Creation du compte de payement Stripe
|
||
"""
|
||
|
||
my_stripe_data = {}
|
||
my_stripe_data['email'] = str(tmp[0]['email'])
|
||
my_stripe_data['name'] = str(tmp[0]['nom'])
|
||
|
||
my_stripe_data['city'] = ""
|
||
if ("adr_city" in tmp[0].keys()):
|
||
if tmp[0]['adr_city']:
|
||
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
||
|
||
|
||
my_stripe_data['adr_country'] = ""
|
||
if ("adr_country" in tmp[0].keys()):
|
||
if tmp[0]['adr_country']:
|
||
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
||
|
||
|
||
|
||
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
||
if( local_status is False):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client "+str(tmp[0]['nom']))
|
||
|
||
|
||
'''
|
||
Create default / temporary pwd for new account
|
||
'''
|
||
#my_tmp_pwd = mycommon.create_token_urlsafe();
|
||
|
||
now = datetime.now()
|
||
ret_val = coll_name.find_one_and_update({'_id':ObjectId(str(value)), 'locked':'0'},
|
||
{"$set":
|
||
{'active': "1","date_update":str(now),
|
||
'secret_key':str(my_token),
|
||
'stripe_account_id':part_stripe_account_id,
|
||
'active': "1",
|
||
}
|
||
},
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
|
||
|
||
if( ret_val is None or "_id" not in ret_val.keys()):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucune modif n'a été faite")
|
||
return False, "Impossible de valider le compte"
|
||
|
||
|
||
"""
|
||
# Ap présent que le compte est activé, il faut aller :
|
||
1 -Init_And_Update_courrier_template_tracking pour le tracking des documents
|
||
2 - Initialiser les points de configuration technique, mais sans les activer
|
||
|
||
"""
|
||
|
||
local_status, local_retval = module_editique.Init_And_Update_courrier_template_tracking_With_Partner_Data(ret_val)
|
||
if( local_status is False ):
|
||
mycommon.myprint(" WARNING : Impossible d'initialiser le 'courrier_template_type_document' pour le partner_account_id =" + str(ret_val['_id']))
|
||
|
||
|
||
for val_tmp in MYSY_GV.dbname['base_partner_setup'].find({'partner_owner_recid':'default', 'valide':'1', 'locked':'0'}):
|
||
new_data = val_tmp
|
||
del new_data['_id']
|
||
new_data['config_value'] = ""
|
||
new_data['update_date'] = ""
|
||
new_data['partner_owner_recid'] = str(ret_val['recid'])
|
||
|
||
key_data = {}
|
||
key_data['config_name'] = val_tmp['config_name']
|
||
key_data['partner_owner_recid'] = str(ret_val['recid'])
|
||
|
||
new_retval_data = MYSY_GV.dbname['base_partner_setup'].find_one_and_update(key_data,
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if new_retval_data is None or "_id" not in new_retval_data.keys():
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Impossible d'initialiser le point de configuration technique " + str(val_tmp['config_name']) + ". ")
|
||
|
||
|
||
|
||
|
||
|
||
"""
|
||
12/03/2024 - Initialiser le reste des points de configuration pour rendre le compte plus opérationnel
|
||
|
||
Liste des points de configuration à ajouter
|
||
- Les document : Il faut créer à minima les documents suivants :
|
||
|
||
- Un modele de journée de travail
|
||
|
||
- Les étapes d'un session :
|
||
|
||
|
||
- Un site par defaut :
|
||
|
||
|
||
- CRM Etap Opportunité:
|
||
|
||
|
||
- Conditions de paiement
|
||
|
||
"""
|
||
local_status, local_retval = mycommon.Configure_Partner_Init_Setup_No_Token({'partner_id':str(value)})
|
||
if( local_status is False) :
|
||
return local_status, local_retval
|
||
|
||
mycommon.myprint("La modif a bien ete faite Ajout secret_key OK, =" + str(ret_val['_id']))
|
||
# Envoie du mail de notification
|
||
mail.Pro_Account_Token_Pass(partner_email, my_token)
|
||
return 'True', my_token
|
||
|
||
|
||
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 valider le compte"
|
||
|
||
|
||
|
||
|
||
'''
|
||
Recuperation d'un partenaire
|
||
'''
|
||
def get_partner_account(diction):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token']
|
||
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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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']
|
||
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, " Impossible de récupérer les informations"
|
||
|
||
# recuperation des paramettre
|
||
email_value = ""
|
||
|
||
|
||
token_value = ""
|
||
if diction['token']:
|
||
token_value = diction['token']
|
||
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
# Verification de la valididé du token
|
||
coll_token = MYSY_GV.dbname['user_token']
|
||
|
||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||
retval = mycommon.check_partner_token_validity(email_value, token_value )
|
||
|
||
if retval is False:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - La session de connexion n'est pas valide")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
|
||
'''tmp_count = coll_token.find({'email':email_value, 'token': token_value, 'valide': '1'}).count()
|
||
|
||
if (tmp_count <= 0):
|
||
mycommon.myprint("L'email ou le token ne sont pas valident")
|
||
return False
|
||
'''
|
||
|
||
coll_token = MYSY_GV.dbname['partner_token']
|
||
tmp = coll_token.find({ 'token': str(token_value), 'valide': '1'})
|
||
partnere_recid = tmp[0]['recid']
|
||
parnter_account_id = tmp[0]['partner_account_id']
|
||
|
||
#print(" #### parters RECID = "+str(partnere_recid))
|
||
|
||
|
||
RetObject = []
|
||
for retVal in coll_name.find({'_id': ObjectId(str(parnter_account_id)), 'active':'1', 'locked':'0'}):
|
||
|
||
user = retVal
|
||
|
||
"""
|
||
On va aller recuperer le nombre de compte utilisateur (partner_account), de formations , de session, d'inscrit
|
||
"""
|
||
nb_count_partner = MYSY_GV.dbname['partnair_account'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid'])})
|
||
nb_count_user = MYSY_GV.dbname['user_account'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid'])})
|
||
|
||
nb_count_class = MYSY_GV.dbname['myclass'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid'])})
|
||
|
||
nb_count_session = MYSY_GV.dbname['session_formation'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid']), })
|
||
|
||
nb_count_inscrit = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid']),
|
||
'status': {'$ne': '-1'}})
|
||
|
||
user['nb_partner_account'] = str(nb_count_partner)
|
||
user['nb_user_account'] = str(nb_count_user)
|
||
|
||
user['nb_class'] = str(nb_count_class)
|
||
user['nb_session'] = str(nb_count_session)
|
||
user['nb_inscrit'] = str(nb_count_inscrit)
|
||
|
||
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
|
||
|
||
abonnement_periodicite = ""
|
||
if ("abonnement_periodicite" in retVal.keys()):
|
||
abonnement_periodicite = retVal['abonnement_periodicite']
|
||
user['abonnement_periodicite'] = abonnement_periodicite
|
||
|
||
|
||
"""
|
||
05/09/2024 : Recuperer le nombre d'activité en retard pour la personne connectée
|
||
"""
|
||
local_diction = {}
|
||
local_diction['partner_owner_recid'] = str(partnere_recid)
|
||
local_diction['employee_assigned_to_id'] = str(retVal['ressource_humaine_id'])
|
||
|
||
local_activite_status, local_activite_retval = Activite.Get_Nb_Entity_Activite_Assigne_To_Me_En_Retard_No_token(local_diction)
|
||
if( local_activite_status is True):
|
||
user['nb_activite_retard'] = local_activite_retval
|
||
else:
|
||
user['nb_activite_retard'] = "0"
|
||
|
||
|
||
"""
|
||
Recuperation du nombre de nouvelles activité assigné a moi
|
||
"""
|
||
local_new_activite_status, local_new_activite_retval = Activite.Get_Nb_New_Activite_Assigne_To_Me_Token(
|
||
local_diction)
|
||
if (local_new_activite_status is True):
|
||
user['nb_activite_new'] = local_new_activite_retval
|
||
else:
|
||
user['nb_activite_new'] = "0"
|
||
|
||
|
||
"""
|
||
update du 01/05/2024
|
||
Pour distinguer si le partenaire est a lié à une formation initiale ou continue
|
||
on va aller recuperer les paramétrage sur le compte admin du partenaire.
|
||
|
||
Volontairement, on ne descend pas ce paramettre sur les utilisateurs associée au partenaire
|
||
"""
|
||
|
||
admin_partnair_account = MYSY_GV.dbname['partnair_account'].find_one({'recid':retVal['recid'],
|
||
'active':'1',
|
||
'locked':'0',
|
||
'is_partner_admin_account':"1"})
|
||
|
||
formation_initiale = "0"
|
||
if(admin_partnair_account and "formation_initiale" in admin_partnair_account.keys() ):
|
||
formation_initiale = str(admin_partnair_account['formation_initiale'])
|
||
|
||
user['formation_initiale'] = formation_initiale
|
||
|
||
document_super_admin = "0"
|
||
if (admin_partnair_account and "document_super_admin" in admin_partnair_account.keys()):
|
||
document_super_admin = str(admin_partnair_account['document_super_admin'])
|
||
|
||
user['document_super_admin'] = document_super_admin
|
||
|
||
plateforme_super_admin = "0"
|
||
if (plateforme_super_admin and "plateforme_super_admin" in admin_partnair_account.keys()):
|
||
plateforme_super_admin = str(admin_partnair_account['plateforme_super_admin'])
|
||
|
||
user['plateforme_super_admin'] = plateforme_super_admin
|
||
|
||
RetObject.append(JSONEncoder().encode(user))
|
||
|
||
|
||
|
||
my_new_data = {}
|
||
now = str(datetime.now())
|
||
my_new_data = {'firstconnexion':'0', 'lastconnexion':now}
|
||
|
||
|
||
ret_val = coll_name.find_one_and_update({'_id': ObjectId(str(parnter_account_id)), 'active':'1', 'locked':'0'},
|
||
{"$set": my_new_data},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if ret_val and ret_val['_id']:
|
||
mycommon.myprint("Connexion du partner recid = "+str(partnere_recid)+" OK. Mise à jour du firstconnexion et/ou lastconnexion : OK")
|
||
|
||
else:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) +
|
||
" WARNING : Impossible de mettre à jour du firstconnexion et/ou lastconnexion du partner recid = "+str(partnere_recid)+". ")
|
||
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer les informations"
|
||
|
||
|
||
"""
|
||
Recuperation des images d'un partenaire (logo & cachet)
|
||
"""
|
||
|
||
def getRecodedParnterImage_from_front(diction=None):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token']
|
||
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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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']
|
||
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, " Impossible de récupérer les informations"
|
||
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'partnair_account',
|
||
'related_collection_recid': str(my_partner['recid'])}
|
||
|
||
#print(" ### qery_images = ", qery_images)
|
||
|
||
RetObject = []
|
||
partner_images = {}
|
||
cpt = 0
|
||
# Recuperation des image 'logo' et 'cachet' si le partenaire en a
|
||
for retVal in MYSY_GV.dbname['mysy_images'].find(qery_images):
|
||
if ('type_img' in retVal.keys()):
|
||
if (retVal['type_img'] == "logo"):
|
||
partner_images['logo_img'] = retVal['img'].decode()
|
||
partner_images['logo_img_recid'] = retVal['recid']
|
||
cpt = cpt + 1
|
||
|
||
if (retVal['type_img'] == "cachet"):
|
||
partner_images['cachet_img'] = retVal['img'].decode()
|
||
partner_images['cachet_img_recid'] = retVal['recid']
|
||
cpt = cpt + 1
|
||
|
||
if( cpt > 0):
|
||
RetObject.append(JSONEncoder().encode(partner_images))
|
||
#print(" ### getRecodedParnterImage_from_front RetObject = ", RetObject)
|
||
return True, RetObject
|
||
else:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Aucune image (Logo ou Cachet trouvé) ")
|
||
|
||
return False, "Aucune image (Logo ou Cachet trouvé) "
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de recupérer les images/médias du partenaire"
|
||
|
||
|
||
|
||
'''
|
||
|
||
Login du partenaire avec
|
||
- mail
|
||
- passwd
|
||
- cle secrete qui est son token fixe.
|
||
|
||
Important : update du 28/09/2023 :
|
||
Cette fonction retourne les droits d'acces de l'utilisateur
|
||
dans une champ : 'user_acces_right', idealement sous forme JSON
|
||
Cette info sera stocké et exploiré sous forme de cookie chez le client.
|
||
Ce cookie sera prefixé du token du client, ceci pour rendre cette valeur unique non copiable
|
||
|
||
'''
|
||
def partner_login(diction):
|
||
try:
|
||
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['email', 'pwd', ]
|
||
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'est pas accepté dans cette API")
|
||
return False, str(inspect.stack()[0][3]) + " Toutes les informations obligatoires ne sont pas fournies"
|
||
|
||
'''
|
||
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 des champs")
|
||
return False, str(inspect.stack()[0][3]) + " Toutes les informations obligatoires ne sont pas fournies (2) "
|
||
|
||
|
||
mydata={}
|
||
|
||
# recuperation des paramettre
|
||
email = ""
|
||
if ("email" in diction.keys()):
|
||
if diction['email']:
|
||
email = diction['email']
|
||
mydata['email'] = diction['email']
|
||
|
||
pwd = ""
|
||
if ("pwd" in diction.keys()):
|
||
if diction['pwd']:
|
||
pwd = diction['pwd']
|
||
|
||
# Verifier la taille des infos saisies. Pour le login et pass, la longeur max autorisée est 100 caractère
|
||
if (len(str(email)) > 100 or len(str(pwd)) > 100):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Les informations de login et/ou mot de passe sont incorrectes")
|
||
return False, " Les informations de login et/ou mot de passe sont incorrectes."
|
||
|
||
# Verifier la taille des infos saisies. Pour le login et pass, la longeur max autorisée est 100 caractère
|
||
if (len(str(email)) <= 0 or len(str(pwd)) <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Les informations de login et/ou mot de passe sont incorrectes")
|
||
return False, " Les informations de login et/ou mot de passe sont incorrectes."
|
||
|
||
|
||
"""
|
||
Verifier si le compte ne serait pas verrouillé
|
||
"""
|
||
|
||
tmp_count_verrou = MYSY_GV.dbname['partnair_account'].count_documents({'email':email, 'pwd':pwd, 'locked':'1', 'active': '1'})
|
||
if (tmp_count_verrou > 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Ce compte " + str(email) + " est actuellement verrouillé")
|
||
return False, " Ce compte " + str(email) + " est actuellement verrouillé."
|
||
|
||
# Verification si ce user existe (controle : login et passwd)
|
||
tmp_count = MYSY_GV.dbname['partnair_account'].count_documents({'email':email, 'pwd':pwd, 'locked':'0', 'active': '1'})
|
||
|
||
if (tmp_count != 1):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " Login et/ou mot de passe invalide " + str( email) + " ")
|
||
return False, " Login et/ou mot de passe invalide, merci de verifier votre saisie. "
|
||
|
||
|
||
# Recuperation des données du partenaire qui se connecte
|
||
my_partner = MYSY_GV.dbname['partnair_account'].find_one(
|
||
{'email': email, 'pwd': pwd, 'locked': '0', 'active': '1'})
|
||
|
||
partner_recid = my_partner['recid']
|
||
ressource_humaine_id = ""
|
||
if ( "ressource_humaine_id" in my_partner.keys()):
|
||
ressource_humaine_id = my_partner['ressource_humaine_id']
|
||
|
||
# A ce niveau le login et passe sont ok.
|
||
# il faut donc créer le token et renvoyer le token.
|
||
my_token = mycommon.create_token_urlsafe()
|
||
|
||
# 1 - Vu le login et passe sont valident, alors on va aller desactier un eventuel token qui existerait
|
||
local_now = str(datetime.now())
|
||
local_result = MYSY_GV.dbname['partner_token'].update_many(
|
||
{'valide': '1', 'partner_account_id':str(my_partner['_id'])},
|
||
{
|
||
"$set": {"valide": '0', 'end_date': str(datetime.now()), 'date_update': str(datetime.now())}
|
||
})
|
||
|
||
# Enregistrement du nouveau token
|
||
tokenfield = {}
|
||
tokenfield['partner_account_id'] = str(my_partner['_id'])
|
||
tokenfield['email'] = email
|
||
tokenfield['recid'] = partner_recid
|
||
tokenfield['update_date'] = str(datetime.now())
|
||
tokenfield['valide'] = '1'
|
||
tokenfield['locked'] = '0'
|
||
tokenfield['start_date'] = str(datetime.now())
|
||
tokenfield['token'] = str(my_token)
|
||
tokenfield['type'] = 'partner'
|
||
|
||
|
||
|
||
'''
|
||
Insertion du nouveau token
|
||
'''
|
||
ret_val = MYSY_GV.dbname['partner_token'].insert_one(tokenfield, )
|
||
|
||
if (not ret_val.inserted_id):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Impossible de finaliser la creation du token du partner")
|
||
return False, "Impossible de se connecter, merci de contacter le support technique (1)"
|
||
|
||
|
||
|
||
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['token'] = str(my_token)
|
||
|
||
|
||
mydata['valide'] = "1"
|
||
mydata['update_date'] = now
|
||
|
||
partner_key_secrete_key = ""
|
||
|
||
# Verification que les informations sont juste
|
||
coll_name = MYSY_GV.dbname['partnair_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) "
|
||
|
||
list_connexion_context = []
|
||
if( "list_connexion_context" in ret_val.keys() ):
|
||
list_connexion_context = ret_val['list_connexion_context']
|
||
|
||
return_data = {}
|
||
return_data['token'] = str(my_token)
|
||
return_data['list_connexion_context'] = list_connexion_context
|
||
|
||
#print(" ### token partner = ", str(my_token))
|
||
|
||
|
||
"""
|
||
Update du 28/09/2023 :
|
||
Recuperation de la matrice des droits de l'utilisateur qui vient de se connecter
|
||
"""
|
||
return_data['user_access_right'] = []
|
||
qry = {'valide':'1', 'locked':'0','partner_owner_recid':str(partner_recid),'user_id':str(ressource_humaine_id)}
|
||
#print(" #### partner_login user_access_right qry = ", qry)
|
||
|
||
for retval in MYSY_GV.dbname['user_access_right'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
||
local_access_right = {}
|
||
if( 'module' in retval.keys()):
|
||
local_access_right['module'] = retval['module']
|
||
|
||
if ('read' in retval.keys()):
|
||
local_access_right['read'] = retval['read']
|
||
|
||
if ('write' in retval.keys()):
|
||
local_access_right['write'] = retval['write']
|
||
|
||
|
||
return_data['user_access_right'].append(local_access_right)
|
||
|
||
|
||
RetObject = []
|
||
|
||
#print(" #### partner_login : return_data = ", return_data)
|
||
RetObject.append(JSONEncoder().encode(return_data))
|
||
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 au système. Merci de contacter votre administrateur "
|
||
|
||
|
||
"""
|
||
Cette fonction upgrade un compte utilisateur vers
|
||
un compte PRO (aussi appelé compte partenaire).
|
||
|
||
Ceci revient à créer un nouveau compte utilisateur. aini la personne en face
|
||
aura
|
||
- un compte utilisateur classique et
|
||
- un compte pro
|
||
|
||
En suite on desactive le compte utilisateur classique et on maintient que le compte pro.
|
||
|
||
Pour migrer un compte utilisateur classique vers un compte pro, voici ce qu'il faut faire :
|
||
|
||
1 - récupérer les infos du contact . ici à partir du token de la personne connectée, on peut aller chercher ses info.
|
||
2 - récupérer les infos de la société
|
||
3 - récupérer les infos sur pack
|
||
|
||
etape 1 : add_partner_account(diction)
|
||
etape 2 : Desactivation du compte utilisateur
|
||
"""
|
||
def UpgradetoPro(diction):
|
||
try:
|
||
field_list = ['token', 'nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country', 'link_linkedin', 'link_facebook',
|
||
'link_twitter', 'email', 'pwd', 'telephone', 'contact_nom', 'contact_prenom', 'contact_tel',
|
||
'contact_mail', 'pack_service']
|
||
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'existe pas, UpgradetoPro annulée")
|
||
return False, "Impossible de créer le partenaire"
|
||
|
||
'''
|
||
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', 'nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country',
|
||
'email', 'telephone', 'pack_service']
|
||
|
||
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, "Tous les champs obligatoires ne sont pas fournis"
|
||
|
||
token = ""
|
||
new_diction = {}
|
||
user_recid = "None"
|
||
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
|
||
if ( len(str(token)) > 0 ):
|
||
retval = mycommon.check_token_validity("", token)
|
||
|
||
if retval is False :
|
||
mycommon.myprint(str(inspect.stack()[0][3])+" - La session de connexion n'est pas valide")
|
||
return "Err_Connexion", "La session de connexion n'est pas valide"
|
||
|
||
# Recuperation du recid de l'utilisateur
|
||
user_recid = mycommon.get_user_recid_from_token(token)
|
||
if user_recid is False:
|
||
mycommon.myprint(str(inspect.stack()[0][3])+" - Impossible de récupérer le token de l'utilisateur")
|
||
return False, " Impossible de migrer vers le compte pro"
|
||
|
||
|
||
# Recuperation des paramettre du compe
|
||
if ("nom" in diction.keys()):
|
||
if diction['nom']:
|
||
new_diction['nom'] = diction['nom']
|
||
|
||
if ("adr_street" in diction.keys()):
|
||
if diction['adr_street']:
|
||
new_diction['adr_street'] = diction['adr_street']
|
||
|
||
if ("adr_city" in diction.keys()):
|
||
if diction['adr_city']:
|
||
new_diction['adr_city'] = diction['adr_city']
|
||
|
||
if ("adr_zip" in diction.keys()):
|
||
if diction['adr_zip']:
|
||
new_diction['adr_zip'] = diction['adr_zip']
|
||
|
||
if ("adr_country" in diction.keys()):
|
||
if diction['adr_country']:
|
||
new_diction['adr_country'] = diction['adr_country']
|
||
|
||
if ("link_linkedin" in diction.keys()):
|
||
if diction['link_linkedin']:
|
||
new_diction['link_linkedin'] = diction['link_linkedin']
|
||
|
||
if ("link_facebook" in diction.keys()):
|
||
if diction['link_facebook']:
|
||
new_diction['link_facebook'] = diction['link_facebook']
|
||
|
||
if ("link_twitter" in diction.keys()):
|
||
if diction['link_twitter']:
|
||
new_diction['link_twitter'] = diction['link_twitter']
|
||
|
||
if ("email" in diction.keys()):
|
||
if diction['email']:
|
||
new_diction['email'] = diction['email']
|
||
|
||
if ("telephone" in diction.keys()):
|
||
if diction['telephone']:
|
||
new_diction['telephone'] = diction['telephone']
|
||
|
||
|
||
if ("pack_service" in diction.keys()):
|
||
if diction['pack_service']:
|
||
new_diction['pack_service'] = diction['pack_service']
|
||
|
||
'''
|
||
Create default pwd for new account
|
||
'''
|
||
new_diction['pwd'] = mycommon.create_token_urlsafe();
|
||
|
||
|
||
'''
|
||
Recuperation des information du contact.
|
||
Pour memo, le compte utilisateur qui fait cette migration devient automatiquement
|
||
le contact principal du compte pro.
|
||
'''
|
||
coll_user_account = MYSY_GV.dbname['user_account']
|
||
for x in coll_user_account.find({"recid": user_recid}):
|
||
if ("email" in x.keys()):
|
||
if x['email']:
|
||
new_diction['contact_mail'] = x['email']
|
||
|
||
if ("last_name" in x.keys()):
|
||
if x['last_name']:
|
||
new_diction['contact_nom'] = x['last_name']
|
||
|
||
if ("surname" in x.keys()):
|
||
if x['surname']:
|
||
new_diction['contact_prenom'] = x['surname']
|
||
|
||
if ("mob_phone" in x.keys()):
|
||
if x['mob_phone']:
|
||
new_diction['contact_tel'] = x['mob_phone']
|
||
|
||
print(" new_diction la = "+str(new_diction))
|
||
|
||
'''
|
||
Verification que cette adresse email n'hesiste pas deja dans
|
||
'''
|
||
check_tmp = coll_user_account.count_documents({'email': str(diction['email'])})
|
||
|
||
if (check_tmp < 0):
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce compte partenaire existe deja")
|
||
return False, "Ce compte partenaire existe deja"
|
||
|
||
status, retval = add_partner_account(new_diction)
|
||
|
||
if( status ):
|
||
'''
|
||
La migration s'est bien passée.
|
||
Maintenant mettre le compte utilisateur :
|
||
- "migrated : 1"
|
||
- "migrated_mail_account" : le mail du compte pro associé
|
||
- "migration_date" : datetime.now()
|
||
|
||
'''
|
||
mydata = {}
|
||
mydata['migrated'] = "1"
|
||
mydata['ispending'] = "0"
|
||
mydata['migrated_date'] = str(datetime.now())
|
||
mydata['migrated_mail_account'] = new_diction['email']
|
||
ret_val = coll_user_account.find_one_and_update(
|
||
{"recid": user_recid},
|
||
{"$set": mydata},
|
||
return_document=ReturnDocument.AFTER )
|
||
if (ret_val and ret_val['_id']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " le compte recid "+str(user_recid)+" migré en compte pro "+str(mydata))
|
||
|
||
else:
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de migrer le user_account : " + str(user_recid)+" en compte pro")
|
||
return False, " Impossible de finaliser la migration vers le compte PRO : "
|
||
|
||
|
||
else:
|
||
return False, "Impossible de migrer le compte vers le compte pro"
|
||
|
||
return True, "Le compte à été bien migré vers un compte pro"
|
||
|
||
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 migrer vers le compte pro"
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction verrouille le compte d'un utilisateur
|
||
"""
|
||
def Lock_partner_account(diction):
|
||
try:
|
||
|
||
field_list = ['token', 'partner_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é, 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', ]
|
||
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, "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 "
|
||
|
||
new_data = {}
|
||
new_data['update_date'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['locked'] = "1"
|
||
new_data['active'] = "0"
|
||
|
||
|
||
|
||
|
||
update_data = MYSY_GV.dbname['partnair_account'].find_one_and_update({'_id':ObjectId(str(diction['partner_id'])),
|
||
'recid':my_partner['recid']},
|
||
{'$set':new_data})
|
||
|
||
if( update_data and '_id' in update_data.keys() ):
|
||
return True, "Le compte a été correctement verrouillé"
|
||
|
||
else:
|
||
return False, "Impossible de verrouiller le compte utilisateur (2)"
|
||
|
||
|
||
|
||
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 verrouiller le compte utilisateur"
|
||
|
||
"""
|
||
Cette fonction reactive le compte d'un utilisateur
|
||
"""
|
||
def UnLock_partner_account(diction):
|
||
try:
|
||
|
||
field_list = ['token', 'partner_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é, 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', ]
|
||
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, "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 "
|
||
|
||
new_data = {}
|
||
new_data['update_date'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['locked'] = "0"
|
||
new_data['active'] = "1"
|
||
|
||
|
||
|
||
|
||
update_data = MYSY_GV.dbname['partnair_account'].find_one_and_update({'_id':ObjectId(str(diction['partner_id'])),
|
||
'recid':my_partner['recid']},
|
||
{'$set':new_data})
|
||
|
||
if( update_data and '_id' in update_data.keys() ):
|
||
return True, "Le compte a été correctement réactivé"
|
||
|
||
else:
|
||
return False, "Impossible de réactiver le compte utilisateur (2)"
|
||
|
||
|
||
|
||
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 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 la liste des arguments ")
|
||
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 "
|
||
|
||
|
||
"""
|
||
Récuperer la liste des partenaires de la plateforme avec des filtres
|
||
|
||
"""
|
||
def Get_List_Plateforme_Partnaire_With_Filter(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'email', 'nom', '_id',
|
||
'locked', 'active']
|
||
|
||
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', ]
|
||
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
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if( "plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if( is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
filt_nom = {}
|
||
if ("nom" in diction.keys()):
|
||
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
||
|
||
filt_email = {}
|
||
if ("nom" in diction.keys()):
|
||
filt_email = {'email': {'$regex': str(diction['email']), "$options": "i"}}
|
||
|
||
filt_id = {}
|
||
if ("_id" in diction.keys()):
|
||
filt_id = {'_id': ObjectId(str(diction['_id']))}
|
||
|
||
filt_locked = {}
|
||
if ("locked" in diction.keys()):
|
||
filt_locked = {'locked': str(diction['locked'])}
|
||
|
||
filt_active = {}
|
||
if ("active" in diction.keys()):
|
||
filt_active = {'active': str(diction['active'])}
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
find_qry = {
|
||
'$and': [filt_nom,
|
||
filt_email, filt_id, filt_locked, filt_active, {'is_partner_admin_account':'1'}]}
|
||
|
||
print("### Get_List_Partnaire_With_Filter find_qry = ", find_qry)
|
||
|
||
exported_fields = {'nom':1, 'email':1, 'telephone':1, 'invoice_nom':1, 'invoice_email':1, 'invoice_telephone':1,
|
||
'contact_nom':1, 'contact_prenom':1, 'contact_tel':1, 'contact_mail':1, 'active':1, 'locked':1,
|
||
'lms_virtualhost_url':1, 'date_update':1, 'formation_initiale':1, 'adr_street':1, 'adr_zip':1,
|
||
'adr_city':1, 'adr_country':1, 'invoice_adr_street':1, 'invoice_adr_zip':1,
|
||
'invoice_adr_city':1, 'invoice_adr_country':1, 'pack_service':1, 'recid':1}
|
||
|
||
|
||
for retval in MYSY_GV.dbname['partnair_account'].find(find_qry, exported_fields).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
|
||
|
||
"""
|
||
On va aller recuperer le nombre de compte utilisateur (partner_account), de formations , de session, d'inscrit
|
||
"""
|
||
nb_count_partner = MYSY_GV.dbname['partnair_account'].count_documents(
|
||
{'partner_owner_recid': str(retval['recid'])})
|
||
|
||
nb_count_user = MYSY_GV.dbname['user_account'].count_documents(
|
||
{'partner_owner_recid': str(retval['recid'])})
|
||
|
||
nb_count_class = MYSY_GV.dbname['myclass'].count_documents(
|
||
{'partner_owner_recid': str(retval['recid'])})
|
||
|
||
nb_count_session = MYSY_GV.dbname['session_formation'].count_documents(
|
||
{'partner_owner_recid': str(retval['recid'])})
|
||
|
||
nb_count_inscrit = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'partner_owner_recid': str(retval['recid'])})
|
||
|
||
user['nb_partner_account'] = str(nb_count_partner)
|
||
user['nb_user_account'] = str(nb_count_user)
|
||
|
||
user['nb_class'] = str(nb_count_class)
|
||
user['nb_session'] = str(nb_count_session)
|
||
user['nb_inscrit'] = str(nb_count_inscrit)
|
||
|
||
formation_initiale = "0"
|
||
formation_initiale_code = ""
|
||
if ("formation_initiale" in user.keys()):
|
||
if (user['formation_initiale'] == "1"):
|
||
formation_initiale_code = "F. Initiale"
|
||
formation_initiale = user['formation_initiale']
|
||
else:
|
||
formation_initiale_code = "F. Continue"
|
||
|
||
user['formation_initiale'] = formation_initiale
|
||
user['formation_initiale_code'] = formation_initiale_code
|
||
val_tmp = val_tmp + 1
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
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 liste des partenaires "
|
||
|
||
|
||
"""
|
||
Cette fonction permet de recuperer la liste des connexions liée à un partenaire
|
||
(que soit lui ou des utilisateur de partenaire)"""
|
||
def Get_Given_Plateforme_Partnaire_Connexion_Login_With_Filter(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'email', ]
|
||
|
||
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', ]
|
||
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
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if( "plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if( is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
|
||
filt_email = {}
|
||
if ("nom" in diction.keys()):
|
||
filt_email = {'email': {'$regex': str(diction['email']), "$options": "i"}}
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
find_qry = {
|
||
'$and': [filt_email, ]}
|
||
|
||
print("### Get_List_Partnaire_With_Filter find_qry = ", find_qry)
|
||
|
||
exported_fields = {'token':0, 'partner_account_id':0}
|
||
|
||
|
||
for retval in MYSY_GV.dbname['partnair_account'].find(find_qry, exported_fields).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
|
||
|
||
val_tmp = val_tmp + 1
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
|
||
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 liste des connexions "
|
||
|
||
|
||
"""
|
||
Recuperer les données d'un partenaire à partir de son ID
|
||
"""
|
||
|
||
def get_partner_account_from_id(diction):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token', '_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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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', '_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 la liste des arguments ")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
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
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if ("plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if (is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
|
||
# recuperation des paramettre
|
||
email_value = ""
|
||
|
||
token_value = ""
|
||
if diction['token']:
|
||
token_value = diction['token']
|
||
|
||
coll_name = MYSY_GV.dbname['partnair_account']
|
||
|
||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||
retval = mycommon.check_partner_token_validity(email_value, token_value)
|
||
|
||
|
||
|
||
coll_token = MYSY_GV.dbname['partner_token']
|
||
tmp = coll_token.find({'token': str(token_value), 'valide': '1'})
|
||
partnere_recid = tmp[0]['recid']
|
||
parnter_account_id = tmp[0]['partner_account_id']
|
||
|
||
# print(" #### parters RECID = "+str(partnere_recid))
|
||
|
||
RetObject = []
|
||
for retVal in MYSY_GV.dbname['partnair_account'].find({'_id': ObjectId(str(diction['_id'])),}):
|
||
|
||
user = retVal
|
||
|
||
"""
|
||
On va aller recuperer le nombre de compte utilisateur (partner_account), de formations , de session, d'inscrit
|
||
"""
|
||
nb_count_partner = MYSY_GV.dbname['partnair_account'].count_documents({'partner_owner_recid':str(retVal['recid'])})
|
||
nb_count_user = MYSY_GV.dbname['user_account'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid'])})
|
||
|
||
nb_count_class = MYSY_GV.dbname['myclass'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid'])})
|
||
|
||
nb_count_session = MYSY_GV.dbname['session_formation'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid']),})
|
||
|
||
nb_count_inscrit = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'partner_owner_recid': str(retVal['recid']),
|
||
'status':{'$ne':'-1'}})
|
||
|
||
user['nb_partner_account'] = str(nb_count_partner)
|
||
user['nb_user_account'] = str(nb_count_user)
|
||
|
||
user['nb_class'] = str(nb_count_class)
|
||
user['nb_session'] = str(nb_count_session)
|
||
user['nb_inscrit'] = str(nb_count_inscrit)
|
||
|
||
formation_initiale = "0"
|
||
formation_initiale_code = ""
|
||
if( "formation_initiale" in user.keys()):
|
||
if( user['formation_initiale'] == "1"):
|
||
formation_initiale_code = "F. Initiale"
|
||
formation_initiale = user['formation_initiale']
|
||
else:
|
||
formation_initiale_code = "F. Continue"
|
||
|
||
user['formation_initiale'] = formation_initiale
|
||
user['formation_initiale_code'] = formation_initiale_code
|
||
|
||
|
||
RetObject.append(JSONEncoder().encode(user))
|
||
|
||
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer les informations"
|
||
|
||
"""
|
||
Verrouiller un partenaire, ainsi que les sous comptes associés ainsi que les formations associées
|
||
"""
|
||
def Lock_PF_partner_account_And_Sub_Accound_from_id(diction):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token', '_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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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', '_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 la liste des arguments ")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
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
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if ("plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if (is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
|
||
|
||
"""
|
||
Le système ne permettra pas de verrouiller un compte 'is_plateforme_super_admin'.
|
||
On va donc verifier que le compte à verrouiller n'est pas un compte 'is_plateforme_super_admin'
|
||
"""
|
||
local_pf_partner_count = MYSY_GV.dbname['partnair_account'].count_documents(
|
||
{'_id': ObjectId(diction['_id']), 'is_partner_admin_account': '1'})
|
||
|
||
if( local_pf_partner_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du compte partenaire est invalide ")
|
||
return False, " L'identifiant du compte partenaire est invalide "
|
||
|
||
|
||
local_pf_partner_data = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(diction['_id']), 'is_partner_admin_account':'1'})
|
||
if( "plateforme_super_admin" in local_pf_partner_data.keys() and local_pf_partner_data['plateforme_super_admin'] == "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Ce compte est un super-administrateur de la plateforme et ne peut pas être verrouillé. ")
|
||
return False, " Ce compte est un super-administrateur de la plateforme et ne peut pas être verrouillé. ",
|
||
|
||
|
||
new_data = {}
|
||
new_data['update_date'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['lock_raison'] = "plateforme_admin"
|
||
new_data['locked'] = "1"
|
||
new_data['locked_date'] = str(datetime.now())
|
||
|
||
|
||
|
||
updated_partnair_account = MYSY_GV.dbname['partnair_account'].update_many(
|
||
{"$or": [ { 'partner_owner_recid': local_pf_partner_data['recid'], },
|
||
{'recid': local_pf_partner_data['recid'], }]},
|
||
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_partnair_account.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise (partnair_account) à jour n'a été faite")
|
||
|
||
"""
|
||
Verrouiller les compte utilisateurs rattachés à ce compte user_account
|
||
"""
|
||
|
||
updated_user_account = MYSY_GV.dbname['user_account'].update_many(
|
||
{'partner_owner_recid': local_pf_partner_data['recid'], },
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_user_account.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise à jour (user_account) n'a été faite")
|
||
|
||
|
||
"""
|
||
Verrouillage des formations
|
||
"""
|
||
updated_class = MYSY_GV.dbname['myclass'].update_many(
|
||
{'partner_owner_recid': local_pf_partner_data['recid'], },
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_class.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise à jour (myclass) n'a été faite")
|
||
|
||
"""
|
||
# Ajout de l'evenement dans l'historique
|
||
"""
|
||
|
||
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "partnair_account"
|
||
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
history_event_dict['action_description'] = "Compte verrouillé par l’administrateur de la plateforme. "
|
||
|
||
|
||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||
if (local_status is False):
|
||
mycommon.myprint(
|
||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||
|
||
return True, "Tous les comptes associés à ce partenaire ont été verrouillés."
|
||
|
||
|
||
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 verrouiller ce compte "
|
||
|
||
|
||
"""
|
||
Déverrouiller un partenaire, ainsi que les sous comptes associés ainsi que les formations associées
|
||
"""
|
||
def UnLock_PF_partner_account_And_Sub_Accound_from_id(diction):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token', '_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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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', '_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 la liste des arguments ")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
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
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if ("plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if (is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
|
||
|
||
"""
|
||
Le système ne permettra pas de déverrouiller un compte 'is_plateforme_super_admin'.
|
||
On va donc verifier que le compte à verrouiller n'est pas un compte 'is_plateforme_super_admin'
|
||
"""
|
||
local_pf_partner_count = MYSY_GV.dbname['partnair_account'].count_documents(
|
||
{'_id': ObjectId(diction['_id']), 'is_partner_admin_account': '1'})
|
||
|
||
if( local_pf_partner_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du compte partenaire est invalide ")
|
||
return False, " L'identifiant du compte partenaire est invalide "
|
||
|
||
|
||
local_pf_partner_data = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(diction['_id']), 'is_partner_admin_account':'1'})
|
||
if( "plateforme_super_admin" in local_pf_partner_data.keys() and local_pf_partner_data['plateforme_super_admin'] == "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Ce compte est un super-administrateur de la plateforme et ne peut pas être verrouillé. ")
|
||
return False, " Ce compte est un super-administrateur de la plateforme et ne peut pas être verrouillé. ",
|
||
|
||
|
||
new_data = {}
|
||
new_data['update_date'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['lock_raison'] = ""
|
||
new_data['locked'] = "0"
|
||
new_data['locked_date'] = ""
|
||
|
||
updated_partnair_account = MYSY_GV.dbname['partnair_account'].update_many(
|
||
{"$or": [{'partner_owner_recid': local_pf_partner_data['recid'], },
|
||
{'recid': local_pf_partner_data['recid'], }]},
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_partnair_account.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise à jour (updated_partnair_account) n'a été faite")
|
||
|
||
"""
|
||
Verrouiller les compte utilisateurs rattachés à ce compte user_account
|
||
"""
|
||
|
||
updated_user_account = MYSY_GV.dbname['user_account'].update_many(
|
||
{'partner_owner_recid': local_pf_partner_data['recid'], 'lock_raison':'plateforme_admin'},
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_user_account.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise à jour (user_account) n'a été faite")
|
||
|
||
"""
|
||
Verrouillage des formations
|
||
"""
|
||
updated_class = MYSY_GV.dbname['myclass'].update_many(
|
||
{'partner_owner_recid': local_pf_partner_data['recid'], 'lock_raison':'plateforme_admin'},
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_class.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise à jour (myclass) n'a été faite")
|
||
|
||
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "partnair_account"
|
||
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
history_event_dict['action_description'] = "Compte déverrouillé par l’administrateur de la plateforme. "
|
||
|
||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||
if (local_status is False):
|
||
mycommon.myprint(
|
||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||
|
||
return True, "Tous les comptes associés à ce partenaire ont été déverrouillés."
|
||
|
||
|
||
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 verrouiller ce compte "
|
||
|
||
|
||
"""
|
||
Cette fonction permet de passer un compte de 'formation continue' a 'formation initiale' ou inversement
|
||
|
||
"""
|
||
def Change_PF_partner_account_Type_Licence_from_id(diction):
|
||
try:
|
||
# Dictionnaire des champs utilisables
|
||
field_list = ['token', '_id', 'formation_initiale']
|
||
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'existe pas, requete annulée")
|
||
return False, " Impossible de récupérer les informations"
|
||
|
||
'''
|
||
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', '_id', 'formation_initiale']
|
||
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, " Impossible de récupérer les informations"
|
||
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
if( diction['formation_initiale'] not in ['0', '1']):
|
||
mycommon.myprint(str(inspect.stack()[0][
|
||
3]) + " Impossible de determiner l'action à réaliser ")
|
||
return False, " Impossible de determiner l'action à réaliser "
|
||
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
is_plateforme_super_admin = "0"
|
||
if ("plateforme_super_admin" in my_partner.keys()):
|
||
is_plateforme_super_admin = my_partner['plateforme_super_admin']
|
||
|
||
if (is_plateforme_super_admin != "1"):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ")
|
||
return False, " Vous ne disposez pas des droits nécessaires pour accéder à cette fonctionnalité. ",
|
||
|
||
|
||
|
||
"""
|
||
Le système de changer de type de licence uniquement au niveau d'un compte "is_partner_admin_account"
|
||
"""
|
||
local_pf_partner_count = MYSY_GV.dbname['partnair_account'].count_documents(
|
||
{'_id': ObjectId(diction['_id']), 'is_partner_admin_account': '1'})
|
||
|
||
if( local_pf_partner_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du compte partenaire est invalide ")
|
||
return False, " L'identifiant du compte partenaire est invalide "
|
||
|
||
|
||
|
||
new_data = {}
|
||
new_data['update_date'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['formation_initiale'] = diction['formation_initiale']
|
||
|
||
updated_partnair_account = MYSY_GV.dbname['partnair_account'].update_many(
|
||
{'_id': ObjectId(diction['_id']) },
|
||
{'$set': new_data}
|
||
)
|
||
|
||
if (updated_partnair_account.modified_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " WARNING - Aucune mise (partnair_account) à jour n'a été faite")
|
||
|
||
|
||
"""
|
||
# Ajout de l'evenement dans l'historique
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "partnair_account"
|
||
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
history_event_dict['action_description'] = " Changement de licence : 'formation_initiale' = "+str(diction['formation_initiale'])+" "
|
||
|
||
|
||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||
if (local_status is False):
|
||
mycommon.myprint(
|
||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||
|
||
return True, "Tous les comptes associés à ce partenaire ont été verrouillés."
|
||
|
||
|
||
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 changer le type de licence de ce compte "
|
||
|