In my SP2010 visual webpart, I am checking permissions with the code below. Basically the current user is either an admin or a regular user. If they are an admin, they need to have permission to edit properties of the item and read properties of the item. And if they are a regular user, they need to have permissions to read properties from items.
I think my code is doing more than whats required, like it may be doing redundent checks. Does anyone know whats the best way to check?
Thanks.
public bool have_permissions_for_item(bool isEditMode, SPListItem item, Report RO)
{
try
{
// skip documents if user doesn't have access
if (!item.DoesUserHavePermissions(SPBasePermissions.ViewListItems)) return false;
// skip documents if user doesn't have access
if (!item.DoesUserHavePermissions(SPBasePermissions.OpenItems)) return false;
// skip documents if user doesn't have access
if (!item.DoesUserHavePermissions(SPBasePermissions.Open)) return false;
if (isEditMode)
{
// skip documents if user doesn't have access
if (!item.DoesUserHavePermissions(SPBasePermissions.EditListItems)) return false;
}
}
// catch the permission denied error so it doesn't ask the user for their credentials
catch (System.UnauthorizedAccessException F)
{
RO.log(Report.get_error_info(F));
return false;
}
return true;
}