1

I am coding a web app that will list all SharePoint apps available for one user.

How is it possible to know if a user is allowed or not to access a SharePoint app? It is useless to display a link if the user doesn't have the right permissions.

Is it possible to do something with NTLM login? The different SharePoint apps are on different domains.

0

Assuming here that the App has deployed an App Web you could check the EffectiveBasePermissions.

Something like

context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
context.load(this._currentUser);
context.load(web,'EffectiveBasePermissions');
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) 
{
  if (web.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)) 
  {
     //User Has Edit Permissions
  }
}}

Code courtesy of MSDN answer: https://social.technet.microsoft.com/forums/sharepoint/en-US/f21ad6b1-445a-497d-a286-d3ba8c2928a6/how-to-get-the-current-user-permission-level-on-a-list-item-with-ecmascript

EDIT To run across different version you might want to look at using the server object model. The below will iterate over a web and list out all lists and users with access. You can modify this to check for a specific user and return that results. the roleassignment method is what you will want to work with. Hope this works a little better for you.

This is from StackOverflow https://stackoverflow.com/questions/2248211/getting-all-sites-lists-and-user-permissions-in-sharepoint

static void ListLists()
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://mossdev:8060"));
            foreach(SPSite site in webApp.Sites)
            {
                try
                {
                    PrintWebAndListsRecursive(site.RootWeb, 0);
                }
                finally
                {
                    site.Dispose();
                }
            }

            Console.ReadLine();
        }

        static void PrintWebAndListsRecursive(SPWeb web, int level)
        {
            Console.WriteLine("".PadLeft(level * 3) + "Site: {0} ({1})", web.Title, web.Url);
            foreach(SPList list in web.Lists)
            {
                Console.WriteLine("".PadLeft((level + 1) * 3) + "List: {0}", list.Title);
                foreach(SPRoleAssignment roleAssignment in list.RoleAssignments)
                {                    
                    if(roleAssignment.Member is SPGroup)
                    {
                        var group = (SPGroup) roleAssignment.Member;
                        Console.WriteLine("".PadLeft((level + 2) * 3) + "Group: {0}", group.Name);   
                        foreach(SPUser user in group.Users)
                        {
                            Console.WriteLine("".PadLeft((level + 4) * 3) + user.Name);   
                        }
                    }
                    else
                    {
                         Console.WriteLine("".PadLeft((level + 2) *3) + "User: {0}", roleAssignment.Member.Name);  
                    }

                    foreach(SPRoleDefinition roleDef in roleAssignment.RoleDefinitionBindings)
                    {
                        if (!roleDef.Hidden)
                        {
                            Console.WriteLine("".PadLeft((level + 3) * 3) + "Role Definition: {0}", roleDef.Name);
                        }
                    }
                }
            }

            foreach(SPWeb subWeb in web.Webs)
            {
                try
                {
                    PrintWebAndListsRecursive(subWeb, level+1);
                }
                finally
                {
                    subWeb.Dispose();
                }
            }
        }
  • ok it works with sharepoint 2013 appz but what about sharepoint 2007 appz ? – toto29000 Dec 10 '14 at 15:52
  • You will need to clarify on what you mean by 2007 appz? 2007 didn't have what we call Apps. in 2007 you could deploy full trust code in WSP packages - which could contain, literally anything. It might extend a site or it might be a site. – Jesus Shelby Dec 10 '14 at 20:23
  • Sorry by "appz" I was meaning sharepoint websites. Your solution is working with new sharepoint websites but it is not working with the old ones. Also I don't need to know in details the permissions of one user, I just need to know if he can access or not the website. With your solution when the user cannot access the website, there is a windows authentification pop up showing up when I am firing "executeQueryAsync", this is also a problem. – toto29000 Dec 11 '14 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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