SAN FRANCISCO — An appeals court on Wednesday ordered California's Pelican Bay State Prison to halt race-based punishment except during riots and other dire emergencies.

The California Court of Appeal ruled that Pelican Bay authorities were wrong to deprive certain ethnic groups of privileges such as family visits, outside exercise and religious services during lengthy periods of heightened racial tensions.

The unanimous three-judge panel upheld a lower court ruling in favor of Jose Morales, a Hispanic inmate from Southern California. The court said the prison could find means of controlling violence other than long-term restrictions placed on ethnic groups.

Morales filed a lawsuit in 2010 alleging that he was denied certain privileges afforded other inmates because of his ethnic classification. Pelican Bay authorities had barred Hispanic inmates from certain privileges from three years after a major riot between Northern California and Southern California Hispanics.

Prison officials said the two groups were at "war" and attacked each other on sight. Prison officials argued unsuccessfully that they targeted "validated" gang members rather than ethnic groups. They also argued unsuccessfully that even if they were classifying inmates by race, "partial lockdowns" of certain ethnic groups is a vital tool in combating racial violence.

The California Department of Corrections and Rehabilitation could ask the state Supreme Court to review the case.

CDCR spokeswoman Terry Thornton said department lawyers had not yet reviewed the ruling and declined comment.

Read all of the PD's fire coverage here