Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
    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": ""}
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def list(self, **kwargs):
     """Lists all available team drives."""
     client = get_service("drive", "v3", self.scopes)
     return list_team_drives(client, **kwargs)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def __init__(self):
     scopes = ["https://www.googleapis.com/auth/calendar"]
     self.client = get_service("calendar", "v3", scopes).events()
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
 def delete(self, email: str):
     """Deletes an existing google group."""
     client = get_service("admin", "directory_v1", self.scopes)
     delete_group(client, email)
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
 def __init__(self):
     scopes = ["https://mail.google.com/"]
     self.client = get_service("gmail", "v1", scopes)
Ejemplo n.º 20
0
 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
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
 def delete(self, event_id: str):
     """Deletes an existing event."""
     client = get_service("calendar", "v3", self.scopes)
     return delete_event(client, event_id)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
 def list(self, file_id: str, **kwargs):
     """Lists all available tasks."""
     client = get_service("drive", "v3", self.scopes)
     return list_tasks(client, file_id)
Ejemplo n.º 26
0
 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)
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
0
 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"]]
Ejemplo n.º 29
0
 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)
Ejemplo n.º 30
0
 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)