By Wayne Brill
The Vault API has several functions for setting security permissions on things in the Vault. The example on this blog post should be very helpful if you are trying to learn how to set permissions: Effective Permissions 2013
One thing that may not be obvious is that UpdateSystemACL() is not supported for files. Instead you can use SetSystemACL(). Here is an update to the VaultFileBrowser SDK C# sample that uses this function. (replaces FindButton_Click in FinderForm.cs). With this additional code a file that is found will have permissions set for it.
private void FindButton_Click
(object sender, System.EventArgs e)
{
//make sure search conditions
//have been added
if (m_criteriaListBox.Items.Count > 0)
{
//clear out previous search
//results if they exist
m_searchResultsListBox.Items.Clear();
//build our array of SearchConditions
// to use for the file search
SrchCond[] conditions =
new SrchCond[m_criteriaListBox.Items.Count];
for (int i = 0; i <
m_criteriaListBox.Items.Count; i++)
{
conditions[i] =((ListBoxSrchCondItem)
m_criteriaListBox.Items[i]).SrchCond;
}
string bookmark = string.Empty;
SrchStatus status = null;
// added to existing SDK sample VaultFileBrowser
// (around line #196 in FinderForm.cs file.
try
{
File[] myFiles = m_serviceManager.
DocumentService.FindFilesBySearchConditions
(conditions, null, null, false, true,
ref bookmark, out status);
Group group = m_serviceManager.
AdminService.GetGroupByName("Everyone");
// Could use this to get existing
// permissions on the file
// ACL[] acls = m_serviceManager.
// SecurityService.GetACLsByEntityIds
//(new long[] { myFiles[0].MasterId });
// ACE[] aces = acls[0].ACEArray;
ACE ace = new ACE();
ace.UserGrpId = group.Id;
AccessPermis readAccessPermis =
new AccessPermis();
readAccessPermis.Id = 1;
readAccessPermis.Val = true;
AccessPermis writeAccessPermis =
new AccessPermis();
writeAccessPermis.Id = 2;
writeAccessPermis.Val = true;
AccessPermis deleteAccessPermis =
new AccessPermis();
deleteAccessPermis.Id = 3;
deleteAccessPermis.Val = true;
ace.PermisArray = new AccessPermis[]
{ readAccessPermis, writeAccessPermis,
deleteAccessPermis };
ACE[] aces = new ACE[1];
aces[0] = ace;
ACL myAcl = m_serviceManager.
SecurityService.AddSystemACL(aces);
m_serviceManager.SecurityService.
SetSystemACLs(new long[]
{ myFiles[0].MasterId }, myAcl.Id);
}
catch (Exception ex)
{
Debug.Print(ex.ToString());
}
// End Added for setting ACL
//search for files
List<File> fileList = new List<File>();
while (status == null || fileList.Count
< status.TotalHits)
{
File[] files = m_serviceManager.
DocumentService.
FindFilesBySearchConditions
(conditions, null, null, true, true,
ref bookmark, out status);
if (files != null)
fileList.AddRange(files);
}
if (fileList.Count > 0)
{
//iterate through found files
//and display them in the search
//results list box
foreach (File file in fileList)
{
//create the list item that
//will wrap the File
ListBoxFileItem fileItem =
new ListBoxFileItem(file);
m_searchResultsListBox.
Items.Add(fileItem);
}
}
//update the items count label
m_itemsCountLabel.Text =
(fileList.Count > 0) ?
fileList.Count + " Items" : "0 Items";
}
}