Skip to content

Commit

Permalink
Merge pull request #749 from meejah/748.read-only
Browse files Browse the repository at this point in the history
#748: read-only is actually optional, and documentation
  • Loading branch information
meejah authored Feb 15, 2024
2 parents 88f6c92 + b020ebd commit 04cffbe
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ The body of the request is a JSON object with keys:
* ``author``: arbitrary, valid author name
* ``poll-interval``: seconds between remote update checks
* ``scan-interval``: seconds between local update checks
* ``read-only`` (optional): if specified, and True, reject write authority for this invite

The endpoint returns 201 Created once the folder is created and joined.
Otherwise, a 400 error is returned describing the error.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/748.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The new "read-only" option for join introduced in 24.1.0 unintentionally became required; fix this behavior, and document the feature.
2 changes: 1 addition & 1 deletion src/magic_folder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def join(options):
options["author"],
int(options["poll-interval"]),
None if options['disable-scanning'] else int(options["scan-interval"]),
options["read-only"],
True if options["read-only"] else None,
)
if ans["success"]:
print("Successfully joined as '{}'".format(ans["participant-name"]))
Expand Down
22 changes: 11 additions & 11 deletions src/magic_folder/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,20 @@ def invite_wait(self, magic_folder, invite_id):

def join(self, magic_folder, invite_code, local_dir, author, poll_interval, scan_interval, read_only=None):
api_url = self.base_url.child(u"experimental").child(u"magic-folder").child(magic_folder).child(u"join")
join_body = {
"invite-code": invite_code,
"local-directory": local_dir.asTextMode().path,
"author": author,
"poll-interval": poll_interval,
"scan-interval": scan_interval,
}
if read_only is not None:
join_body["read-only"] = read_only

return self._authorized_request(
"POST",
api_url,
body=json.dumps(
{
"invite-code": invite_code,
"local-directory": local_dir.asTextMode().path,
"author": author,
"poll-interval": poll_interval,
"scan-interval": scan_interval,
"read-only": read_only,
},
ensure_ascii=False,
).encode("utf-8"),
body=json.dumps(join_body, ensure_ascii=False).encode("utf-8"),
)

def list_invites(self, magic_folder):
Expand Down
28 changes: 27 additions & 1 deletion src/magic_folder/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def test_join(self):
"author": "amy",
"poll-interval": 123,
"scan-interval": 321,
"read-only": None,
}
).encode("utf-8")

Expand All @@ -177,3 +176,30 @@ def test_join(self):
b"Content-Length": ["{}".format(len(body)).encode("utf8")],
},
)

def test_join_read_only(self):
"""
The /join API works, with read-only too
"""
folder_dir = FilePath(self.mktemp()).asTextMode()
body = json.dumps(
{
"invite-code": "2-suspicious-penguin",
"local-directory": folder_dir.path,
"author": "amy",
"poll-interval": 123,
"scan-interval": 321,
"read-only": True,
}
).encode("utf-8")

return self._client_method_request(
"join",
("folder_name", "2-suspicious-penguin", folder_dir, "amy", 123, 321, True),
b"POST",
"http://invalid./experimental/magic-folder/folder_name/join",
body,
{
b"Content-Length": ["{}".format(len(body)).encode("utf8")],
},
)
2 changes: 1 addition & 1 deletion src/magic_folder/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def accept_invite(request, folder_name):
raise _InputError(
"Missing keys: {}".format(" ".join(missing))
)
extra_keys = required_keys.union({"read-only"}) - set(body.keys())
extra_keys = set(body.keys() - required_keys.union({"read-only"}))
if extra_keys:
raise _InputError(
"Extra keys: {}".format(" ".join(extra_keys))
Expand Down

0 comments on commit 04cffbe

Please sign in to comment.