private void InitialiseAccessTeamConfiguration() { var sw = new Stopwatch(); sw.Start(); //create a new security role with basic level only on all contact privileges var accessTeamTestRole = crm.CloneSecurityRole("Salesperson"); accessTeamTestRole.Name = "AccessTeamTest"; accessTeamTestRole.RoleId = Guid.Parse("c8357b35-8a17-4601-997a-5d011960ba2b"); var contactPriv = accessTeamTestRole.Privileges["contact"]; var newPriv = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in contactPriv) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv.Add(priv.Key, newP); } accessTeamTestRole.Privileges.Remove("contact"); accessTeamTestRole.Privileges.Add("contact", newPriv); var accountPriv = accessTeamTestRole.Privileges["account"]; newPriv = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in accountPriv) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv.Add(priv.Key, newP); } accessTeamTestRole.Privileges.Remove("account"); accessTeamTestRole.Privileges.Add("account", newPriv); crm.AddSecurityRole(accessTeamTestRole); //create some users with the new role var user = new Entity("systemuser"); user["internalemailaddress"] = "*****@*****.**"; user["businessunitid"] = crm.RootBusinessUnit; user["islicensed"] = true; user.Id = Guid.Parse("d8357b35-8a17-4601-997a-5d011960ba2b"); testUser1 = crm.CreateUser(orgAdminService, user, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser1Service = crm.CreateOrganizationService(testUser1.Id); var user2 = new Entity("systemuser"); user2["internalemailaddress"] = "*****@*****.**"; user2["businessunitid"] = crm.RootBusinessUnit; user2["islicensed"] = true; user2.Id = Guid.Parse("e8357b35-8a17-4601-997a-5d011960ba2b"); testUser2 = crm.CreateUser(orgAdminService, user2, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser2Service = crm.CreateOrganizationService(testUser2.Id); var user3 = new Entity("systemuser"); user3["internalemailaddress"] = "*****@*****.**"; user3["businessunitid"] = crm.RootBusinessUnit; user3["islicensed"] = true; user3.Id = Guid.Parse("f8357b35-8a17-4601-997a-5d011960ba2b"); testUser3 = crm.CreateUser(orgAdminService, user3, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser3Service = crm.CreateOrganizationService(testUser3.Id); var salesUser = new Entity("systemuser"); salesUser["internalemailaddress"] = "*****@*****.**"; salesUser["businessunitid"] = crm.RootBusinessUnit; salesUser["islicensed"] = true; salesUser.Id = Guid.Parse("09357b35-8a17-4601-997a-5d011960ba2b"); crm.CreateUser(orgAdminService, salesUser, new Guid[] { SecurityRoles.Salesperson }); salesUserService = crm.CreateOrganizationService(salesUser.Id); //create some access team templates var q = new QueryExpression("teamtemplate"); q.ColumnSet = new ColumnSet("teamtemplatename"); var existing = orgAdminService.RetrieveMultiple(q); if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestWriteContact")) { CreateAccessTeamTemplate("TestWriteContact", 2, AccessRights.WriteAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestReadContact")) { CreateAccessTeamTemplate("TestReadContact", 2, AccessRights.ReadAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestDeleteContact")) { CreateAccessTeamTemplate("TestDeleteContact", 2, AccessRights.DeleteAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestAppendContact")) { CreateAccessTeamTemplate("TestAppendContact", 2, AccessRights.AppendAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestAssignContact")) { CreateAccessTeamTemplate("TestAssignContact", 2, AccessRights.AssignAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestShareContact")) { CreateAccessTeamTemplate("TestShareContact", 2, AccessRights.ShareAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestAppendToAccount")) { CreateAccessTeamTemplate("TestAppendToAccount", 1, AccessRights.AppendToAccess); } if (!existing.Entities.Any(x => x.GetAttributeValue <string>("teamtemplatename") == "TestMultipleContact")) { CreateAccessTeamTemplate("TestMultipleContact", 2, AccessRights.WriteAccess, AccessRights.ReadAccess, AccessRights.DeleteAccess); } Console.WriteLine(sw.ElapsedMilliseconds.ToString()); sw.Stop(); }
private void InitialiseAccessTeamConfiguration() { //create a new security role with basic level only on all contact privileges var accessTeamTestRole = crm.CloneSecurityRole("Salesperson"); accessTeamTestRole.Name = "AccessTeamTest"; var contactPriv = accessTeamTestRole.Privileges["contact"]; var newPriv = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in contactPriv) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv.Add(priv.Key, newP); } accessTeamTestRole.Privileges.Remove("contact"); accessTeamTestRole.Privileges.Add("contact", newPriv); var accountPriv = accessTeamTestRole.Privileges["account"]; newPriv = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in accountPriv) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv.Add(priv.Key, newP); } accessTeamTestRole.Privileges.Remove("account"); accessTeamTestRole.Privileges.Add("account", newPriv); crm.AddSecurityRole(accessTeamTestRole); //create a new security role without share priv on contact var accessTeamTestRole2 = crm.CloneSecurityRole("Salesperson"); accessTeamTestRole2.Name = "AccessTeamTestNoShare"; var contactPriv2 = accessTeamTestRole.Privileges["contact"]; var newPriv2 = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in contactPriv.Where(x => x.Value.AccessRight != AccessRights.ShareAccess)) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv2.Add(priv.Key, newP); } accessTeamTestRole2.Privileges.Remove("contact"); accessTeamTestRole2.Privileges.Add("contact", newPriv2); crm.AddSecurityRole(accessTeamTestRole2); //create a new security role without write priv on contact var accessTeamTestRole3 = crm.CloneSecurityRole("Salesperson"); accessTeamTestRole3.Name = "AccessTeamTestNoWrite"; var contactPriv3 = accessTeamTestRole.Privileges["contact"]; var newPriv3 = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>(); foreach (var priv in contactPriv.Where(x => x.Value.AccessRight != AccessRights.WriteAccess)) { var newP = priv.Value.Clone(); newP.PrivilegeDepth = PrivilegeDepth.Basic; newPriv3.Add(priv.Key, newP); } accessTeamTestRole3.Privileges.Remove("contact"); accessTeamTestRole3.Privileges.Add("contact", newPriv3); crm.AddSecurityRole(accessTeamTestRole3); //create some users with the new role var user = new Entity("systemuser"); user["internalemailaddress"] = "*****@*****.**"; user["businessunitid"] = crm.RootBusinessUnit; user["islicensed"] = true; testUser1 = crm.CreateUser(orgAdminService, user, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser1Service = crm.CreateOrganizationService(testUser1.Id); var user2 = new Entity("systemuser"); user2["internalemailaddress"] = "*****@*****.**"; user2["businessunitid"] = crm.RootBusinessUnit; user2["islicensed"] = true; testUser2 = crm.CreateUser(orgAdminService, user2, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser2Service = crm.CreateOrganizationService(testUser2.Id); var user3 = new Entity("systemuser"); user3["internalemailaddress"] = "*****@*****.**"; user3["businessunitid"] = crm.RootBusinessUnit; user3["islicensed"] = true; testUser3 = crm.CreateUser(orgAdminService, user3, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId }); testUser3Service = crm.CreateOrganizationService(testUser3.Id); var user4 = new Entity("systemuser"); user4["internalemailaddress"] = "*****@*****.**"; user4["businessunitid"] = crm.RootBusinessUnit; user4["islicensed"] = true; testUser4 = crm.CreateUser(orgAdminService, user4, new Guid[] { crm.GetSecurityRole("AccessTeamTestNoShare").RoleId }); testUser4Service = crm.CreateOrganizationService(testUser4.Id); var user5 = new Entity("systemuser"); user5["internalemailaddress"] = "*****@*****.**"; user5["businessunitid"] = crm.RootBusinessUnit; user5["islicensed"] = true; testUser5 = crm.CreateUser(orgAdminService, user5, new Guid[] { crm.GetSecurityRole("AccessTeamTestNoWrite").RoleId }); //create some access team templates CreateAccessTeamTemplate("TestWriteContact", 2, AccessRights.WriteAccess); CreateAccessTeamTemplate("TestReadContact", 2, AccessRights.ReadAccess); CreateAccessTeamTemplate("TestDeleteContact", 2, AccessRights.DeleteAccess); CreateAccessTeamTemplate("TestAppendContact", 2, AccessRights.AppendAccess); CreateAccessTeamTemplate("TestAssignContact", 2, AccessRights.AssignAccess); CreateAccessTeamTemplate("TestShareContact", 2, AccessRights.ShareAccess); CreateAccessTeamTemplate("TestAppendToAccount", 1, AccessRights.AppendToAccess); CreateAccessTeamTemplate("TestMultipleContact", 2, AccessRights.WriteAccess, AccessRights.ReadAccess, AccessRights.DeleteAccess); }