Clearing special permissions from folders in a branch

We are a fairly large project with one branch of the trunk. Most of them use default permissions, but several folders have user permissions - let's say only registration of the "Builders" group is allowed.

We want to allow people to create their own private branches from the trunk, where they can freely register and merge later (I hope often). However, when creating a branch, special permissions are copied along with the folders, which means that people cannot freely register in their branch.

  • Is there a way to clear special permissions from a branch or folder?
  • Is there a way to do this automatically, so anyone who creates a branch under / private / ** will not run into this problem?
+5
source share
1 answer

I found out about tf resolution (example:) tf permission /inherit:yes itemSpec. However, the recursive switch does not work with it. I guess I could write something that recursively runs it ...

Edit: I finally got to writing a tool for it:

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;
    }
}
+6
source

All Articles