将AD用户添加到TFS组时,有没有办法在TFS中发表评论?

时间:2015-11-04 14:28:03

标签: security tfs

我想知道当我将AD用户添加到TFS组或更改用户组时,我是否可以在Team Foundation Server中的某处发表评论,以供审核。

2 个答案:

答案 0 :(得分:0)

我创建了一个PowerShell脚本来记录对TFS用户数据库的day2day更改,并查询AD以找出谁批准了此更改。 现在我们有了一个自制的数据库。

答案 1 :(得分:-1)

为了它的价值 - 我写了一个C#方法来从每个TFS组中提取所有成员的列表。希望有所帮助!

编辑:" 这是作为答案发布的,因为" xidada"我打算写一个脚本来提取信息,因为我已经有了获取所需信息的代码,我认为代码可以作为帮助他/她使用脚本的指南"

 private void btn_GetNow_Click()
    {
        TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://server/collection"));
        tfs.EnsureAuthenticated();

        TfsConfigurationServer srv = tfs.ConfigurationServer;

        CatalogNode configurationServerNode = srv.CatalogNode;

        // Query the children of the configuration server node for all of the team project collection nodes
        ReadOnlyCollection<CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
              new Guid[] { CatalogResourceTypes.ProjectCollection },
              false,
              CatalogQueryOptions.None
            );

        Guid tpcId = new Guid(tpcNodes[0].Resource.Properties["InstanceId"]);
        TfsTeamProjectCollection tpc = srv.GetTeamProjectCollection(tpcId);

        // get a reference to the work item tracking service
        var workItemStore = tpc.GetService<WorkItemStore>();
        List<Identity> result = new List<Identity>();
        // iterate over the projects
        foreach (Project project in workItemStore.Projects)
        {
            Console.WriteLine("\tProject: {0}", project.Name);
            try
            {
                VersionControlServer versionControl = (VersionControlServer)tpc.GetService(typeof(VersionControlServer));
                TeamProject teamProject = versionControl.GetTeamProject(project.Name);
                IGroupSecurityService gss = (IGroupSecurityService)tpc.GetService<IGroupSecurityService>();
                Identity[] appGroups = gss.ListApplicationGroups(teamProject.ArtifactUri.AbsoluteUri);

                foreach (Identity group in appGroups)
                {
                    rtb_Users.AppendText(group.DisplayName + "\n");
                    Identity[] groupMembers = gss.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);
                    foreach (Identity member in groupMembers)
                    {
                        if (member.Members != null)
                        {
                            foreach (string memberSid in member.Members)
                            {
                                Identity memberInfo = gss.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);
                                if (memberInfo.Type == IdentityType.WindowsUser)
                                {
                                    if (!result.Contains(memberInfo))
                                    {
                                        result.Add(memberInfo);
                                        rtb_Users.AppendText("\t\t" + memberInfo.AccountName + " - " + memberInfo.DisplayName + " - " + memberInfo.Domain + "\n");
                                    }
                                    else
                                    {
                                        Console.WriteLine("\t\tUser already available " + memberInfo.AccountName);
                                    }

                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\tThe Project: '{0}' throws an exception: {1} and will be ignored.", project.Name, ex.Message);
            }
        } 
    } 

此方法已从我的应用程序中提取出来,需要根据您的需求进行定制。