Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement media unquarantine command #85

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,13 @@ def media_quarantine(self, server_name, media_id):
"post", f"v1/media/quarantine/{server_name}/{media_id}", data={}
)

def media_unquarantine(self, server_name, media_id):
""" Removes a single piece of local or remote media from quarantine.
"""
return self.query(
"post", f"v1/media/unquarantine/{server_name}/{media_id}", data={}
)

def room_media_quarantine(self, room_id):
""" Quarantine all local and remote media in a room
"""
Expand Down
37 changes: 37 additions & 0 deletions synadm/cli/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,43 @@ def media_quarantine_cmd(helper, server_name, media_id, user_id, room_id):
helper.output(media_quarantined)


@media.command(name="unquarantine")
@optgroup.group(
"unquarantine media by",
cls=RequiredAnyOptionGroup,
help="")
@optgroup.option(
"--media-id", "-i", type=str,
help="""The media with this specific media ID will be removed from
quarantine.
""")
@click.option(
"--server-name", "-s", type=str,
help="""The server name of the media, mandatory when --media-id is used and
_remote_ media should be processed. For locally stored media this option
can be omitted.
""")
@click.pass_obj
def media_unquarantine_cmd(helper, server_name, media_id):
""" Remove media from quarantine.
"""
if media_id and not server_name:
# We assume it is local media and fetch our own server name.
fetched_name = helper.retrieve_homeserver_name(
helper.config["base_url"])
unquarantinend = helper.api.media_unquarantine(fetched_name, media_id)
elif server_name and not media_id:
click.echo("Media ID missing.")
unquarantinend = None
elif media_id and server_name:
unquarantinend = helper.api.media_unquarantine(server_name, media_id)

if unquarantinend is None:
click.echo("Media could not be removed from quarantine.")
raise SystemExit(1)
helper.output(unquarantinend)


@media.command(name="protect")
@click.argument("media_id", type=str)
@click.pass_obj
Expand Down