Is it legal for Department of Homeland Security to send federal agents to cities?

The Trump administration sends federal agents in cities like Portland by citing the Department of Homeland Security. Here is breakdown on the law.