Elevate Permissions
g
is there anyway in code to elevate user permissions temporarily, or run a publish command using an admin users account?
s
Not sure what you want? Editor presses the publish button and you want to pretend an admin did it or..?
g
yeah on a notification, we're doing some variant unpublishing, and we want the user to unpublish all variants, regardless to permission levels
so when they unpublish one variant, we unpublish all variants... (they need to have permissions to do that)
s
This might open up security loopholes but you can hook into (un)publishing notifications and do what you need to https://docs.umbraco.com/umbraco-cms/reference/notifications/contentservice-notifications
g
we currently have this:
Copy code
csharp
  var isCulturingUnPublishing = node.GetCulturesUnpublishing();
  if (isCulturingUnPublishing?.Any() ?? false)
  {
      foreach (var culture in node.PublishedCultures)
          node.UnpublishCulture(culture);
  }
but If the user has access to say, the en-us language only, the unpublish does not unpublish every variant.
s
triple backticks around that will make it more readible 😉
g
done 🙂
s
I think you probably need to instantiate a new contentservice, get the content item and then do the unpublish, then it shouldn't have the context of the user who initiated it. But I'm surprised it has the context now, good permissions model I guess 😁
g
ah ok, I see... I'll give it a go, thanks
2 Views