Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
    }
share|improve this question
add comment

1 Answer

Is it better to use SharePoint group? You can create group whith predefined permissions, then checks if the user is a member of this group.

web.IsCurrentUserMemberOfGroup(group.Id);
share|improve this answer
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.