1

ユーザー (プロジェクト コレクションに接続しているユーザー) がプロジェクト コレクションの管理者グループのメンバーであるかどうかを確認する必要があります。また、プロジェクトについても同じことを行う必要があります。

そのための最も正しい方法が必要です。

現在、私は次の方法を使用していますが、それが完璧な方法であるかどうかはわかりません。

//Get the IdentityManagementService from the Project Collection
IIdentityManagementService LIdentityService = (IIdentityManagementService)ProjectCollection.GetService(typeof(IIdentityManagementService));    
//Search for user identity by user name
TeamFoundationIdentity LUserIdentity = LIdentityService.ReadIdentity(IdentitySearchFactor.AccountName, {Username}, MembershipQuery.Expanded, ReadIdentityOptions.None);
//Get Guid of the same Project Collection to use as scope
String Id = ProjectCollection.InstanceId.ToString();
//Get the Administrators group for Project Collection scope *
TeamFoundationIdentity LAdminIdentity = LIdentityService.ReadIdentity(IdentitySearchFactor.AdministratorsGroup, Id, MembershipQuery.Expanded, ReadIdentityOptions.None);

IsAdmin = false;
//Traverse through the groups of the user and check if administrators group is also one of them
foreach (IdentityDescriptor member in LUserIdentity.MemberOf)
{
    if (member.Identifier.Equals(LAdminIdentity.Descriptor.Identifier, StringComparison.CurrentCultureIgnoreCase))
        IsAdmin = true;
}

これは、あるセットアップでは正常に機能しますが、Team Foundation Server の別のセットアップでは、管理者グループの取得中に次のエラーが発生します。「Team Foundation ID スコープ {プロジェクト コレクションのガイド} が存在しません。」

4

0 に答える 0