def add_participant( self, team_drive_or_file_id: str, participants: List[str], role: str = "owner", user_type: str = "user", ): """Adds participants to existing Google Drive.""" client = get_service(self.configuration, "drive", "v3", self.scopes) for p in participants: add_permission(client, p, team_drive_or_file_id, role, user_type)
def create_file( self, parent_id: str, name: str, participants: List[str] = [], role: str = Roles.writer.value, file_type: str = "folder", ): """Creates a new file in existing Google Drive.""" client = get_service("drive", "v3", self.scopes) response = create_file(client, parent_id, name, participants, role, file_type) response["weblink"] = response["webViewLink"] return response
def create( self, name: str, description: str = None, title: str = None, participants: List[str] = [] ): """Create a new event.""" client = get_service("calendar", "v3", self.scopes) conference = create_event( client, name, description=description, participants=participants, title=title ) meet_url = "" for entry_point in conference["conferenceData"]["entryPoints"]: if entry_point["entryPointType"] == "video": meet_url = entry_point["uri"] return {"weblink": meet_url, "id": conference["id"], "challenge": ""}
def create( self, name: str, participants: List[str], description: str = None, role: str = "MEMBER" ): """Creates a new Google Group.""" client = get_service("admin", "directory_v1", self.scopes) group_key = f"{name.lower()}@{GOOGLE_DOMAIN}" if not description: description = "Group automatically created by Dispatch." group = create_group(client, name, group_key, description) for p in participants: add_member(client, group_key, p, role) group.update( { "weblink": f"https://groups.google.com/a/{GOOGLE_DOMAIN}/forum/#!forum/{group['name']}" } ) return group
def send( self, recipient: str, notification_text: str, notification_template: dict, notification_type: MessageType, items: Optional[List] = None, **kwargs, ): """Sends an html email based on the type.""" # TODO allow for bulk sending (kglisson) client = get_service(self.configuration, "gmail", "v1", self.scopes) subject = notification_text if kwargs.get("name"): subject = f"{kwargs['name'].upper()} - {notification_text}" if kwargs.get("subject"): subject = kwargs["subject"] cc = "" if kwargs.get("cc"): cc = kwargs["cc"] if not items: message_body = create_message_body(notification_template, notification_type, **kwargs) else: message_body = create_multi_message_body( notification_template, notification_type, items, **kwargs ) html_message = create_html_message( self.configuration.service_account_delegated_account, recipient, cc, subject, message_body, ) return send_message(client, html_message)
def remove(self, email: str, participants: List[str]): """Removes participants from existing Google Group.""" client = get_service("admin", "directory_v1", self.scopes) for p in participants: remove_member(client, email, p)
def add(self, email: str, participants: List[str], role: str = "MEMBER"): """Adds participants to existing Google Group.""" client = get_service("admin", "directory_v1", self.scopes) for p in participants: add_member(client, email, p, role)
def list(self, **kwargs): """Lists all available team drives.""" client = get_service("drive", "v3", self.scopes) return list_team_drives(client, **kwargs)
def get(self, file_id: str, mime_type=None): """Fetches document text.""" client = get_service("drive", "v3", self.scopes) return download_google_document(client, file_id, mime_type=mime_type)
def restrict(self, team_drive_id: str): """Applies a set of restrictions and capabilities to the team drive.""" client = get_service("drive", "v3", self.scopes) response = restrict_team_drive(client, team_drive_id) return response
def create(self, name: str, participants: List[str], role: str = Roles.file_organizer.value): """Creates a new Google Drive.""" client = get_service("drive", "v3", self.scopes) response = create_team_drive(client, name, participants, role) response["weblink"] = f"https://drive.google.com/drive/folders/{response['id']}" return response
def delete_file(self, team_drive_id: str, file_id: str): """Removes a file from existing Google Drive.""" client = get_service("drive", "v3", self.scopes) response = delete_file(client, team_drive_id, file_id) response["weblink"] = response["webViewLink"] return response
def __init__(self): scopes = ["https://www.googleapis.com/auth/calendar"] self.client = get_service("calendar", "v3", scopes).events()
def open(self, folder_id: str): """Adds the domain permission to the folder.""" client = get_service("drive", "v3", self.scopes) add_domain_permission(client, folder_id, GOOGLE_DOMAIN)
def update(self, file_id: str, task_id: str, content: str = None, resolved: bool = False): """Updates an existing task.""" client = get_service("drive", "v3", self.scopes) return add_reply(client, file_id, task_id, content, resolved)
def create_file(self, team_drive_id: str, name: str, file_type: str = "folder"): """Creates a new file in existing Google Drive.""" client = get_service("drive", "v3", self.scopes) response = create_file(client, team_drive_id, name, file_type) response["weblink"] = response["webViewLink"] return response
def delete(self, email: str): """Deletes an existing google group.""" client = get_service("admin", "directory_v1", self.scopes) delete_group(client, email)
def move_file(self, new_team_drive_id: str, file_id: str): """Moves a file from one team drive to another.""" client = get_service("drive", "v3", self.scopes) response = move_file(client, new_team_drive_id, file_id) response["weblink"] = response["webViewLink"] return response
def __init__(self): scopes = ["https://mail.google.com/"] self.client = get_service("gmail", "v1", scopes)
def archive(self, source_team_drive_id: str, dest_team_drive_id: str, folder_name: str): """Archives a shared team drive to a specific folder.""" client = get_service("drive", "v3", self.scopes) response = archive_team_drive(client, source_team_drive_id, dest_team_drive_id, folder_name) return response
def copy_file(self, team_drive_id: str, file_id: str, name: str): """Creates a copy of the given file and places it in the specified team drive.""" client = get_service("drive", "v3", self.scopes) response = copy_file(client, team_drive_id, file_id, name) response["weblink"] = response["webViewLink"] return response
def delete(self, event_id: str): """Deletes an existing event.""" client = get_service("calendar", "v3", self.scopes) return delete_event(client, event_id)
def list_files(self, team_drive_id: str, q: str = None): """Lists all files in team drive.""" client = get_service("drive", "v3", self.scopes) return list_files(client, team_drive_id, q)
def add_participant(self, event_id: str, participant: str): """Adds a new participant to event.""" client = get_service("calendar", "v3", self.scopes) return add_participant(client, event_id, participant)
def list(self, file_id: str, **kwargs): """Lists all available tasks.""" client = get_service("drive", "v3", self.scopes) return list_tasks(client, file_id)
def remove_participant(self, event_id: str, participant: str): """Removes a participant from event.""" client = get_service("calendar", "v3", self.scopes) return remove_participant(client, event_id, participant)
def delete(self, team_drive_id: str, empty: bool = True): """Deletes a Google Drive.""" client = get_service("drive", "v3", self.scopes) return delete_team_drive(client, team_drive_id, empty)
def list(self, email: str): """Lists members from an existing Google Group.""" client = get_service("admin", "directory_v1", self.scopes) members = list_members(client, email) return [m["email"] for m in members["members"]]
def remove_participant(self, team_drive_id: str, participants: List[str]): """Removes participants from existing Google Drive.""" client = get_service("drive", "v3", self.scopes) for p in participants: remove_permission(client, p, team_drive_id)
def update(self, document_id: str, **kwargs): """Replaces text in document.""" # TODO escape and use f strings? (kglisson) kwargs = {"{{" + k + "}}": v for k, v in kwargs.items()} client = get_service("docs", "v1", self.scopes).documents() return replace_text(client, document_id, kwargs)