Friday, 20 September 2013

SharePoint Check User Permissions

checkifUserHasEditPermissions();
      var _currentUser;
      var _theList;

function checkifUserHasEditPermissions()
{
      context = new SP.ClientContext.get_current();
      web = context.get_web();
      this._currentUser = web.get_currentUser();
      this._theList = web.get_lists().getByTitle('Announcements');
      context.load(this._currentUser);
      context.load(web,'EffectiveBasePermissions');
      context.load(this._theList, 'EffectiveBasePermissions')
      context.executeQueryAsync(Function.createDelegate(this, this.onPermissionsSuccessMethod), Function.createDelegate(this, this.onPermissionsFailureMethod));
      }

function onPermissionsSuccessMethod(sender, args)
{
      if (this._theList.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems))
      {
            alert('User Can Edit the list.');
      }
      else
      {
            alert('User Can NOT Edit the list.');
      }
}

function onPermissionsFailureMethod()
{
      //alert user
}

Share This!


No comments:

Post a Comment

Translate

Total Pageviews

Powered By Blogger · Designed By Seo Blogger Templates