views:

30

answers:

1

I have an application that needs to load data via web service calls and perform various permission and data checks. Fairly typical. I'm currently doing this in the background when the application starts, however it is a wizard type application and so the user can't do much until all of this has completed. If any issues come up when doing this I want to present the user a helpful message (you are "missing permission x" or "failed to retrieve y").

For the following, understand that I can change how I'm going about doing something, but I can't change what steps I need to perform. This has been simplified down as well.

A typical item might go like this. I need to retrieve a list of groups the user belongs to. However, first I need to check if the user has permission to view this list of groups otherwise the other call will fail. Once I have the list, I then need to check whether they have certain permissions within each item and discard those that don't apply. If they don't have permission in any of the groups, inform the user.

Initially I had everything in a LoadAndCheck() type call to work out all the various items I needed. Obviously this is large an clunky.

I then moved to a breaking each step up into pattern where each item was in a class behind an interface

interface IInitialize {
    bool InitializeAction();
    void OnFailure();
}

(i.e. CheckThisPermission, LoadThisList, CheckThatPermission). Each class performed a small action and if that action failed (loading data) or was false (permission check) it contained the step to perform to inform the user of the issue.

I can then loop through these classes and on failure of one step, not perform the following steps and have things configured to inform the user. This also lends itself to DI down the road if I settle on this pattern.

However, something just doesn't feel right about this pattern, though it is better than everything in one big call. Maybe it's just the name I'm giving to things. However my brain is wiped out and I'm not coming up with anything better.

So do you have any good patterns for doing something similar when starting up your application?

A: 

I personally have a SecurityManager static class that i call methods on for checking certain types(groups/items/users/etc) with methods such as

HasTradePermission(PermissionType type, User user, Trade trade);
HasInvoicePermission(PermissionType type, User user, Invoice invoice);

Only inside this method do I start calling the is part of group/what group/ does this group have this and this permission etc, so as far as the application is aware, all it interacts with is 'HasPermission' objects, therefore in my app i just iterate over e.g. Trades, and call the HasTradePermission.

Inside these has permission object, i would get the list of groups that the user is part of and check if there is a match with one of the groups inside the TradePermissionGroups etc..

LnDCobra