paheko standby
This commit is contained in:
		@@ -1,9 +1,11 @@
 | 
				
			|||||||
 | 
					import re
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .config import getDockersConfig, getSecretConfig
 | 
					from .config import getDockersConfig, getSecretConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
paheko_ident = getDockersConfig("paheko_API_USER")
 | 
					paheko_ident = getDockersConfig("paheko_API_USER")
 | 
				
			||||||
paheko_pass = getDockersConfig("paheko_API_PASSWORD")
 | 
					paheko_pass = getDockersConfig("paheko_API_PASSWORD")
 | 
				
			||||||
 | 
					paheko_auth = (paheko_ident, paheko_pass)
 | 
				
			||||||
paheko_url = f"https://kaz-paheko.{getDockersConfig('domain')}"
 | 
					paheko_url = f"https://kaz-paheko.{getDockersConfig('domain')}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Paheko:
 | 
					class Paheko:
 | 
				
			||||||
@@ -11,12 +13,9 @@ class Paheko:
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        Récupérer les catégories Paheko avec le compteur associé
 | 
					        Récupérer les catégories Paheko avec le compteur associé
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        global paheko_ident, paheko_pass, paheko_url
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        auth = (paheko_ident, paheko_pass)
 | 
					 | 
				
			||||||
        api_url = paheko_url + '/api/user/categories'
 | 
					        api_url = paheko_url + '/api/user/categories'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        response = requests.get(api_url, auth=auth)
 | 
					        response = requests.get(api_url, auth=paheko_auth)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if response.status_code == 200:
 | 
					        if response.status_code == 200:
 | 
				
			||||||
            data = response.json()
 | 
					            data = response.json()
 | 
				
			||||||
@@ -29,16 +28,12 @@ class Paheko:
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        Afficher les membres d'une catégorie Paheko
 | 
					        Afficher les membres d'une catégorie Paheko
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					 | 
				
			||||||
        global paheko_ident, paheko_pass, paheko_url
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        auth = (paheko_ident, paheko_pass)
 | 
					 | 
				
			||||||
        if not categorie.isdigit():
 | 
					        if not categorie.isdigit():
 | 
				
			||||||
            return 'Id de category non valide', 400
 | 
					            return 'Id de category non valide', 400
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        api_url = paheko_url + '/api/user/category/'+categorie+'.json'
 | 
					        api_url = paheko_url + '/api/user/category/'+categorie+'.json'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        response = requests.get(api_url, auth=auth)
 | 
					        response = requests.get(api_url, auth=paheko_auth)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if response.status_code == 200:
 | 
					        if response.status_code == 200:
 | 
				
			||||||
            data = response.json()
 | 
					            data = response.json()
 | 
				
			||||||
@@ -56,17 +51,17 @@ class Paheko:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if emailmatchregexp.match(ident):
 | 
					        if emailmatchregexp.match(ident):
 | 
				
			||||||
          data = { "sql": f"select * from users where email='{ident}' or alias = '{ident}'" }
 | 
					          data = { "sql": f"select * from users where email='{ident}' or alias = '{ident}'" }
 | 
				
			||||||
          api_url = self.paheko_url + '/api/sql/'
 | 
					          api_url = paheko_url + '/api/sql/'
 | 
				
			||||||
          response = requests.post(api_url, auth=self.auth,  data=data)
 | 
					          response = requests.post(api_url, auth=paheko_auth,  data=data)
 | 
				
			||||||
          #TODO: if faut Rechercher count et vérifier que = 1 et supprimer le count=1 dans la réponse
 | 
					          #TODO: if faut Rechercher count et vérifier que = 1 et supprimer le count=1 dans la réponse
 | 
				
			||||||
        elif  ident.isdigit():
 | 
					        elif  ident.isdigit():
 | 
				
			||||||
          api_url = self.paheko_url + '/api/user/'+ident
 | 
					          api_url = paheko_url + '/api/user/'+ident
 | 
				
			||||||
          response = requests.get(api_url, auth=self.auth)
 | 
					          response = requests.get(api_url, auth=paheko_auth)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
          nomorga = re.sub(r'\W+', '', ident) # on vire les caractères non alphanumérique
 | 
					          nomorga = re.sub(r'\W+', '', ident) # on vire les caractères non alphanumérique
 | 
				
			||||||
          data = { "sql": f"select * from users where admin_orga=1 and nom_orga='{nomorga}'" }
 | 
					          data = { "sql": f"select * from users where admin_orga=1 and nom_orga='{nomorga}'" }
 | 
				
			||||||
          api_url = self.paheko_url + '/api/sql/'
 | 
					          api_url = paheko_url + '/api/sql/'
 | 
				
			||||||
          response = requests.post(api_url, auth=self.auth,  data=data)
 | 
					          response = requests.post(api_url, auth=paheko_auth,  data=data)
 | 
				
			||||||
          #TODO:if faut Rechercher count et vérifier que = 1  et supprimer le count=1 dans la réponse
 | 
					          #TODO:if faut Rechercher count et vérifier que = 1  et supprimer le count=1 dans la réponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if response.status_code == 200:
 | 
					        if response.status_code == 200:
 | 
				
			||||||
@@ -90,8 +85,8 @@ class Paheko:
 | 
				
			|||||||
        emailmatchregexp = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
 | 
					        emailmatchregexp = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
 | 
				
			||||||
        if emailmatchregexp.match(ident):
 | 
					        if emailmatchregexp.match(ident):
 | 
				
			||||||
          data = { "sql": f"select id from users where email='{ident}'" }
 | 
					          data = { "sql": f"select id from users where email='{ident}'" }
 | 
				
			||||||
          api_url = self.paheko_url + '/api/sql/'
 | 
					          api_url = paheko_url + '/api/sql/'
 | 
				
			||||||
          response = requests.post(api_url, auth=self.auth, data=data)
 | 
					          response = requests.post(api_url, auth=paheko_auth, data=data)
 | 
				
			||||||
          if response.status_code == 200:
 | 
					          if response.status_code == 200:
 | 
				
			||||||
              #on extrait l'id de la réponse
 | 
					              #on extrait l'id de la réponse
 | 
				
			||||||
              data = response.json()
 | 
					              data = response.json()
 | 
				
			||||||
@@ -116,9 +111,9 @@ class Paheko:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        champ = re.sub(r'\W+','',field) # pas de caractères non alphanumériques ici, dans l'idéal, c'est à choisir dans une liste plutot
 | 
					        champ = re.sub(r'\W+','',field) # pas de caractères non alphanumériques ici, dans l'idéal, c'est à choisir dans une liste plutot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        api_url = self.paheko_url + '/api/user/'+str(ident)
 | 
					        api_url = paheko_url + '/api/user/'+str(ident)
 | 
				
			||||||
        payload = {champ: valeur}
 | 
					        payload = {champ: valeur}
 | 
				
			||||||
        response = requests.post(api_url, auth=self.auth, data=payload)
 | 
					        response = requests.post(api_url, auth=paheko_auth, data=payload)
 | 
				
			||||||
        return response.json()
 | 
					        return response.json()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -126,11 +121,10 @@ class Paheko:
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        retourne tous les membres de paheko avec une action à mener (création du compte kaz / modification...)
 | 
					        retourne tous les membres de paheko avec une action à mener (création du compte kaz / modification...)
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        auth = (paheko_ident, paheko_pass)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        api_url = paheko_url + '/api/sql/'
 | 
					        api_url = paheko_url + '/api/sql/'
 | 
				
			||||||
        payload = { "sql": f"select * from users where action_auto='{action}'" }
 | 
					        payload = { "sql": f"select * from users where action_auto='{action}'" }
 | 
				
			||||||
        response = requests.post(api_url, auth=auth,  data=payload)
 | 
					        response = requests.post(api_url, auth=paheko_auth,  data=payload)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if response.status_code == 200:
 | 
					        if response.status_code == 200:
 | 
				
			||||||
            return response.json()
 | 
					            return response.json()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,8 +109,8 @@ def create_user(email, email_secours, admin_orga, nom_orga, quota_disque, nom, p
 | 
				
			|||||||
    # mail.send(msg)
 | 
					    # mail.send(msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #on met le flag paheko action à Aucune
 | 
					    #on met le flag paheko action à Aucune
 | 
				
			||||||
    paheko = Paheko()
 | 
					    # paheko = Paheko()
 | 
				
			||||||
    paheko.set_user(email, "action_auto", "Aucune")
 | 
					    # paheko.set_user(email, "action_auto", "Aucune")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #on post sur MM pour dire ok
 | 
					    #on post sur MM pour dire ok
 | 
				
			||||||
    with Mattermost() as mm:
 | 
					    with Mattermost() as mm:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user