/// <summary> /// Binds the role dropdown list. /// </summary> /// <param name="rockDropdownList">The rock dropdown list.</param> private void BindRoleDropdownList(RockDropDownList rockDropdownList) { rockDropdownList.Items.Clear(); foreach (var role in RoleCache.AllRoles()) { string name = role.IsSecurityTypeGroup ? role.Name : "GROUP - " + role.Name; rockDropdownList.Items.Add(new ListItem(name, role.Id.ToString())); } }
/// <summary> /// Get the MobilePerson object for the specified Person. /// </summary> /// <param name="person">The person to be converted into a MobilePerson object.</param> /// <param name="site">The site to use for configuration data.</param> /// <returns>A MobilePerson object.</returns> public static MobilePerson GetMobilePerson(Person person, SiteCache site) { var baseUrl = GlobalAttributesCache.Value("PublicApplicationRoot"); var homePhoneTypeId = DefinedValueCache.Get(SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME.AsGuid()).Id; var mobilePhoneTypeId = DefinedValueCache.Get(SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE.AsGuid()).Id; var alternateIdTypeId = DefinedValueCache.Get(SystemGuid.DefinedValue.PERSON_SEARCH_KEYS_ALTERNATE_ID).Id; var additionalSettings = site.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>(); if (person.Attributes == null) { person.LoadAttributes(); } var personAttributes = person.Attributes .Select(a => a.Value) .Where(a => a.Categories.Any(c => additionalSettings.PersonAttributeCategories.Contains(c.Id))); var roleGuids = RoleCache.AllRoles() .Where(r => r.IsPersonInRole(person.Guid)) .Select(r => r.Guid) .ToList(); var alternateId = person.GetPersonSearchKeys() .Where(a => a.SearchTypeValueId == alternateIdTypeId) .FirstOrDefault()?.SearchValue; return(new MobilePerson { FirstName = person.FirstName, NickName = person.NickName, LastName = person.LastName, Gender = (Rock.Common.Mobile.Enums.Gender)person.Gender, BirthDate = person.BirthDate, Email = person.Email, HomePhone = person.PhoneNumbers.Where(p => p.NumberTypeValueId == homePhoneTypeId).Select(p => p.NumberFormatted).FirstOrDefault(), MobilePhone = person.PhoneNumbers.Where(p => p.NumberTypeValueId == mobilePhoneTypeId).Select(p => p.NumberFormatted).FirstOrDefault(), HomeAddress = GetMobileAddress(person.GetHomeLocation()), CampusGuid = person.GetCampus()?.Guid, PersonAliasId = person.PrimaryAliasId.Value, PhotoUrl = (person.PhotoId.HasValue ? $"{baseUrl}{person.PhotoUrl}" : null), SecurityGroupGuids = roleGuids, PersonalizationSegmentGuids = new List <Guid>(), PersonGuid = person.Guid, PersonId = person.Id, AlternateId = alternateId, AttributeValues = GetMobileAttributeValues(person, personAttributes) }); }
/// <summary> /// Binds the roles. /// </summary> private void BindRoles() { ddlRoles.Items.Clear(); ddlRoles.Items.Add(new ListItem("[All Users]", "-1")); ddlRoles.Items.Add(new ListItem("[All Authenticated Users]", "-2")); ddlRoles.Items.Add(new ListItem("[All Un-Authenticated Users]", "-3")); var securityRoleType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid()); foreach (var role in RoleCache.AllRoles()) { string name = role.IsSecurityTypeGroup ? role.Name : "GROUP - " + role.Name; ddlRoles.Items.Add(new ListItem(name, role.Id.ToString())); } }
/// <summary> /// Returns a list of all the possible Roles /// </summary> /// <returns></returns> public static List <Role> AllRoles() { var roles = new List <Role>(); var cacheRoles = RoleCache.AllRoles(); if (cacheRoles == null) { return(roles); } foreach (var cacheRole in cacheRoles) { roles.Add(new Role(cacheRole)); } return(roles); }
/// <summary> /// Gets the default security settings. /// </summary> /// <returns></returns> private SecuritySettings GetDefaultSecuritySettings() { Group adminGroup = null; Group dataIntegrityGroup = null; using (var rockContext = new RockContext()) { var groupService = new GroupService(rockContext); adminGroup = groupService.GetByGuid(SystemGuid.Group.GROUP_ADMINISTRATORS.AsGuid()); dataIntegrityGroup = groupService.GetByGuid(SystemGuid.Group.GROUP_DATA_INTEGRITY_WORKER.AsGuid()); } var allRoles = RoleCache.AllRoles(); var adminRole = allRoles .Where(r => r.Guid == SystemGuid.Group.GROUP_ADMINISTRATORS.AsGuid()) .FirstOrDefault(); var dataIntegrityRole = allRoles .Where(r => r.Guid == SystemGuid.Group.GROUP_DATA_INTEGRITY_WORKER.AsGuid()) .FirstOrDefault(); return(new SecuritySettings { AccountProtectionProfilesForDuplicateDetectionToIgnore = new List <AccountProtectionProfile> { AccountProtectionProfile.Extreme, AccountProtectionProfile.High, AccountProtectionProfile.Medium }, AccountProtectionProfileSecurityGroup = new Dictionary <AccountProtectionProfile, RoleCache> { { AccountProtectionProfile.Extreme, adminRole }, { AccountProtectionProfile.High, dataIntegrityRole } }, DisableTokensForAccountProtectionProfiles = new List <AccountProtectionProfile> { AccountProtectionProfile.Extreme }, }); }