mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 04:41:35 +00:00
Put send_email back for todrive, update OAUTH2_SCOPES (#288)
* Put send-email back for todrive, update scopes * Use loop instead of list comprehension for selected_scopes * Engage brain fully before commit
This commit is contained in:
25
src/gam.py
25
src/gam.py
@@ -8180,6 +8180,20 @@ def doDeleteOrg():
|
|||||||
print u"Deleting organization %s" % name
|
print u"Deleting organization %s" % name
|
||||||
callGAPI(cd.orgunits(), u'delete', customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=name)
|
callGAPI(cd.orgunits(), u'delete', customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=name)
|
||||||
|
|
||||||
|
# Send an email
|
||||||
|
def send_email(msg_subj, msg_txt, msg_rcpt=None):
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
gmail = buildGAPIObject(u'gmail')
|
||||||
|
sender_email = gmail._http.request.credentials.id_token[u'email']
|
||||||
|
if not msg_rcpt:
|
||||||
|
msg_rcpt = sender_email
|
||||||
|
msg = MIMEText(msg_txt)
|
||||||
|
msg[u'Subject'] = msg_subj
|
||||||
|
msg[u'From'] = sender_email
|
||||||
|
msg[u'To'] = msg_rcpt
|
||||||
|
callGAPI(gmail.users().messages(), u'send',
|
||||||
|
userId=sender_email, body={u'raw': base64.urlsafe_b64encode(msg.as_string())})
|
||||||
|
|
||||||
# Write a CSV file
|
# Write a CSV file
|
||||||
def addTitleToCSVfile(title, titles):
|
def addTitleToCSVfile(title, titles):
|
||||||
titles.append(title)
|
titles.append(title)
|
||||||
@@ -8263,6 +8277,8 @@ def writeCSVfile(csvRows, titles, list_type, todrive):
|
|||||||
file_url = result[u'alternateLink']
|
file_url = result[u'alternateLink']
|
||||||
if GC_Values[GC_NO_BROWSER]:
|
if GC_Values[GC_NO_BROWSER]:
|
||||||
msg_txt = u'Drive file uploaded to:\n %s' % file_url
|
msg_txt = u'Drive file uploaded to:\n %s' % file_url
|
||||||
|
msg_subj = u'%s - %s' % (GC_Values[GC_DOMAIN], list_type)
|
||||||
|
send_email(msg_subj, msg_txt)
|
||||||
print msg_txt
|
print msg_txt
|
||||||
else:
|
else:
|
||||||
import webbrowser
|
import webbrowser
|
||||||
@@ -9461,14 +9477,18 @@ OAUTH2_SCOPES = [
|
|||||||
u'subscopes': [],
|
u'subscopes': [],
|
||||||
u'scopes': u'https://www.googleapis.com/auth/admin.directory.notifications'},
|
u'scopes': u'https://www.googleapis.com/auth/admin.directory.notifications'},
|
||||||
{u'name': u'Site Verification API',
|
{u'name': u'Site Verification API',
|
||||||
|
u'offByDefault': True,
|
||||||
u'subscopes': [],
|
u'subscopes': [],
|
||||||
u'scopes': u'https://www.googleapis.com/auth/siteverification'},
|
u'scopes': u'https://www.googleapis.com/auth/siteverification'},
|
||||||
|
{u'name': u'Gmail API - send report docs todrive notifications only',
|
||||||
|
u'subscopes': [],
|
||||||
|
u'scopes': u'https://www.googleapis.com/auth/gmail.send'},
|
||||||
{u'name': u'User Schema Directory API',
|
{u'name': u'User Schema Directory API',
|
||||||
u'subscopes': [u'readonly'],
|
u'subscopes': [u'readonly'],
|
||||||
u'scopes': u'https://www.googleapis.com/auth/admin.directory.userschema'},
|
u'scopes': u'https://www.googleapis.com/auth/admin.directory.userschema'},
|
||||||
{u'name': u'Classroom API - counts as 5 scopes',
|
{u'name': u'Classroom API - counts as 5 scopes',
|
||||||
u'subscopes': [],
|
u'subscopes': [],
|
||||||
u'scopes': [u'https://www.googleapis.com/auth/classroom.rosters', # 17:Classroom API
|
u'scopes': [u'https://www.googleapis.com/auth/classroom.rosters',
|
||||||
u'https://www.googleapis.com/auth/classroom.courses',
|
u'https://www.googleapis.com/auth/classroom.courses',
|
||||||
u'https://www.googleapis.com/auth/classroom.profile.emails',
|
u'https://www.googleapis.com/auth/classroom.profile.emails',
|
||||||
u'https://www.googleapis.com/auth/classroom.profile.photos',
|
u'https://www.googleapis.com/auth/classroom.profile.photos',
|
||||||
@@ -9490,7 +9510,6 @@ OAUTH2_SCOPES = [
|
|||||||
u'scopes': u'https://www.googleapis.com/auth/admin.directory.rolemanagement'},
|
u'scopes': u'https://www.googleapis.com/auth/admin.directory.rolemanagement'},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
OAUTH2_MENU = u'''
|
OAUTH2_MENU = u'''
|
||||||
Select the authorized scopes by entering a number.
|
Select the authorized scopes by entering a number.
|
||||||
Append an 'r' to grant read-only access or an 'a' to grant action-only access.
|
Append an 'r' to grant read-only access or an 'a' to grant action-only access.
|
||||||
@@ -9548,7 +9567,7 @@ See this site for instructions:
|
|||||||
menu = OAUTH2_MENU % tuple(range(num_scopes))
|
menu = OAUTH2_MENU % tuple(range(num_scopes))
|
||||||
selected_scopes = []
|
selected_scopes = []
|
||||||
for scope in OAUTH2_SCOPES:
|
for scope in OAUTH2_SCOPES:
|
||||||
if u'offByDefault' in scope:
|
if scope.get(u'offByDefault', False):
|
||||||
selected_scopes.append(u' ')
|
selected_scopes.append(u' ')
|
||||||
else:
|
else:
|
||||||
selected_scopes.append(u'*')
|
selected_scopes.append(u'*')
|
||||||
|
|||||||
Reference in New Issue
Block a user