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

The context for this is the SPServices or Imtech (SP)LookupAddNew function that let you add new items to lookups without navigating to the target list.

Can we avoid adding the link for users without the permission to add items to the target list?

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

I have been working on a similar situation and it really depends on what you can do. I chose to use custom code because for my situation the amount of code was smaller. I setup a simple aspx page that tests if the user has permissions on the list in question and then I can ajax that page and read the response to draw the link accordingly. At the list level, you can do it all in javascript and web services but not at the item level. A quick example on the aspx page I use:

SPWeb web = "get handle to web";
SPList list = "get handle to list";
Boolean hasright = list.DoesUserHavePermissions(SPBasePermission.AddListItems);

You can format this as xml and use response object to render it. When it is returned to the calling page just check the returned xml and draw the link if needed.

share|improve this answer
    
Great. Just the adequate amount of custom code to accomplish the task and simple to deploy and support. Thanks a lot! –  Alexey Krasheninnikov May 23 '10 at 21:40
add comment

You can use the GetPermissionCollection method from the Permissions web service.

More info here:

http://msdn.microsoft.com/en-us/library/permissions.permissions.getpermissioncollection.aspx?ppud=4

Be aware though that the user executing the code would need to have permissions on the site to view permissions...if you know what I mean!

You can use this through SPServices as well if that is what you are using so you would make the call to this when the page loads and then show or hide the link accordingly.

share|improve this answer
    
The trick is yes you can, but only if you have the permissions to use the Permissions web service, right? what if I had the rights to add an item and the rights to add an item to one of the lookup lists but not the other. Moreover, if I had not the rights to enumerate permissions. Then what? –  Alexey Krasheninnikov May 7 '10 at 10:55
    
Then HTTP Status 401 Access denied is returned for both ajax requests, whereas one of them is expected to return "Yes you may" while the other - "Keep out", right? How can we handle this? –  Alexey Krasheninnikov May 7 '10 at 10:57
    
Custom server side code is probably your best bet then. Or is that not an option? –  Charles Lee May 7 '10 at 12:55
    
Yes it is an option but the fewer lines of code the more supportable, right? –  Alexey Krasheninnikov May 9 '10 at 19:59
add comment

You could always try a GetListItems on the target list and then an UpdateListItems on that item. If the user can accomplish that, then they are allowed to add items. There are issues with this, too, but you can see that it's another angle which might work, depending on your situation.

Also take a look at the Users and Groups operations.

share|improve this answer
    
Thanks Mark, but that's not the best option in a number of scenarios because it creates unnecessary items and bloats the data every time we show an edit form with AddNewLookup enabled. You can delete the test items but still the IDs might have a meaning to someone. –  Alexey Krasheninnikov May 9 '10 at 19:59
    
And Marc, did I say your documentation style is AWESOME? Thanks for that! –  Alexey Krasheninnikov May 9 '10 at 20:01
    
Like I said, this wasn't a perfect suggestion, but more another way to think about it. Glad the docs are working for you! –  Marc D Anderson May 10 '10 at 3:43
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.