Skip to content

Commit

Permalink
[hma] add endpoint to delete a content_signal from a bank (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
prenner authored Oct 3, 2024
1 parent 0f1cc50 commit 09ea0c4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
14 changes: 14 additions & 0 deletions hasher-matcher-actioner/src/OpenMediaMatch/blueprints/curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ def _bank_add_signals(
}


@bp.route("/bank/<bank_name>/content/<content_id>", methods=["DELETE"])
def bank_delete_content(bank_name: str, content_id: int):
"""
Remove a signal from a bank.
"""
storage = persistence.get_storage()
bank = storage.get_bank(bank_name)
if not bank:
abort(404, f"bank '{bank_name}' not found")

count = storage.bank_remove_content(bank.name, content_id)
return {"deleted": count}


@bp.route("/bank/<bank_name>/signal", methods=["POST"])
def bank_add_as_signals(bank_name: str):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def bank_add_content(
"""

@abc.abstractmethod
def bank_remove_content(self, bank_name: str, content_id: int) -> None:
def bank_remove_content(self, bank_name: str, content_id: int) -> int:
"""Remove content from bank by id"""

@abc.abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def bank_add_content(
# TODO
raise Exception("Not implemented")

def bank_remove_content(self, bank_name: str, content_id: int) -> None:
def bank_remove_content(self, bank_name: str, content_id: int) -> int:
# TODO
raise Exception("Not implemented")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,13 @@ def bank_add_content(
sesh.commit()
return content.id

def bank_remove_content(self, bank_name: str, content_id: int) -> None:
database.db.session.execute(
def bank_remove_content(self, bank_name: str, content_id: int) -> int:
# TODO: throw an exception if deleting imported content
result = database.db.session.execute(
delete(database.BankContent).where(database.BankContent.id == content_id)
)
database.db.session.commit()
return result.rowcount

def get_current_index_build_target(
self, signal_type: t.Type[SignalType]
Expand Down
13 changes: 13 additions & 0 deletions hasher-matcher-actioner/src/OpenMediaMatch/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def test_banks_add_hash(client: FlaskClient):
}


def test_banks_delete_hash(client: FlaskClient):
bank_name = "NEW_BANK"
image_url = "https://github.com/facebook/ThreatExchange/blob/main/pdq/data/bridge-mods/aaa-orig.jpg?raw=true"

create_bank(client, bank_name)
add_hash_to_bank(client, bank_name, image_url, 1)

post_response = client.delete(f"/c/bank/{bank_name}/content/1")

assert post_response.status_code == 200
assert post_response.json == {"deleted": 1}


def test_banks_add_metadata(client: FlaskClient):
bank_name = "NEW_BANK"
create_bank(client, bank_name)
Expand Down

0 comments on commit 09ea0c4

Please sign in to comment.