Summary
This article outlines how to create an action that will propagate roles and permissions from the top owner to all branded owners when creating or updating.
It requires that the contact type and status types already exist across all branded owners otherwise it will fail and add an event log entry
It will add or update existing roles when the top owner role is created or saved
It will NOT propagate role profile questions or saved list views
This assumes that the event manager is running which is the service that processes these events when creating /updating occurs
Note: as of EngageIP 8.6.0 options exist to propagate and update branded owner data to other branded owners. See the Configuring Branded and Unbranded Owners article for details
Configuration
Click on Setup
Click Actions
Click Add to add a new action
In the Name section enter 'Propagate Roles and Permissions to all branded owners'
In Event Code enter: 'Role.Update,Role.Create'
In the Script text box enter the code shown below
Note: Note: make sure to replace "Logisense Corporation" with YOURÂ owner name otherwise the action will not workRole role = Role.GetByID(Convert.ToInt32(context["RoleID"]));Owner owner = Owner.GetByID(role.OwnerID); if (owner.Name == "<span style='color: #ff0000;'>Logisense Corporation</span>") { User userowner = User.GetByID(owner.GetUserOwner().UserID); RolePermissions[] rps = role.GetRolePermissionsCollection(); OwnerParentQuery opq = new OwnerParentQuery(); opq.ActAs_OwnerIDMin = Int32.MinValue;ContactTypeQuery ctq = new ContactTypeQuery(); ctq.IDMin = role.ContactTypeID; ctq.IDMax = role.ContactTypeID;UserStatusTypeQuery ustq = new UserStatusTypeQuery(); ustq.IDMin = role.UserStatusTypeID; ustq.IDMax = role.UserStatusTypeID;UserStatusType ust = UserStatusType.GetCollection(ref ustq)[0]; foreach (OwnerParent op in OwnerParent.GetCollection(ref opq)) { //Logisense.Boss.Logic.Core.Alert.Create(op.OwnerID.ToString(), 1); RoleQuery rq = new RoleQuery(); rq.Name = role.Name; rq.OwnerIDMin = op.OwnerID; rq.OwnerIDMax = op.OwnerID; if (Role.GetCollection(ref rq).Length > 0) { //update Role ownerrole = Role.GetCollection(ref rq)[0]; if (ContactType.GetCollection(ref ctq).Length > 0) { ContactType ct = ContactType.GetCollection(ref ctq)[0]; ContactTypeQuery ownerctq = new ContactTypeQuery(); ownerctq.Name = ct.Name; ownerctq.OwnerIDMin = op.OwnerID; ownerctq.OwnerIDMax = op.OwnerID; if (ContactType.GetCollection(ref ownerctq).Length < 1) { EventLogger.Log(userowner.ID, userowner.ID, "Role Propagation", "Role Propagation", "Role Progation Failed - Contact Type Missing for Owner " + Owner.GetByID(op.OwnerID).Name, owner.ID, "", Int32.MinValue, null); return false; } else { ownerrole.ContactTypeID = ContactType.GetCollection(ref ownerctq)[0].ID; } } else { ownerrole.ContactTypeID = Int32.MinValue; } ownerrole.Assignable = role.Assignable; ownerrole.Name = role.Name; ownerrole.PasswordChangeDays = role.PasswordChangeDays; ownerrole.PasswordHistoryLength = role.PasswordHistoryLength; ownerrole.PasswordMinimumLength = role.PasswordMinimumLength; ownerrole.PasswordMustContainNumbers = role.PasswordMustContainNumbers; ownerrole.LockoutDuration = role.LockoutDuration; ownerrole.FailedLoginLimit = role.FailedLoginLimit; UserStatusTypeQuery ownerustq = new UserStatusTypeQuery(); ownerustq.OwnerIDMin = op.OwnerID; ownerustq.OwnerIDMax = op.OwnerID; ownerustq.Nam e = ust.Name; if (UserStatusType.GetCollection(ref ownerustq).Length < 1) { EventLogger.Log(userowner.ID, userowner.ID, "Role Propagation", "Role Propagation", "Role Progation Failed - User Status Type Missing for Owner " + Owner.GetByID(op.OwnerID).Name, owner.ID, "", Int32.MinValue, null); return false; } else { ownerrole.UserStatusTypeID = UserStatusType.GetCollection(ref ownerustq)[0].ID; } using (Logisense.Boss.Logic.EventLogger.StartEventLoggerFiltering()) { ownerrole.Update(); } RolePermissions[] ownerrps = ownerrole.GetRolePermissionsCollection(); foreach (RolePermissions ownerrp in ownerrps) { ownerrp.Delete(); } foreach (RolePermissions rp in rps) { RolePermissions newrp = RolePermissions.GetNew(); newrp.Name = rp.Name; newrp.RoleID = ownerrole.ID; newrp.Create(); } } else { //create Role newrole = Role.GetNew(); if (ContactType.GetCollection(ref ctq).Length > 0) { ContactType ct = ContactType.GetCollection(ref ctq)[0]; ContactTypeQuery ownerctq = new ContactTypeQuery(); ownerctq.Name = ct.Name; ownerctq.OwnerIDMin = op.OwnerID; ownerctq.OwnerIDMax = op.OwnerID; if (ContactType.GetCollection(ref ownerctq).Length < 1) { EventLogger.Log(userowner.ID, userowner.ID, "Role Propagation", "Role Propagation", "Role Progation Failed - Contact Type Missing for Owner " + Owner.GetByID(op.OwnerID).Name, owner.ID, "", Int32.MinValue, null); return false; } else { newrole.ContactTypeID = ContactType.GetCollection(ref ownerctq)[0].ID; } } else { newrole.ContactTypeID = Int32.MinValue; } newrole.Name = role.Name; newrole.Assignable = role.Assignable; newrole.PasswordChangeDays = role.PasswordChangeDays; newrole.PasswordHistoryLength = role.PasswordHistoryLength; newrole.PasswordMinimumLength = role.PasswordMinimumLength; newrole.PasswordMustContainNumbers = role.PasswordMustContainNumbers; newrole.LockoutDuration = role.LockoutDuration; newrole.FailedLoginLimit = role.FailedLoginLimit; newrole.OwnerID = op.OwnerID; UserStatusTypeQuery ownerustq = new UserStatusTypeQuery(); ownerustq.OwnerIDMin = op.OwnerID; ownerustq.OwnerIDMax = op.OwnerID; ownerustq.Name = ust.Name; if (UserStatusType.GetCollection(ref ownerustq).Length < 1) { EventLogger.Log(userowner.ID, userowner.ID, "Role Propagation", "Role Propagation", "Role Progation Failed - User Status Type Missing for Owner " + Owner.GetByID(op.OwnerID).Name, owner.ID, "", Int32.MinValue, null); return false; } else { newrole.UserStatusTypeID = UserStatusType.GetCollection(ref ownerustq)[0].ID; } using (Logisense.Boss.Logic.EventLogger.StartEventLoggerFiltering()) { newrole.Create(); } foreach (RolePermissions rp in rps) { RolePermissions newrp = RolePermissions.GetNew(); newrp.Name = rp.Name; newrp.RoleID = newrole.ID; newrp.Create(); } } } }