1

In my SharePoint online list I want to disable the Edit option for all users except some specific administrators.

enter image description here

My users should be able to edit, add or delete the items as i circled green but i don't want to allow them quick edit as i circled red in the following picture. enter image description here

  • Disabling edit option , means not allowing user to edit item ? – Bhaskar Dhone Aug 12 '15 at 11:56
  • If you don't want to allow the users to edit the items, Break the security inheritance on that library. and assign read permissions to all security groups. This should remove the Edit option for Users in groups – sekhar Aug 12 '15 at 11:59
  • @sekhar please don't post answers as comments. – Akhoy Aug 12 '15 at 12:19
  • @Jenny : So just want that Quick Edit link to be disappeared. But want users to do normal operations like view, add, edit and delete? But also you would want only administrators to see this link. Correct me if I am wrong. – Asad Refai Aug 13 '15 at 7:35
  • 1
    Yes exactly that's what i wanted! @AsadRefai – Jenny Aug 13 '15 at 7:42
1

Updated Answer after question was updated with more understanding.

Well as you have said that we can remove the Quick Edit link via list setting in Advance Settings option, but unfortunately that hides link for all users irrespective of admin or not.

So I doubt you have any OOB solution which will take care of your requirement. You need some custom solution.

All I can think of a JSOM code which gets the current logged in user and identifies whether he/she is site admin or not, If site admin show link or else hide it.

That function is below:

function chkCurrentUserIfAdmin() {
    try {

                var clientContext = new SP.ClientContext.get_current();
                var tempcurrentUser = clientContext.get_web().get_currentUser();
                clientContext.load(tempcurrentUser); 
                clientContext.executeQueryAsync(function () {
                    var index = tempcurrentUser.get_loginName().indexOf('|') + 1;
                    var currentUser = tempcurrentUser.get_loginName().substring(index);
                    var isSiteAdmin = tempcurrentUser.get_isSiteAdmin();
                    if(!isSiteAdmin) {
                        $("#Hero-WPQ2 a:nth-child(2)").remove();
                        var tempHtml = $("#Hero-WPQ2").html();
                        tempHtml = tempHtml.replace('or  this list', '');
                        $("#Hero-WPQ2").html(tempHtml);

                    }

                }, function () {
                    console.log("error");
                });
            }
            catch (err) {
                console.log("error");
            }

}

But still the main question remains, is how and from where to call it? Well there are 2 options

  1. Place a Content Editor Web Part on your view page: But I believe this is not portable solution, and will have difficulty while moving to Production.
  2. Use JSLink: the main purpose of JSLink is to modify the rendering of the items on a view, but here we can use it as we need to apply something on a view keeping the item design as it is.

Below is the complete JSLink file code. make a file showhideEditLink.js paste below code in it, and upload where ever you want in site.

Note: I have not removed all of the code in override function, but just commented the line of code which actually overrides the view i.e. SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);. You can opt to remove that and just keep the document.ready and the function

// function to process an item..
window.AZR = window.AZR || {};
window.AZR.ListItem = {
    customItemHtml: function (ctx) {
        var ListItemHtml = "<h3>" + ctx.CurrentItem.Title + "</h3>";
        ListItemHtml += "<div>" + ctx.CurrentItem.PrivacyStatementUrls + "</div>";
        return ListItemHtml;

    }
};


// anonymous self-executing function to setup JSLink templates on page load..
(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};

    overrideCtx.Templates.Header = "<div id=\"accordion\">";
    overrideCtx.Templates.Item = window.AZR.ListItem.customItemHtml;
    overrideCtx.Templates.Footer = "</div>";

    overrideCtx.BaseViewID = 1;
    overrideCtx.ListTemplateType = 10000;

    //SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function chkCurrentUserIfAdmin() {
    try {

                var clientContext = new SP.ClientContext.get_current();
                var tempcurrentUser = clientContext.get_web().get_currentUser();
                clientContext.load(tempcurrentUser); 
                clientContext.executeQueryAsync(function () {
                    var index = tempcurrentUser.get_loginName().indexOf('|') + 1;
                    var currentUser = tempcurrentUser.get_loginName().substring(index);
                    var isSiteAdmin = tempcurrentUser.get_isSiteAdmin();
                    if(!isSiteAdmin) {
                        $("#Hero-WPQ2 a:nth-child(2)").remove();
                        var tempHtml = $("#Hero-WPQ2").html();
                        tempHtml = tempHtml.replace('or  this list', '');
                        $("#Hero-WPQ2").html(tempHtml);

                    }

                }, function () {
                    console.log("error");
                });
            }
            catch (err) {
                console.log("error");
            }

}

$(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', chkCurrentUserIfAdmin);
});

Now you need to set this JSLink to your view. Refer Setting JSLink SharePoint online

Also if you are unaware of JSLink then go through Using JSLink to change the UI of a SharePoint list/view


Old Answer and approach below

Summing up NkSP's and Eric Alexander's answers into one.

To achieve this we can divide the work into 2 stages.

  • Create permission levels
  • Assign levels to list

Create permission levels:

  1. go to site settings of your Root Site
  2. Click on Site Permissions under Users and Permissions section
  3. Click on Permission Levels from ribbon (Refer below screen shot) enter image description here
  4. Add a new level(Refer screen shot) enter image description here
  5. As mentioned by @NkSP create 2 levels first with Add and View items permissions and second with View items permission only.

Assign levels to list:

  1. Go to your list open up ribbon and click on List Settings
  2. Click on Permissions for this list

  3. From the ribbon you can Stop inheriting permissions. This will break the original Site's permission and give you a chance to set your own permissions on the List. enter image description here

  4. Select your Group and from ribbon click on Edit user permissions enter image description here

  5. On the next page you will see your Newly Created Permission Levels. Select them and save.

  6. This is how you give permissions to Group, and lastly Go back to permissions page, From ribbon Click on Grant Permissions and add your specific administrators with whatever permissions you want to give.

enter image description here

  • I want my users to add, edit ,or delete items one by one but not in the quick edit mode. I have edited my question, Please check my question again for better understanding. – Jenny Aug 13 '15 at 7:40
  • @Jenny : Only administrators should use quick edit mode and not normal users correct? – Asad Refai Aug 13 '15 at 7:42
  • Yes that's correct! – Jenny Aug 13 '15 at 7:47
  • I can disable the quick edit option through list settings but that will be for all users including administrators. – Jenny Aug 13 '15 at 7:55
  • @Jenny I updated my answer with a CSOM solution. Btw this is a nice answer! – Nk SP Aug 13 '15 at 11:50
3

Then in your list, you would want to make sure that the permissions are set so that only your administrators have Contribute, Edit, or Full Control access and everyone else has Read.

This can be found by going to the List tab and selecting List Settings and clicking on Permissions for this list. You might have to break permissions inheritance and set permissions as desired.

3

You have to add two permission levels on the site.
One level needs Add Items and View Items permissions.
The other level needs View Items.

Then assign the level to two different groups and it is done.

User permissions and permission levels in SharePoint 2013

If you want to hide the Edit button in the quick edit mode, I would suggest you to use Javascript to check if the user is in the Administrator group and then hide the button with the CSS.

$(".ms-heroCommandLink").hide()

With this you will hide the button.
Here you can find a nice post that will tell how to check if a user is in a group by CSOM:
Determine if current user is a member of Group via CSOM(JavaScript) in SharePoint 2010/2013 Raw

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.