mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-13 07:12:19 -04:00
Add new admin APIs to remove media by media ID from quarantine. (#10044)
Related to: #6681, #5956, #10040 Signed-off-by: Dirk Klimpel dirk@klimpel.org
This commit is contained in:
parent
bf6fd9f4fd
commit
0284d2a297
5 changed files with 201 additions and 10 deletions
|
@ -764,14 +764,15 @@ class RoomWorkerStore(SQLBaseStore):
|
|||
self,
|
||||
server_name: str,
|
||||
media_id: str,
|
||||
quarantined_by: str,
|
||||
quarantined_by: Optional[str],
|
||||
) -> int:
|
||||
"""quarantines a single local or remote media id
|
||||
"""quarantines or unquarantines a single local or remote media id
|
||||
|
||||
Args:
|
||||
server_name: The name of the server that holds this media
|
||||
media_id: The ID of the media to be quarantined
|
||||
quarantined_by: The user ID that initiated the quarantine request
|
||||
If it is `None` media will be removed from quarantine
|
||||
"""
|
||||
logger.info("Quarantining media: %s/%s", server_name, media_id)
|
||||
is_local = server_name == self.config.server_name
|
||||
|
@ -838,9 +839,9 @@ class RoomWorkerStore(SQLBaseStore):
|
|||
txn,
|
||||
local_mxcs: List[str],
|
||||
remote_mxcs: List[Tuple[str, str]],
|
||||
quarantined_by: str,
|
||||
quarantined_by: Optional[str],
|
||||
) -> int:
|
||||
"""Quarantine local and remote media items
|
||||
"""Quarantine and unquarantine local and remote media items
|
||||
|
||||
Args:
|
||||
txn (cursor)
|
||||
|
@ -848,18 +849,27 @@ class RoomWorkerStore(SQLBaseStore):
|
|||
remote_mxcs: A list of (remote server, media id) tuples representing
|
||||
remote mxc URLs
|
||||
quarantined_by: The ID of the user who initiated the quarantine request
|
||||
If it is `None` media will be removed from quarantine
|
||||
Returns:
|
||||
The total number of media items quarantined
|
||||
"""
|
||||
|
||||
# Update all the tables to set the quarantined_by flag
|
||||
txn.executemany(
|
||||
"""
|
||||
sql = """
|
||||
UPDATE local_media_repository
|
||||
SET quarantined_by = ?
|
||||
WHERE media_id = ? AND safe_from_quarantine = ?
|
||||
""",
|
||||
((quarantined_by, media_id, False) for media_id in local_mxcs),
|
||||
)
|
||||
WHERE media_id = ?
|
||||
"""
|
||||
|
||||
# set quarantine
|
||||
if quarantined_by is not None:
|
||||
sql += "AND safe_from_quarantine = ?"
|
||||
rows = [(quarantined_by, media_id, False) for media_id in local_mxcs]
|
||||
# remove from quarantine
|
||||
else:
|
||||
rows = [(quarantined_by, media_id) for media_id in local_mxcs]
|
||||
|
||||
txn.executemany(sql, rows)
|
||||
# Note that a rowcount of -1 can be used to indicate no rows were affected.
|
||||
total_media_quarantined = txn.rowcount if txn.rowcount > 0 else 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue