2012-02-27 40 views
5

我們是一個相當大的項目,只有一箇中繼分支。其中大部分使用默認權限,但少數文件夾具有自定義權限 - 比方說,只有「Builders」組可以簽入。清除分支中文件夾的特殊權限

我們希望允許人們從樹幹中創建自己的私人分支,他們可以在那裏自由簽入併合並(希望經常)。但是,創建分支時,特殊權限會與文件夾一起復制,這意味着人們無法自由地登錄分支。

  • 有沒有辦法清除分支機構或文件夾的特殊權限?
  • 有沒有辦法自動這樣做,所以任何在/ private/**下創建分支的人都不會遇到這個問題?

回答

6

我找到了約tf permission(例如:tf permission /inherit:yes itemSpec)。但是,/遞歸開關不適用於它。我想我可以寫一個運行它遞歸的東西......

編輯:我終於可以寫它的工具:

static int Main(string[] args) 
{ 
    if (args.Length == 0 || args.Any(a => !a.StartsWith("$/"))) 
    { 
     Console.WriteLine("Removes all explicit permissions and enables inheritance for a subtree.\n" 
         + "Example: " + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + " $/project/path1 $/project/path2"); 
     return 3; 
    } 

    WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); 
    if (wi == null) 
    { 
     Console.WriteLine("Can't determine workspace for current directory: " + Environment.CurrentDirectory); 
     return 2; 
    } 

    var Tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(wi.ServerUri); 
    VersionControlServer VersionControlServer = Tfs.GetService<VersionControlServer>(); 

    Console.WriteLine("Server: {0} Getting permissions...", wi.ServerUri); 
    ItemSecurity[] perms = VersionControlServer.GetPermissions(args, RecursionType.Full); 

    Console.WriteLine("Will remove explicit permissions from the following items:"); 

    var changes = new List<SecurityChange>(); 
    foreach (ItemSecurity perm in perms) 
    { 
     Console.WriteLine(" " + perm.ServerItem); 

     changes.Add(new InheritanceChange(perm.ServerItem, inherit: true)); 
     foreach (AccessEntry e in perm.Entries) 
     { 
      changes.Add(new PermissionChange(perm.ServerItem, e.IdentityName, null, null, PermissionChange.AllItemPermissions)); 
     } 
    } 

    Console.WriteLine("Enter to confirm:"); 
    Console.ReadLine(); 

    var successfulchanges = VersionControlServer.SetPermissions(changes.ToArray()); 
    if (successfulchanges.Length == changes.Count) 
    { 
     Console.WriteLine("Explicit permissions removed from all items"); 
     return 0; 
    } 
    else 
    { 
     Console.WriteLine("Explicit permissions removed only from:"); 
     foreach (var c in successfulchanges) 
     { 
      Console.WriteLine(" " + c.Item); 
     } 

     return 1; 
    } 
} 
+3

感謝這個,我剛剛花了一個小時的努力由於一些愚蠢的明確許可而刪除分支。這鱈魚在2秒內固定它:) – DaveShaw 2014-08-07 09:52:00

+0

你在哪裏執行此代碼?你能告訴你如何使用它?我堅持我認爲是一個類似的事情與一些文件夾的權限,防止我刪除或重命名分支。 – 2014-11-26 12:33:40

+0

@ mats-isaksson創建一個新的控制檯應用程序 – 2015-03-10 16:16:14