Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 184b41ea authored by ANDRADE-BARROSO Guillermo's avatar ANDRADE-BARROSO Guillermo Committed by SIMONIN Matthieu
Browse files

first version of share project fonctions

parent a72406a6
No related branches found
No related tags found
No related merge requests found
......@@ -359,6 +359,7 @@ class SyncClient:
# TODO(msimonin): return type
return r
# TODO: check if this fonction is still usefull (in regard to get_doc)
def get_document(self, project_id, doc_id):
"""Get a single document (e.g tex file).
......@@ -533,6 +534,30 @@ class SyncClient:
raise Exception(f"Uploading {path} fails")
return response
def share(self, project_id, email, can_edit=True):
"""Send a invitation to share (edit/view) a project.
Args:
project_id (str): The project id of the project to share
email (str): Email of the recipient of the invitation
can_edit (boolean):True (resp. False) gives read/write (resp. read-only) access to the project
Returns:
response (dict) status of the request as returned by sharelatex
Raises:
Exception if something is wrong with the compilation
"""
url = f"{self.base_url}/project/{project_id}/invite"
data = {
"email":email,
"privileges": "readAndWrite" if can_edit else "readOnly",
"_csrf": self.csrf}
r = self.client.post(url, data=data, verify=self.verify)
r.raise_for_status()
response = r.json()
return response
def compile(self, project_id):
"""Trigger a remote compilation.
......
......@@ -255,6 +255,27 @@ def compile(project_id):
print(response)
@cli.command(help="Send a invitation to share (edit/view) a project")
@click.argument("email", default="")
@click.option("--project_id", default=None)
@click.option(
"--can-edit/--read-only",
default=True,
help="""Authorize user to edit the project or not""",
)
def share(project_id, email, can_edit):
repo = Repo()
base_url, project_id = refresh_project_information(repo,project_id=project_id)
username, password = refresh_account_information(repo)
client = SyncClient(
base_url=base_url, username=username, password=password, verify=True
)
response = client.share(project_id, email, can_edit)
print(response)
@cli.command(
help=f"""Pull the files from sharelatex.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment