2

I'm developing an SP2013 App using JSOM and have a few questions which I'm struggling to get answered:

  1. I am deploying a list on which I want to have very granular control; users of the app should only have read access and admin users should be able to have full control...as far as I can see there is now way to set these permissions?

  2. On a similar note I have content on the page which I want only Admin user to be able to see but I can see no way to add audience targeting via code? Is this possible?

Any pointers would be appreciated.

1
  • perhaps I am also looking for the same answer: I have a list in the host web, which is accessed by the app and the contents are shown. If the user of the app has WRITE permissions on the list, I have to give them the edit option in the app. How could I check that permission?
    – Betsen
    Dec 2, 2013 at 21:54

2 Answers 2

1

Create a list of users with full control;

Search this list, using JQuery, checking if the user is logged in it;

Now you know whether or not it has Full Control permission. Use this code to get current user:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
var User;
var UserID;
var Context;
function sharePointReady() {
    Context = SP.ClientContext.get_current();
    User = Context.get_web().get_currentUser();
    Context.load(User);

    Context.executeQueryAsync(function(){
        UserID = User.get_id();     
    }, function(){
        console.log('error');       
    })
}
1
  • Thanks for the post...the user list already exists i.e. the host web existing users...
    – Stephen
    Dec 16, 2013 at 14:30
0

I would suggest setting sharepoint permissions on the list at the point of deployment (assuming you mean WSP).

You could have a "deployment" page which configures these permissions. Or if you need to control permissions yourself through JS, you could get the list of users and groups through SPWeb.SiteGroups and SPWeb.SiteUsers.

You can use SPWeb.SiteGroups Collection to get the list of groups for a site. Then you can use SPList.RoleAssignments to give specific permissions (and break inheritance).

Here's an example using C#, however it could be applied to JSOM.

As for audience targetting, you could use a Content Editor Web Part and put your page content inside. CEWP have an Audience targetting property.

1
  • No this is not a WSP...its an app. I'll take a look at the code though, thanks.
    – Stephen
    Dec 3, 2013 at 9:31

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.