Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify the logged in user using Javascript in sharepoint

I need to check whether the logged in user is a administrator or non-admin user by using JavaScript in sharepoint designer or content editor webpart.

Can anybody suggest?

like image 476
Srikanth Avatar asked Jan 10 '12 10:01

Srikanth


1 Answers

You can use the HasRights javascript function defined in SharePoints core.js, you just have to pass the lower (limit) permission mask as well as the upper limit.

See the post about Checking Permissions with Javascript in Sharepoint 2007 and the list of permission masks. As you want to check whether it is an administrator you could try the ManageWeb permission mask: 0x0000000040000000


Edit: Another possibility is not using the HasRights function, but a SPSecurityTrimmedControl to simply set a global Javascript variable. An example you can find here: SharePoint: Run JavaScript based on user rights / permissions. This of course means extra markup (and doesn't work in a content editor webpart), but it does work.
like image 68
Dennis G Avatar answered Oct 24 '22 04:10

Dennis G