Fix permission check in repositories
Modular, better structured javascript...... finally