问题
I am trying to set the various version control permissions of a TFS item via the TFS API. Here is the code I am using that successfully sets the read and checkout permissions for the given folder path:
IIdentityManagementService ims = tpc.GetService<IIdentityManagementService>();
TeamFoundationIdentity userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"Guest",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
ISecurityService ss = tpc.GetService<ISecurityService>();
SecurityNamespace securityNamespace = ss.GetSecurityNamespace(SecurityConstants.RepositorySecurityNamespaceGuid);
securityNamespace.SetPermissions(folderPath, userIdentity.Descriptor, RegistryServicePermissions.AllPermissions, 0, true);
What I don't understand is the value to use in the 3rd parameter (the "allow" parameter) of SetPermissions in order to set various things such as checkin, manage branch, etc. the MSDN documentation is vary vague.
public abstract AccessControlEntry SetPermissions(
string token,
IdentityDescriptor descriptor,
int allow,
int deny,
bool merge
)
The description for the "allow" parameter simply says:
allow
Type: System.Int32
Any help is greatly appreciated.
回答1:
The contents of allow should be the value of the exact permission you want to allow on this particular identity eg. VersionedItemPermissions.Read
Since it is an enum it is listed as an int32 since enums to support various entities in TFS ie Build, Version Control, Work Item Tracking etc.
回答2:
You can use the int parameter like this:
int allow = (int)Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.Read;
int deny = (int)(Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.AdminProjectRights |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.Checkin |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.CheckinOther |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.PendChange |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.Label |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.ReviseOther |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.LabelOther |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.Lock |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.ManageBranch |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.Merge |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.UndoOther |
Microsoft.TeamFoundation.VersionControl.Common.VersionedItemPermissions.UnlockOther);
来源:https://stackoverflow.com/questions/14691924/tfs-2012-api-set-version-control-permissions