AccuRev locks are often applied in the following way to give only members of a specific group the ability to promote changes to or from a stream; no one outside the group can promote to/from the stream.
accurev lock -c <comment> [-kt | -kf] -e <group> <stream>
This translates to: Lock promotions [to | from] <stream> for everyone except those in group <group>.
PromoRights.cs
lists all users and their promote
command privileges for streams in the depots listed in PromoRights.exe.config
. The tab-delimited program results are sent to the console.
Adelbert None
Banazir None
Daisy ExceptFor
Hilda None
Mantissa ExceptFor
Razanur ExceptFor
...
- See also
- AcLocks constructor, LockStreams.cs, Locks.cs
- PromoRights.exe.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="Depots" type="AcUtils.DepotsSection, AcUtils, Version=1.6.4.0, Culture=neutral, PublicKeyToken=26470c2daf5c2e2f, processorArchitecture=MSIL" />
</configSections>
<Depots>
<depots>
</depots>
</Depots>
<system.diagnostics>
<assert assertuienabled="false" />
<sources>
<source name="PromoRights">
<listeners>
<remove name="Default" />
<add name="AcLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</listeners>
</source>
</sources>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
using System.Collections.Generic;
namespace PromoRights
{
class Program
{
#region class variables
private static DepotsCollection _depots;
private static AcUsers _users;
private static AcLocks _locks;
#endregion
static int Main()
{
Task<bool> ini = initAsync();
if (!ini.Result) return 1;
return (promoRights()) ? 0 : 1;
}
private static bool promoRights()
{
bool ret = false;
try
{
foreach (AcUser
user in _users.OrderBy(n => n))
{
SortedSet<string> groups = user.Principal.Members;
IEnumerable<string> query =
from ef in _locks.Select(lk => lk.ExceptFor)
where groups.Any(g => g == ef)
select ef;
string found = query.FirstOrDefault();
Console.WriteLine($"{user}\t{((found == null) ? "None" : "ExceptFor")}");
}
ret = true;
}
catch (Exception ecx)
{
AcDebug.Log($"Exception caught and logged in Program.promoRights{Environment.NewLine}{ecx.Message}");
}
return ret;
}
private static async Task<bool> initAsync()
{
if (!AcDebug.initAcLogging())
{
Console.WriteLine("Logging support initialization failed.");
return false;
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);
string prncpl = await AcQuery.getPrincipalAsync();
if (String.IsNullOrEmpty(prncpl))
{
AcDebug.Log($"Not logged into AccuRev.{Environment.NewLine}Please login and try again.");
return false;
}
if (!initAppConfigData()) return false;
_users = new AcUsers(null, null, includeGroupsList: true);
_locks = new AcLocks();
bool[] arr = await Task.WhenAll(
_users.initAsync(),
_locks.initAsync(_depots)
);
return (arr != null && arr.All(n => n == true));
}
private static bool initAppConfigData()
{
bool ret = true;
try
{
DepotsSection depotsConfigSection = ConfigurationManager.GetSection("Depots") as DepotsSection;
if (depotsConfigSection == null)
{
AcDebug.Log("Error in Program.initAppConfigData creating DepotsSection");
ret = false;
}
else
_depots = depotsConfigSection.Depots;
}
catch (ConfigurationErrorsException exc)
{
Process currentProcess = Process.GetCurrentProcess();
ProcessModule pm = currentProcess.MainModule;
AcDebug.Log($"Invalid data in {pm.ModuleName}.config{Environment.NewLine}{exc.Message}");
ret = false;
}
return ret;
}
}
}