Resolve conlict
This commit is contained in:
@@ -18,14 +18,21 @@ from sendgrid.helpers.mail import (
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.files.base import ContentFile
|
||||
from sikweb.settings import (
|
||||
DEPLOY_ENV,
|
||||
FRONTEND_URL,
|
||||
EMAIL_API_KEY,
|
||||
DEFAULT_EMAIL_FROM,
|
||||
DEFAULT_EMAIL_FROM_ADDR,
|
||||
ENABLE_AUTOMATIC_EMAILS,
|
||||
GROUP_KEY,
|
||||
GOOGLE_SERVICE_ACCOUNT,
|
||||
)
|
||||
from datetime import timedelta
|
||||
|
||||
from google.oauth2 import service_account
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
|
||||
|
||||
def get_file_extension(file_name, decoded_file):
|
||||
extension = imghdr.what(file_name, decoded_file)
|
||||
@@ -119,3 +126,34 @@ def send_signup_email(to, subject, id, uuid, content):
|
||||
def admin_send_email_signupees(list, subject, content):
|
||||
for to in list:
|
||||
send_email(to.email, subject, markdown.markdown(content), True)
|
||||
|
||||
|
||||
def add_to_mailinglist(email: str):
|
||||
try:
|
||||
# get data
|
||||
SCOPES = ["https://www.googleapis.com/auth/admin.directory.group"]
|
||||
|
||||
# create credentials, with subject is used to impersonate admin account
|
||||
# jas_manager has groups editor rights in google admin
|
||||
credentials = service_account.Credentials.from_service_account_info(
|
||||
info=GOOGLE_SERVICE_ACCOUNT, scopes=SCOPES
|
||||
).with_subject("jas_manager@sahkoinsinoorikilta.fi")
|
||||
|
||||
service = build("admin", "directory_v1", credentials=credentials)
|
||||
service.members().insert(groupKey=GROUP_KEY, body={"email": email}).execute()
|
||||
except HttpError as err:
|
||||
# Already in list, do nothing
|
||||
if err.status_code == 409:
|
||||
pass
|
||||
else:
|
||||
logging.exception("Failed adding user to list")
|
||||
|
||||
# Send email notificcation to maintainer, only in prod
|
||||
if DEPLOY_ENV == "production":
|
||||
to = "ilari.ojakorpi@sahkoinsinoorikilta.fi"
|
||||
subject = "Web error: Failed adding to google groups"
|
||||
body = "Error code: {}\nError details: {}\nEmail that was not added: {}\n\nAdd user manually to jäsenet groups.".format(
|
||||
err.status_code, err.error_details, email
|
||||
)
|
||||
|
||||
send_email(to, subject, body)
|
||||
|
||||
Reference in New Issue
Block a user