0

Ran into a unique problem - I have built a collaborative page, where many users are coming to get their daily communications and such. I have used almost exclusively web parts, with a small amount of text in the body of the page.

However, when clicking the body of text, it's bring up the format text/insert ribbons - almost as though it's in edit mode. This is even happening for users who cannot edit.

A secondary question I have is also, the ribbon added "items/list" when clicking into a webpart zone - is there any way to lock all of this off from users?

Thanks so much in advance!

1

You could use a CEWP to add some jQuery or CSS to hide the ribbon once the element has focus. That would be one way your could do it.

EDIT:

You can run code in your CEWP to check if a user is an admin and base your hide/show off of that. You of course still need to reference your jQuery library you are using in your CEWP:

Please review the below code:

<script src="*Your JS Library Location*"></script>

<script type="text/javascript">

$(function () {
    if (!IsAdmin()) {
       HideRibbon();
    }
});

function IsAdmin() {
    var isSiteAdmin;
    var call = jQuery.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser/issiteadmin",
        type: "GET",
        datatype: "json",
        headers: { Accept: "application/json;odata=verbose" }
    });
    call.done(function(data) {
        isSiteAdmin = data.d.isSiteAdmin;
    });
    return isSiteAdmin;
}

function HideRibbon() {

   $("#s4-ribbonrow").hide();

   var newHeight = $(document).height();

   if ($.browser.msie) {newHeight = newHeight - 3; }

      $("#s4-workspace").height(newHeight);

}

</script>


<script type="text/javascript">
//Kind of hacky, but sometimes you got to do it in SharePoint
//Hide based off username

$(function () {
    var fullControlUsers = ["userName1", "userName2", "userName3", "userName4"];
    var currentUser = CurrentUser();

    for(var i =0; i < fullControlUsers.length; i++) {
        if(fullControlUsers[i] != currentUser.toString()) {
            HideRibbon();
        }       
    }
});

function CurrentUser() {
    var currentUser;
    var call = jQuery.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser",
        type: "GET",
        datatype: "json",
        headers: { Accept: "application/json;odata=verbose" }
    });
    call.done(function(data) {
        //console.dir(data);  look at this and see what will work best for you
        currentUser = data.d.Title;
    });
    return currentUser;
}

function HideRibbon() {

   $("#s4-ribbonrow").hide();

   var newHeight = $(document).height();

   if ($.browser.msie) {newHeight = newHeight - 3; }

      $("#s4-workspace").height(newHeight);

}

</script>

Explaination EDIT:

This should work for Full Control users as well. Using REST or CSOM, the call used gets the users' base permissions is using Permissionskind. The manageWeb permissions kind is what determains Full Control. The Admin Check looks for that as well. The code here will run with a regular user because users can look up their own information and the admin check is part of the return for current user.

Trying to run a Permissionkind check requires elevated permissions and regular user will not be able to run the code. The user will get an Access Denied exception. REST and CSOM run based on the permissions of the user who is executing the code at that time in SharePoint. The only way to do the SP.BasePermissions and SP.Permissionkind check for users other than Admin/Full Control would be to run it in a web service with elevated privilages.

If this does not work for some reason, you could try looking up your Full Control users by username and base you hide/show logic off of that. You can use the same function I have provided you to do that just take off the issiteadmin from the end of the URL. I provided another example for you. That will be $100.00 lol. Just Kidding! Hope this will work for you.

  • I was thinking about trying this, hiding it entirely. I do prefer that it's easy to edit the page for those who are admins. I don't have approval to edit the master page (this is for a big company, and they don't appreciate editing things such as master pages), so I cannot do the security based changes I've seen on here to remove ribbons for certain users. I cannot quite find a way to edit the page without the ribbon and cog. Is there a way? – Tom Shepherd Apr 9 '18 at 13:27
  • Check my edit. If you can use a CEWP, you can check if the user is an admin. There is no need to modify the master page. – lazoDev Apr 9 '18 at 13:53
  • Oh wow, this sounds amazing. Thank you so much, will try at work today and get back to you. Legend! – Tom Shepherd Apr 9 '18 at 22:57
  • Hey lazoDev, thank you - worked out how to reference a javascript, got it working but realised some users are just full control/design access. Basically just need to block anyone on a certain access, aptly named "Lowest Access" at the moment in the hierachy of users. Is it possible to do this in reverse and remove ribbon when they're that access? – Tom Shepherd Apr 10 '18 at 0:42
  • Yes there is. You can get the user base permissions for the site and provide logic to hide based on different permission levels. Here is some rest to check permission kind. You cna look through the JSON results to get what you are looking for. here is the link: social.technet.microsoft.com/wiki/contents/articles/… – lazoDev Apr 10 '18 at 10:48

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.