On Thursday, the New Zealand Appeals Court ruled (PDF) that Kim Dotcom has the right to sue the government of New Zealand for illegal surveillance. The Megaupload founder had previously gotten the green light late last year, but the government appealed that ruling.

New Zealand’s Government Communications Security Bureau (GCSB), analogous to the National Security Agency in the United States, was found to have spied on Dotcom (a German national with permanent residency status in New Zealand) before the January 2012 raid on his mansion.

The shuttering of Megaupload has led to a long, drawn-out court criminal case in the US, with charges of mass criminal copyright infringement, online piracy, and money laundering. Dotcom has responded vociferously, fighting extradition to the United States.

As we reported last year, because Dotcom had obtained permanent resident status, he does not qualify as a foreigner under the latest version of the GCSB law and therefore should not have been subjected to GCSB surveillance. But the agency evidently misunderstood the law or failed to verify Dotcom's immigration status.

"If they had been more thorough in what they had done, they would have worked out that Mr. Dotcom had a residence class visa, and therefore was protected by the law," Key told reporters in New Zealand in September 2012. "Frankly, I'm pretty appalled by what I've seen, because these are basic errors."

"This is really a matter of mistake and human error, not one of a great conspiracy," Key added. But he emphasized that "the agency has let itself down very badly."

On Thursday, Dotcom’s lawyer, Ira Rothken tweeted: “We look forward to holding GCSB spy org accountable. Doing so will not only protect @KimDotcom's rights but the rights of all NZ residents.”