You want to leave the doors open on a center-aisle barn as much as possible to allow air circulation, but the door should always have some sort of barrier, particularly if there's no enclosed stable yard with a gate. (A fence with gate around barn is a wonderful tool for keeping loose horses off of nearby roads.)
A door that adjoins a pasture should have some sort of solid bar or an actual gate, as horses may decide to challenge that entrance. Otherwise, a simple chain across doorways works well for most horses.
The barrier should always be attached unless horses or equipment need to pass through. Make it a barn rule. It should also be easy for a person to pass though without being detached, which will mean that it more likely will stay in place. If you use a chain, you can attach boots or lay a towel over it for better visibility.