Invert Umbraco extension condition

is it possible when creating a custom extension to invert the condition rule in the manifest, so it’s equivalent of NOT? So for example:

“conditions”: [
   {
      "alias": "Umb.Condition.HasPermission",
      "match": "Publish",
      "invert": true <====== something like this i.e. apply if user does NOT have publish permission
   }
]


HI Gavin!

It is possible, the standard pattern is to write your own condition that performs the permission check and flips the permitted state. Conditions are just extensions that extend UmbConditionBase and set this.permitted = boolean.

Just a fair warning, negative conditions usually age badly, if you want to do something like ‘ Show to users without publish’ can change meaning every time you add a new permission / restructure things.

It might be better to seperate it in groups. “Show to users in group x” (user’s without publish permissions)

1 Like

I’m interrested in your use case. What do you want to do?

In my scenario I wanted to display a custom button if the current user wasn’t an admin, essentially a “send for approval” button. So I was wanting to invert the IsAdmin condition as an easier way than having to check membership of a number of different groups.