mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
Client side integration for ShareWorkspace endpoint
Summary: This diff adds the necessary code changes to integrate the client with the `ShareWorkspace` endpoint on the `CommitCloud` service. The command `hg cloud share` can be used by workspace owners to provide access to their workspaces to other users. Reviewed By: liubov-dmitrieva Differential Revision: D39609834 fbshipit-source-id: f8c4781848d2d18023516cf9242ac518e903f88e
This commit is contained in:
parent
a47fef4ec3
commit
210d0f5723
@ -256,6 +256,10 @@ class BaseService(pycompat.ABC):
|
||||
def renameworkspace(self, reponame, workspace, new_workspace):
|
||||
"""Rename the given workspace"""
|
||||
|
||||
@abstractmethod
|
||||
def shareworkspace(self, reponame, workspace):
|
||||
"""Enable sharing for the given workspace"""
|
||||
|
||||
@staticmethod
|
||||
def _makesmartloginfo(data):
|
||||
"""Returns a SmartlogInfo that supports DAG operations like heads, parents,
|
||||
|
@ -129,6 +129,7 @@ subcmd = cloud.subcommand(
|
||||
["backup", "check"],
|
||||
),
|
||||
("Manage automatic backup or sync", ["disable", "enable"]),
|
||||
("Enable sharing for a cloud workspace", ["share"]),
|
||||
]
|
||||
)
|
||||
|
||||
@ -1462,6 +1463,19 @@ def backupdisable(ui, repo, **opts):
|
||||
return 0
|
||||
|
||||
|
||||
@subcmd("share")
|
||||
def shareworkspace(ui, repo, **opts):
|
||||
"""Marks the given workspace for sharing and prints out the corresponding ACL"""
|
||||
workspacename = workspace.currentworkspace(repo)
|
||||
if workspacename is None:
|
||||
ui.write(_("You are not connected to any workspace\n"))
|
||||
return
|
||||
sharing_data = service.get(ui, tokenmod.TokenLocator(ui).token).shareworkspace(
|
||||
ccutil.getreponame(repo), workspacename
|
||||
)
|
||||
ui.write(sharing_data["sharing_message"] + "\n")
|
||||
|
||||
|
||||
@subcmd("status")
|
||||
def cloudstatus(ui, repo, **opts):
|
||||
"""Shows information about the state of the user's workspace"""
|
||||
|
@ -523,6 +523,18 @@ class _HttpsCommitCloudService(baseservice.BaseService):
|
||||
}
|
||||
self._timedsend(path, data)
|
||||
|
||||
@perftrace.tracefunc("Share Workspace")
|
||||
def shareworkspace(self, reponame, workspace):
|
||||
"""Enable sharing for the given workspace"""
|
||||
self.ui.debug("sending 'share_workspace' request\n", component="commitcloud")
|
||||
path = "/commit_cloud/share_workspace"
|
||||
data = {
|
||||
"repo_name": reponame,
|
||||
"workspace": workspace,
|
||||
}
|
||||
response = self._timedsend(path, data)
|
||||
return response["sharing_data"]
|
||||
|
||||
|
||||
# Make sure that the HttpsCommitCloudService is a singleton
|
||||
HttpsCommitCloudService = baseservice.SingletonDecorator(_HttpsCommitCloudService)
|
||||
|
@ -326,6 +326,10 @@ class _LocalService(baseservice.BaseService):
|
||||
else:
|
||||
raise error.Abort(_("unknown workspace: %s") % workspace)
|
||||
|
||||
def shareworkspace(self, reponame, workspace):
|
||||
"""Enable sharing for the given workspace"""
|
||||
raise NotImplementedError # Since auth is disabled in tests
|
||||
|
||||
|
||||
# Make sure that the LocalService is a singleton
|
||||
LocalService = baseservice.SingletonDecorator(_LocalService)
|
||||
|
Loading…
Reference in New Issue
Block a user