Modifying permissions on files/items in version control using TFS API
Using the TFS API, I need to change permissions on a specified file/item in version control. I need to edit permissions for a particular user or for all users.
For instance, my app will prevent check-in of a specified file for all users. Then, it would allow check-in of that file for a particular user开发者_如何学Go, perform check in of the file, then allow check-in again for all users.
How can I do this? Please provide example code.
With guidance from Vicky Song at Microsoft (http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/289fb1f4-4052-41f1-b2bf-f97cd6d9e389/), here is what I ended up with:
public void SetCheckInLockForFile(string fileAndPath, string userGroup, bool checkInLock)
{
// sets of the CheckIn permission for the specified file
List<SecurityChange> changes = new List<SecurityChange>();
string[] perm = new string[] { PermissionChange.ItemPermissionCheckin };
if (checkInLock)
changes.Add(new PermissionChange(fileAndPath, userGroup, null, perm, null));
else
changes.Add(new PermissionChange(fileAndPath, userGroup, null, null, perm));
SecurityChange[] actualChanges = versionControlServer.SetPermissions(changes.ToArray());
}
When CheckInLock is true, a deny permission is added for check in. When CheckInLock is false, the check in permission is removed, allowing check in permission for the specified file to be inherited.
精彩评论