TFS 2012 API - Set Version Control Permissions?

冷暖自知 提交于 2019-12-24 09:02:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!