Can a student write their undergraduate thesis on the main result of a paper under review for a journal? I think it's fairly common practice to isolate some parts of a thesis, if interesting enough, and publish them as a paper after properly changing structure and style. 

Is the opposite possible, if the paper has been submitted to a journal and is under review? And what if it actually gets published before the dissertation?
If the student did the work, then I see no problem at all. While its never happened for me with an undergrad dissertation (mostly because UGs get about 3 weeks to write their dissertation after the research period has finished, and a paper takes at least 6 months to go through review), this is a pretty normal thing to happen for a PhD. 

Write up the paper first and submit it for publication. Use this as a good starting point for the thesis. If the stars align, the paper will be back from review with corrections at about the time the thesis is submitted, and the corrections to the paper can be done while the student is waiting for their viva.

This is all on the proviso of course that the student actually writes the dissertation themselves and doesn't just paraphrase an article written by their supervisor.