Set user/groups programatically

  • 13 October 2005
  • 5 replies
  • 2 views

Badge +2
I need to make use of K2Manager and set up the user and usergroups programatically reading from the Active directory.

Would appreciate any help.

5 replies

Badge +8
You could probably use a combination of the K2MNG.dll assembly and the DirectorySearcher namespace to achieve what you want to do.

I'd suggest to start with the K2 Studio Help file, under the K2.net Management Objects chapter, and specifically the UpdateProcUserPermissions Method heading...
Badge +2
We have tried to code similarly but still the users/groups are not added

Here is the code snippet :P

foreach(ProcessSet ps in pf.ProcessSets)
{
if (!ps.Name.Equals("keshava")) { continue; }

ps.LoadUserPermissions(MGR);
ps.LoadGroupPermissions(MGR);

Response.Write("<br>adding "+apiUser+" to "+ps.Name +":"+MGR.UpdateProcUserPermissions(ps.ProcSetID,NewUserPerm(apiUser,ps.ProcSetID,ps.Name,ps.FullName)));
foreach(Model.Security.AdGroup g in groups)
{
ProcSetPermissions pp = NewPerm(ps.ProcSetID,ps.Name,ps.FullName);
pp.GroupName = @"rocd1"+g.AD_GROUP_ID;
MGR.GetGroupPermissions(@"rocd1"+g.AD_GROUP_ID).Add(pp);

ps.LoadGroupPermissions(MGR);
Response.Write("<br>adding "+g.AD_GROUP_ID+" to "+ps.Name+":"+MGR.UpdateProcGroupPermissions(ps.ProcSetID,NewGroupPerm(@"rocd1"+g.AD_GROUP_ID,ps.ProcSetID,ps.Name,ps.FullName)));
}
}


private static Permissions NewUserPerm(string u,int ProcSetID,string ProcessName,string ProcessFullName)
{
ProcSetPermissions p = NewPerm(ProcSetID,ProcessName,ProcessFullName);
p.UserName = u;
Permissions r = new Permissions();
r.Add(p);
return r;
}

private static Permissions NewGroupPerm(string g,int ProcSetID,string ProcessName,string ProcessFullName)
{
ProcSetPermissions p = NewPerm(ProcSetID,ProcessName,ProcessFullName);
p.GroupName = g;
Permissions r = new Permissions();
r.Add(p);
return r;
}

private static ProcSetPermissions NewPerm(int ProcSetID,string ProcessName,string ProcessFullName)
{
ProcSetPermissions p = new ProcSetPermissions();
p.GroupName = null;
p.UserName = null;
p.ProcSetID = ProcSetID;
p.ProcessName = ProcessName;
p.ProcessFullName = ProcessFullName;
p.Admin = true;
p.Start = true;
p.View = true;
p.ViewPart = true;
p.ServerEvent = true;
return p;
}

What is wrong here? :(
would be happy if you could post some sample code. :idea:

Thanx in anticipation
Keshava
Badge +2
Here is the code snippet to make it work :lol: :) 8)


foreach(ProcessSet ps in pf.ProcessSets)
{
if (!ps.Name.Equals("keshava")) { continue; }


foreach(Model.Security.AdGroup g in groups)
{
SourceCode.K2Mng.Permissions perms=MGR.GetProcessGroupPermissions(ps.ProcSetID);
ProcSetPermissions pp = NewPerm(ps.ProcSetID,ps.Name,ps.FullName);
pp.GroupName = @"rocd1"+g.AD_GROUP_ID;
MGR.UpdateProcGroupPermissions(ps.ProcSetID,perms);

}
}


private static ProcSetPermissions NewPerm(int ProcSetID,string ProcessName,string ProcessFullName)
{
ProcSetPermissions p = new ProcSetPermissions();
p.GroupName = null;
p.UserName = null;
p.ProcSetID = ProcSetID;
p.ProcessName = ProcessName;
p.ProcessFullName = ProcessFullName;
p.Admin = true;
p.Start = true;
p.View = true;
p.ViewPart = true;
p.ServerEvent = true;
return p;
}
Badge +11
Thank you Keshavbs for posting the correct code...

Does this mean that you are sorted for the moment?

Regards,
Ockert
Badge +2
Yes.I could successfully create the user/groups.
I did miss a line in the above code when posting in this forum.

perms.Add(pp);

Add this line before calling MGR.updateProcGroupPermissions and you are ready to Goooo......

Thanx

Reply