0

I know that you can apply security trimming to .aspx pages via the <SharePoint:SecurityTrimmedControl> control, but is there an equivalent way of security trimming dynamically generated DOM nodes - client-side only?

For example, I have a node being created from a function that will be injected into a SP.UI.ModalDialog object.

var modal = function (title) {
  var container = document.createElement("div");
      container.innerHTML = "This is something that should be security trimmed";
      container.className = "button half bg-green";
      container.id = "trim-this-mofo";
  // how do you security trim the node created above?
  var options = {
      allowMaximize: false,
      title: title,
      html: container,
      showClose: true,
      width: 750
  };
  SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
};

Again, this is client side only.

  • I don't think in this case it will be pure security trimming rather just hiding the element from the user. – Amal Hashim Dec 19 '14 at 17:18
  • You can edit the aspx page this sits on or the master page and wrap it in a SecurityTrimmedControl based on user rights – Eric Alexander Dec 19 '14 at 17:48
2

I don't think there's a general approach to do this, but depending on your exact needs there might be a solution. I can think of a few options:

  1. Create a list to hold the HTML nodes and apply audience targeting to the individual list items. This way, the user could execute a clientside request to the list to pull back all nodes but they'd only receive nodes they had access to. This will make your code a little more complicated, because you'd need to parse the list items to get the HTML out and concatenate them together, but it provides full security.

  2. Use security trimming to include different CSS stylesheets that would hide different CSS classes based on access. This approach doesn't really "trim" things out, but the user wouldn't see them. If the requirement is more about user experience than pure security, this would work and mostly separate your presentation from your trimming logic.

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.