adhesion: correction API
This commit is contained in:
parent
6a63cc8070
commit
47e7347bfc
|
@ -16,7 +16,9 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os, requests, json, datetime, shutil, quopri, subprocess
|
import os, requests, json, datetime, shutil, quopri, subprocess, base64, os
|
||||||
|
import time, random, string, dateutil.parser, re, pygitea
|
||||||
|
from typing import List
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from requests.auth import HTTPDigestAuth
|
from requests.auth import HTTPDigestAuth
|
||||||
|
|
||||||
|
@ -30,6 +32,7 @@ WELCOME_MAIL_HEADERS="mail_bienvenue_header.txt"
|
||||||
SUMMARY_MAIL="mail_resume.txt"
|
SUMMARY_MAIL="mail_resume.txt"
|
||||||
SENDMAIL_LOCATION = "/usr/sbin/sendmail" # sendmail location
|
SENDMAIL_LOCATION = "/usr/sbin/sendmail" # sendmail location
|
||||||
BUF=[]
|
BUF=[]
|
||||||
|
GITEA_URL = "forge.a-lec.org"
|
||||||
|
|
||||||
# gestion_read("SELECT * FROM services_users su \
|
# gestion_read("SELECT * FROM services_users su \
|
||||||
# INNER JOIN membres m ON m.id = su.id_user \
|
# INNER JOIN membres m ON m.id = su.id_user \
|
||||||
|
@ -64,17 +67,16 @@ def gestion_read(req):
|
||||||
data = req)
|
data = req)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def git_mail_ticket_create(req):
|
def forgejo_post_issue(owner, repo, title, body, labels):
|
||||||
response = requests.post('https://git.a-lec.org/api/v4/projects/46/issues',
|
import_response: requests.Response = gitea_api.post("/repos/" + owner + "/" + repo + "/issues", json={
|
||||||
headers={'PRIVATE-TOKEN' : git_get_secret()},
|
"body": issue.description,
|
||||||
data = req)
|
"labels": labels,
|
||||||
return response.json()
|
"title": issue.title,
|
||||||
|
})
|
||||||
def git_xmpp_ticket_create(req):
|
if not(import_response.ok):
|
||||||
response = requests.post('https://git.a-lec.org/api/v4/projects/44/issues',
|
print("Erreur à l'envoi du ticket {} à {}".format(title, repo))
|
||||||
headers={'PRIVATE-TOKEN' : git_get_secret()},
|
raise(Exception)
|
||||||
data = req)
|
return import_response.ok
|
||||||
return response.json()
|
|
||||||
|
|
||||||
def gestion_adduser(req):
|
def gestion_adduser(req):
|
||||||
response = requests.put('https://gestion.a-lec.org/api/user/import',
|
response = requests.put('https://gestion.a-lec.org/api/user/import',
|
||||||
|
@ -257,10 +259,8 @@ def validate_registrations_worker():
|
||||||
BUF.append("=> MEMBRE VALIDE PAR SECRETARIAT <=")
|
BUF.append("=> MEMBRE VALIDE PAR SECRETARIAT <=")
|
||||||
|
|
||||||
# Launch git tickets
|
# Launch git tickets
|
||||||
request = { 'title' : "Création d'un compte courriel membre n°{}.".format(numero),
|
title = "Création d'un compte courriel membre n°{}.".format(numero)
|
||||||
'labels' : "Nouveau membre",
|
body = "Bonjour,\n Une demande de création de compte de" \
|
||||||
'confidential' : "yes",
|
|
||||||
'description' : "Bonjour,\n Une demande de création de compte de" \
|
|
||||||
+ "courriel ou une redirection a été émise.\n\n" \
|
+ "courriel ou une redirection a été émise.\n\n" \
|
||||||
+ "Compte de courriel actuel : {} \n".format(
|
+ "Compte de courriel actuel : {} \n".format(
|
||||||
email) \
|
email) \
|
||||||
|
@ -268,29 +268,29 @@ def validate_registrations_worker():
|
||||||
member['email']) \
|
member['email']) \
|
||||||
+ "Redirection ('on' si oui, vide si non) : {} \n".format(
|
+ "Redirection ('on' si oui, vide si non) : {} \n".format(
|
||||||
is_redir)
|
is_redir)
|
||||||
}
|
labels = [970]
|
||||||
if not "id" in str(git_mail_ticket_create(request)):
|
ticket_response = forgejo_post_issue("cominfra", "mail", title, body, labels)
|
||||||
|
if not "id" in str(ticket_response):
|
||||||
BUF.append("Validation échouée : ticket git MAIL en erreur : {}".format(
|
BUF.append("Validation échouée : ticket git MAIL en erreur : {}".format(
|
||||||
git_mail_ticket_create(request)
|
ticket_response
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
BUF.append("Ticket courriel ouvert.")
|
BUF.append("Ticket courriel ouvert.")
|
||||||
|
|
||||||
if is_xmpp == "on":
|
if is_xmpp == "on":
|
||||||
request = { 'title' : "Création d'un compte XMPP membre n°{}".format(numero),
|
title = "Création d'un compte XMPP membre n°{}".format(numero)
|
||||||
'labels' : "Nouveau membre",
|
body = "Bonjour,\n Une demande de création de compte XMPP " \
|
||||||
'confidential' : "yes",
|
+ "a été émise.\n\n" \
|
||||||
'description' : "Bonjour,\n Une demande de création de compte" \
|
|
||||||
+ " XMPP a été émise.\n\n" \
|
|
||||||
+ "Compte de courriel actuel : {} \n".format(
|
+ "Compte de courriel actuel : {} \n".format(
|
||||||
email) \
|
email) \
|
||||||
+ "Compte XMPP désiré : {} \n".format(
|
+ "Compte de XMPP désiré : {} \n".format(
|
||||||
member['email'])
|
member['email'])
|
||||||
}
|
labels = [970]
|
||||||
if not "id" in str(git_xmpp_ticket_create(request)):
|
ticket_response = forgejo_post_issue("cominfra", "mail", title, body, labels)
|
||||||
BUF.append("Validation échouée : ticket git MAIL en erreur : {}".format(
|
if not "id" in str(ticket_response):
|
||||||
git_xmpp_ticket_create(request)
|
BUF.append("Validation échouée : ticket git XMPP en erreur : {}".format(
|
||||||
|
ticket_response
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -315,6 +315,7 @@ def validate_registrations_worker():
|
||||||
pass
|
pass
|
||||||
os.rename(registration, registration.replace("attente", "valide"))
|
os.rename(registration, registration.replace("attente", "valide"))
|
||||||
|
|
||||||
|
FORGE = pygitea.API(GITEA_URL, token=gestion_get_secret())
|
||||||
def main():
|
def main():
|
||||||
setup_workdir()
|
setup_workdir()
|
||||||
new_registrations_worker()
|
new_registrations_worker()
|
||||||
|
|
Loading…
Reference in New Issue