Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a philosophical question about the MVP pattern: I have a component that checks whether a user has access to a certain privilege. This privilege turns on or off certain UI features. For instance, suppose you have a UI grid, and for each row that gets bound, I do a security check to see if certain features in the grid should be enabled or disabled.

There are two ways to do this: have the UI/view call the component's method, determine if it has access, and enable/disable or show/hide. The other is have the view fire an event to the presenter, have the presenter do the check and return the access back down to the view through the model or through the event arg.

As per the MVP pattern, which component should security checks fit into, the presenter or the view? Since the view is using it to determine its accessibility, it seems more fitting in the view, but it is doing database checks and all inside this business component, and there is business logic there, so I can see the reverse argument too.

Thoughts?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

The security check belongs in the model, and data that should not appear in the UI should not be available to the view at all. Otherwise you have to duplicate the security logic in every view you have on the data, and a mistake in any of them will lead to a security flaw in your product.

share|improve this answer
add comment

As per the MVP pattern, which component should security checks fit into, the presenter or the view? Since the view is using it to determine its accessibility, it seems more fitting in the view, but it is doing database checks and all inside this business component, and there is business logic there, so I can see the reverse argument too.

Should be in the controller and model. It usually is a filter component, reside in the controller, where you check if the user have access by calling the model and querying it, and then the controller decides if it should render that component to the view.

Note: I'm still a beginner at MVC but this is how I see it.

share|improve this answer
    
The problem is that the page is being presented to the user regardless of whether you have access to that piece. So unless you are willing to have duplicated views, the controller has no possible routing choice that hides that part. However if you were using a component-based MVC system, then this logic would absolutely go into the controller. But very few web frameworks use component-based MVC, that's an idea you more often find in interactive applications. –  btilly Mar 9 '11 at 16:40
add comment

Not sure I would pull data that a user/group wasn't allowed to see (other than keys, id's etc.). You may not show the same data in different views, but if you start doing reports, you have a lot of duplication to do.

Are you talking about row only or column/field as well?

share|improve this answer
    
More showing/hiding certain capabilities. –  Brian Mains Mar 9 '11 at 2:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.