Is it bad design to mix code that deals with security logic in the model?
Example for editing a page in the before_save callback
- The current user is grabbed from the
current_user
method in the Controller layer. - Throw exception if
current_user.has_permission? :edit_page
is false - The
editor_id
is set tocurrent_user.id
- The change is logged in a separate table
The model isn't the only security check in the application. The user interface checks for permission before display editing views. The model acts as a barrier against any bugs in the View/Controller level.
Note: The only breach between the Model and Controller levels is the current_user
method. The application I'm working on will never allow anonymous users.