有没有办法在TFS中找到自定义权限

Is there a way to find customized permissions in TFS

我们计划将我们的 Team Foundation Server 服务器移至新域,因此任何自定义权限都需要 updated/corrected。 我想知道是否有一种工具或一些示例代码可以用来扫描 TFS 文件和文件夹(如源代码管理资源管理器中所示)以查找与默认权限不同的权限。 请注意,不幸的是,我们仍在使用 TFS 2010。 我想要的是获取或构建一个汇总列表,说明在此路径中,用户 X 的安全性更改为 a,用户 Y 更改为 b,等等,如果继承被关闭。如果路径没有任何安全更改,那么我希望它不包含在报告中。只要报告采用可编辑格式(例如 csv、xml、html、txt)

,我就可以构建代码以在必要时删除它

我很愿意自己创建这个工具,我只是不确定从哪里开始。似乎这方面的库太大了,而且这些东西通常没有很好的记录。如果我创造了这个,我会分享我能做的。 谢谢

你可以试试Team Foundation Sidekicks。 Team Foundation Sidekicks 包括 Permission Sidekick,它提供以下功能:

  • Select 有效权限待审核用户
  • 查看 Team Foundation Server 组用户是 (Windows 不包括域组)
  • 查看用户的全局 TFS 服务器权限
  • Select团队项目查看项目具体有效权限
  • 查看用户团队项目的权限
  • Select项目的版本控制folder/file并查看有效 该项目的版本控制权限(包括指示 权限是继承的还是显式设置的)
  • Select 项目区域并查看该区域的有效权限
  • 对于每一个有效的权限显示,查看每一个的原因 有效的权限设置——即针对哪些组Allow/Deny 权限已设置,因此有效权限是基于什么 在

我最终编写了代码来执行此操作。很抱歉花了这么长时间 post 这个。
它创建一个文本文件,指定 TFS 中具有明确安全性的每个项目的安全性。它可能会提供更多需要的信息,但很适合我的需要。 如果您使用它,您应该将“TFSServer”替换为您的实际服务器名称,并将“CollectionName”替换为实际的源代码集合名称,通常是“DefaultCollection”。

请注意,这是在 VB 中编写的,需要以下参考资料。

Default references of System, System.Core, XML, and XML.Linq are included.
From "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0" Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.Common
Microsoft.TeamFoundation.VersionControl.Client

Option Explicit On
Option Strict On
Option Infer Off

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.VersionControl.Client
Imports Microsoft.TeamFoundation.Framework.Client
Imports System.IO

Namespace EnumerateTFSSecurity
    Friend Class Program
        Private Shared UpdateConsoleIndex As Integer

        Shared Sub Main()
            Try
                Dim tfs As TfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri("http://TFSServer:8080/tfs/CollectionName"))
                Dim OutputFileName As String = ".\EnumTFSSec.txt"

                If Command().Length <> 0 Then
                    OutputFileName = Command()
                End If

                tfs.EnsureAuthenticated()

                Dim VersionControl As VersionControlServer = tfs.GetService(Of VersionControlServer)()

                Dim OutputFile As StreamWriter = New StreamWriter(OutputFileName)
                Dim AllProjs() As TeamProject = VersionControl.GetAllTeamProjects(True)

                For Each TeamProj As TeamProject In AllProjs
                    GetChildItems(VersionControl, TeamProj.ServerItem, OutputFile)

                    OutputFile.Flush()
                Next

            Catch e As Exception
                Dim ex As String = e.Message
                Console.WriteLine("!!EXCEPTION: " & e.Message)
                Console.WriteLine("Continuing... ")
            End Try

            Console.WriteLine("========")
            Console.Read()
        End Sub

        Private Shared Sub GetChildItems(VersionControl As VersionControlServer, ItemPath As String, OutputFile As StreamWriter)
            Dim Items() As Item = VersionControl.GetItems(ItemPath & "/*").Items
            Dim FolderPaths As Specialized.StringCollection
            Dim FilePaths As List(Of String)

            FolderPaths = New Specialized.StringCollection
            FilePaths = New List(Of String)

            GetSecurityInfo(VersionControl, {ItemPath}, OutputFile)

            For Each Item As Item In Items
                If Item.ItemType = ItemType.Folder Then
                    FolderPaths.Add(Item.ServerItem)

                Else
                    FilePaths.Add(Item.ServerItem)
                End If
            Next

            For Each Folder As String In FolderPaths
                GetChildItems(VersionControl, Folder, OutputFile)
            Next

            If FilePaths.Count <> 0 Then
                GetSecurityInfo(VersionControl, FilePaths.ToArray, OutputFile)
            End If
        End Sub

        ' Define other methods and classes here
        Private Shared Sub GetSecurityInfo(VersionControl As VersionControlServer, ByVal ItemPaths() As String, OutputFile As StreamWriter)
            Dim result As List(Of String) = New List(Of String)
            Dim SecurityList() As ItemSecurity
            Dim SecurityInfo As StringBuilder = Nothing
            Dim Clearstringlength As Integer
            Dim ConsoleText As String

            Try
                SecurityList = VersionControl.GetPermissions(ItemPaths, RecursionType.None)
                SecurityInfo = New StringBuilder

                If SecurityList IsNot Nothing AndAlso SecurityList.Length <> 0 Then
                    For Each ItemSecurity As ItemSecurity In SecurityList
                        With ItemSecurity
                            If .Inherit = False Then
                                SecurityInfo.Append(" - Inherit: False")
                            End If

                            For Each Entry As AccessEntry In .Entries
                                If (Entry.Allow.Length <> 0 OrElse Entry.Deny.Length <> 0) Then
                                    SecurityInfo.AppendLine()
                                    SecurityInfo.AppendLine("    Identity: " & Entry.IdentityName)

                                    If Entry.Allow.Length <> 0 Then
                                        SecurityInfo.Append("        Allow: ")

                                        For Each Value As String In Entry.Allow
                                            SecurityInfo.Append(Value & "; ")
                                        Next

                                        SecurityInfo.Remove(SecurityInfo.Length - 2, 2)

                                        If Entry.Deny.Length <> 0 Then
                                            SecurityInfo.AppendLine()
                                        End If
                                    End If

                                    If Entry.Deny.Length <> 0 Then
                                        SecurityInfo.Append("        Deny: ")

                                        For Each Value As String In Entry.Deny
                                            SecurityInfo.Append(Value & "; ")
                                        Next

                                        SecurityInfo.Remove(SecurityInfo.Length - 2, 2)
                                    End If
                                End If
                            Next

                            If SecurityInfo.Length <> 0 Then
                                SecurityInfo.AppendLine()
                            End If
                        End With

                        If UpdateConsoleIndex Mod 25 = 0 Then
                            ConsoleText = "Item:" & ItemSecurity.ServerItem
                            Clearstringlength = If(Console.CursorTop = 0, 0, Console.CursorTop * Console.BufferWidth - 1) - ConsoleText.Length
                            Console.CursorTop = 0
                            Console.CursorLeft = 0

                            If Clearstringlength > 0 Then
                                ConsoleText &= New String(" "c, Clearstringlength)
                            End If

                            Console.WriteLine(ConsoleText)
                        End If

                        If SecurityInfo IsNot Nothing AndAlso SecurityInfo.Length > 0 Then
                            If UpdateConsoleIndex <> 0 Then
                                OutputFile.WriteLine()
                            End If

                            OutputFile.Write("Item:" & ItemSecurity.ServerItem)

                            OutputFile.Write(SecurityInfo.ToString())

                            SecurityInfo.Clear()
                        End If

                        UpdateConsoleIndex += 1
                    Next
                End If

            Catch e As Exception
                Dim ex As String = e.Message
                Console.WriteLine("!!EXCEPTION: " & e.Message)
                Console.WriteLine("Continuing... ")
            End Try
        End Sub
    End Class
End Namespace