2

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;
    }

1 Answer 1

1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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