清除分支中文件夹的特殊权限 [英] Clearing special permissions from folders in a branch

查看:20
本文介绍了清除分支中文件夹的特殊权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是一个相当大的项目,只有一个主干分支.其中大部分使用默认权限,但少数文件夹具有自定义权限 - 例如,仅允许Builders"组签入.

We're a fairly large project with a single trunk branch. Most of it uses the default permissions, but a few folders have custom permissions - say, only "Builders" group is allowed to check-in.

我们希望允许人们在主干之外创建自己的私有分支,他们可以在其中自由签入并稍后合并(希望经常).但是,创建分支时,特殊权限会随文件夹一起复制,这意味着人们无法自由签入其分支.

We want to allow people to create their own private branches out of trunk, where they can freely check-in and merge later (hopefully often). However, creating a branch, the special permissions are copied along with the folders, meaning that people can't freely check-in into their branch.

  • 有没有办法从分支或文件夹中清除特殊权限?
  • 有没有办法自动执行此操作,因此任何在/private/** 下创建分支的人都不会遇到此问题?

推荐答案

我发现了 tf 权限(例如:tf 权限/inherit:yes itemSpec).但是,/recursive 开关不适用于它.我想我可以写一些递归运行它的东西......

I found out about tf permission (Example: tf permission /inherit:yes itemSpec). However, the /recursive switch doesn't work with it. I guess I could write something that runs it recursively...

我终于开始为它编写一个工具了:

I finally got around 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.
"
                        + "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;
    }
}

这篇关于清除分支中文件夹的特殊权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆