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
|
||||
# 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 HTTPDigestAuth
|
||||
|
||||
|
@ -30,6 +32,7 @@ WELCOME_MAIL_HEADERS="mail_bienvenue_header.txt"
|
|||
SUMMARY_MAIL="mail_resume.txt"
|
||||
SENDMAIL_LOCATION = "/usr/sbin/sendmail" # sendmail location
|
||||
BUF=[]
|
||||
GITEA_URL = "forge.a-lec.org"
|
||||
|
||||
# gestion_read("SELECT * FROM services_users su \
|
||||
# INNER JOIN membres m ON m.id = su.id_user \
|
||||
|
@ -64,17 +67,16 @@ def gestion_read(req):
|
|||
data = req)
|
||||
return response.json()
|
||||
|
||||
def git_mail_ticket_create(req):
|
||||
response = requests.post('https://git.a-lec.org/api/v4/projects/46/issues',
|
||||
headers={'PRIVATE-TOKEN' : git_get_secret()},
|
||||
data = req)
|
||||
return response.json()
|
||||
|
||||
def git_xmpp_ticket_create(req):
|
||||
response = requests.post('https://git.a-lec.org/api/v4/projects/44/issues',
|
||||
headers={'PRIVATE-TOKEN' : git_get_secret()},
|
||||
data = req)
|
||||
return response.json()
|
||||
def forgejo_post_issue(owner, repo, title, body, labels):
|
||||
import_response: requests.Response = gitea_api.post("/repos/" + owner + "/" + repo + "/issues", json={
|
||||
"body": issue.description,
|
||||
"labels": labels,
|
||||
"title": issue.title,
|
||||
})
|
||||
if not(import_response.ok):
|
||||
print("Erreur à l'envoi du ticket {} à {}".format(title, repo))
|
||||
raise(Exception)
|
||||
return import_response.ok
|
||||
|
||||
def gestion_adduser(req):
|
||||
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 <=")
|
||||
|
||||
# Launch git tickets
|
||||
request = { 'title' : "Création d'un compte courriel membre n°{}.".format(numero),
|
||||
'labels' : "Nouveau membre",
|
||||
'confidential' : "yes",
|
||||
'description' : "Bonjour,\n Une demande de création de compte de" \
|
||||
title = "Création d'un compte courriel membre n°{}.".format(numero)
|
||||
body = "Bonjour,\n Une demande de création de compte de" \
|
||||
+ "courriel ou une redirection a été émise.\n\n" \
|
||||
+ "Compte de courriel actuel : {} \n".format(
|
||||
email) \
|
||||
|
@ -268,29 +268,29 @@ def validate_registrations_worker():
|
|||
member['email']) \
|
||||
+ "Redirection ('on' si oui, vide si non) : {} \n".format(
|
||||
is_redir)
|
||||
}
|
||||
if not "id" in str(git_mail_ticket_create(request)):
|
||||
labels = [970]
|
||||
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(
|
||||
git_mail_ticket_create(request)
|
||||
ticket_response
|
||||
))
|
||||
continue
|
||||
else:
|
||||
BUF.append("Ticket courriel ouvert.")
|
||||
|
||||
if is_xmpp == "on":
|
||||
request = { 'title' : "Création d'un compte XMPP membre n°{}".format(numero),
|
||||
'labels' : "Nouveau membre",
|
||||
'confidential' : "yes",
|
||||
'description' : "Bonjour,\n Une demande de création de compte" \
|
||||
+ " XMPP a été émise.\n\n" \
|
||||
title = "Création d'un compte XMPP membre n°{}".format(numero)
|
||||
body = "Bonjour,\n Une demande de création de compte XMPP " \
|
||||
+ "a été émise.\n\n" \
|
||||
+ "Compte de courriel actuel : {} \n".format(
|
||||
email) \
|
||||
+ "Compte XMPP désiré : {} \n".format(
|
||||
+ "Compte de XMPP désiré : {} \n".format(
|
||||
member['email'])
|
||||
}
|
||||
if not "id" in str(git_xmpp_ticket_create(request)):
|
||||
BUF.append("Validation échouée : ticket git MAIL en erreur : {}".format(
|
||||
git_xmpp_ticket_create(request)
|
||||
labels = [970]
|
||||
ticket_response = forgejo_post_issue("cominfra", "mail", title, body, labels)
|
||||
if not "id" in str(ticket_response):
|
||||
BUF.append("Validation échouée : ticket git XMPP en erreur : {}".format(
|
||||
ticket_response
|
||||
))
|
||||
continue
|
||||
else:
|
||||
|
@ -315,6 +315,7 @@ def validate_registrations_worker():
|
|||
pass
|
||||
os.rename(registration, registration.replace("attente", "valide"))
|
||||
|
||||
FORGE = pygitea.API(GITEA_URL, token=gestion_get_secret())
|
||||
def main():
|
||||
setup_workdir()
|
||||
new_registrations_worker()
|
||||
|
|
Loading…
Reference in New Issue