directory api working state
This commit is contained in:
@@ -23,9 +23,13 @@ from sikweb.settings import (
|
||||
DEFAULT_EMAIL_FROM,
|
||||
DEFAULT_EMAIL_FROM_ADDR,
|
||||
ENABLE_AUTOMATIC_EMAILS,
|
||||
GROUP_KEY,
|
||||
)
|
||||
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 +123,23 @@ 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):
|
||||
try:
|
||||
# get data
|
||||
SCOPES = ["https://www.googleapis.com/auth/admin.directory.group"]
|
||||
SERVICE_ACCOUNT_FILE = "google-service-cred.json"
|
||||
|
||||
# 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_file(
|
||||
filename=SERVICE_ACCOUNT_FILE, 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:
|
||||
logging.exception("Something fukd: {}".format(err.error_details))
|
||||
return err.error_details.message
|
||||
|
||||
|
||||
Reference in New Issue
Block a user