How is the story or plot of "Master and Margarita" relevant to Russian history of the time? What is the author attacking in his story?
This is a good question, and without a doubt there is value in the novel if we read it as an allegory or critique of Russian life as Bulgakov saw it. For instance, the work toys with the notion of atheism by bringing Woland to visit the citizens of Moscow. Remember that he is first introduced when the poet and his publisher Berlioz have a conversation about a poem that he is to be edited and the devil (whom they mistake as a tourist) simply walks over and starts a conversation about their belief in God. This sets the plot in motion with the prophesy about the imminent beheading by the tram, which follows shortly thereafter. Berlioz, of course, is then really beheaded and Ivan becomes insane, or is at least considered insane by those around him.
On a literal level, one can read this and other scenes in the text as a critique or illumination of an atheist society, which the Soviet Union officially was at the time the text was written ( 1928-1940, when Bulgakov died while he was still revising the text). This mode of reading seems appropriate in light of the choice that Bulgakov made by writing about life in Moscow in such a detailed manner. Note for instance that the characters in this part of the plot are meticulously detailed and realistic. So, yes, this can quite well be read as a parody of contemporary times.
However, I always caution my students to be overeager and make works didactic by attempting to draw analogies that are not really appropriate, like saying "x in the novel must mean y in the real world". Scholars have argued against hasty readings of atheist parodies as I have suggested above, by pointing out that Woland dispenses divine justice and forces the reader to re-think the relationship between god, satan, and the characters. Since atheism forces a rejection of the divinity, one must have contemplated it (the divinity's) existence to begin with. Or, more simply stated, you can only reject god if you believe he exists, because there is no need to deny or reject something that does not exist. Within the frame of the story, the existence of the devil thus indirectly confirms the existence of god because god is necessary to believe in the devil in the first place.
While I tried to show that the work can be read as addressing or parodying atheism, which was official Bolshevik policy, try to look deeper. It seems fair though to say that parts of the text are a critique of society.
Finally, it is accepted that Bulgakov worked certain experiences and impressions from his personal life into the text, such as a visit to Spaso House in Moscow, which was transformed in to the ball scene.