A federal appeals court has largely upheld Philadelphia’s victory in its contentious “sanctuary city” case against the Trump administration.

The U.S. Court of Appeals for the Third Circuit affirmed on Friday a lower court ruling that the administration could not withhold federal grant money because of a dispute over immigration policy and enforcement, saying the executive branch claimed authority not granted by the Constitution and hence “literally has no power to act.”

“Philadelphia," Mayor Jim Kenney said after the ruling, “is proud to be a city that welcomes all of those who seek safe haven, and this ruling affirms our right to do so.”

In June, after nearly a year of litigation, U.S. District Judge Michael Baylson ruled that the administration’s attempt to withhold about $1.5 million in federal law-enforcement grant money violated statutory and constitutional law.

The money comes under what is called an Edward Byrne Memorial Justice Assistance Grant. The administration wanted to hold back the funds unless the city agreed to actively assist federal authorities in identifying and turning over undocumented immigrants.

The city sued in the summer of 2017, saying that the Police Department is not an arm of immigration enforcement, and that making it one would damage police-community relations.

On Friday the Third Circuit noted the “stark contrast in the priorities of the city and those of the executive branch regarding immigration policy” and said its role was confined strictly to the legal issues of the case.

It said the relief granted to the city by Baylson went too far in one respect — requiring that federal immigration officers obtain a judicial warrant before seeking custody of an undocumented immigrant who may be held by the city. The court vacated that part of the ruling, saying that “while the District Court’s concerns regarding the legality of holding an alien pursuant to a detainer may well be legitimate, they are not part of this case and controversy.”

The city has refused to hold undocumented immigrants beyond the time when they or anyone else might normally be released, saying an administrative detainer did not carry the power of law.