TFS 2018u1. I'm building an extension with custom context menu commands for release definitions. I'd like some of them to be conditionally invisible (upon the rights of the current user). Any way to hide them?
Deliberately not calling VSS.register()
doesn't help; the custom commands are still there, just do nothing.
It's not a security measure, it's a usability thing (the menu is getting crowded).
EDIT: in the Contribution data structure there's a property called constraints
. It's not documented, no idea where it comes from. Probably the manifest. The only mention of constraints I could find is in the TFX tool sources. Apparently, constraints
is a valid value in the manifest JSON (probably under the contribution object), and it's supposed to be an array. One assumes, one of ContributionConstraint
objects. The latter is kind of documented.
A constraint object has a name
property that, according to the docs, contains a reference to an IContributionFilter
class. I couldn't find any mentions of that class neither in docs nor in TypeScript sources. However, there's an interface Microsoft.VisualStudio.Services.ExtensionManagement.Sdk.Server.IContributionFilter
in assembly Microsoft.VisualStudio.Services.ExtensionManagement.Sdk.Server.dll
, and it has a Name
property. There are derived classes in bin\Plugins\Microsoft.VisualStudio.Services.ExtensionManagement.Sdk.Plugins.dll
:
- ExtensionLicensedFilter
- FeatureFlagFilter
- LegacyFeatureEnabledFilter
- ActiveExtensionFilter
- FeatureFilter
- SecurityFilter
Concentrating on the latter. The name is "Security". Looks like it supports the following properties:
- namespaceId (GUID) - AKA security namespace
- namespaceToken (string) - securable object token
- permission (int) - bit mask, similar to those in an ACL
- allowSystemContext (optional bool) - ???
- serviceInstanceType (optional GUID) - only matters for VSTS
If you specify a constraint in the manifest JSON under a contribution object, at the very least it propagates through TFS data structures and shows up under VSS.getContribution()
in the extension's script. Now, on to the details of the security check...