private static ProfileSubtypeProperty EnsureProfileSubtypeProperty( ProfileTypeProperty profileTypeProperty, UserProfilePropertyInfo userProfilePropertyInfo, ProfileSubtypePropertyManager profileSubtypePropertyManager) { var profileSubtypeProperty = profileSubtypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileSubtypeProperty == null) { profileSubtypeProperty = profileSubtypePropertyManager.Create(profileTypeProperty); profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } profileSubtypePropertyManager.Add(profileSubtypeProperty); } else { profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } } profileSubtypeProperty.Commit(); return(profileSubtypeProperty); }
public void EnsureProfileProperty_WhenCreatingProperty_GivenNewUserProfilePropertyInfo_ThenCreatesProperty() { using (var testScope = SiteTestScope.BlankSite()) { // Arrange var site = testScope.SiteCollection; var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue); using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { try { // Act var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); // Assert Assert.IsNotNull(userProfileProperty); } finally { this.TestCleanup(); } } } }
/// <summary> /// Cleans up the test data. /// </summary> public void TestCleanup() { using (var testScope = SiteTestScope.BlankSite()) { var site = testScope.SiteCollection; var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue); using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { // Try removing the test profile property try { var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); userProfileHelper.RemoveProfileProperty(site, userProfilePropertyInfo); } catch (Exception) { // Do nothing } } } }
private static ProfileTypeProperty EnsureProfileTypeProperty( CoreProperty property, UserProfilePropertyInfo userProfilePropertyInfo, ProfileTypePropertyManager profileTypePropertyManager) { var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileTypeProperty == null) { profileTypeProperty = profileTypePropertyManager.Create(property); profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer; profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor; profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable; profileTypePropertyManager.Add(profileTypeProperty); } else { profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer; profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor; profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable; } profileTypeProperty.Commit(); return(profileTypeProperty); }
private CoreProperty EnsureCoreProperty( SPSite site, UserProfilePropertyInfo userProfilePropertyInfo, CorePropertyManager userProfileCoreProperties) { // If property is null, create it. Else, update it var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property == null) { this.logger.Info("Creating user profile property '{0}'", userProfilePropertyInfo.Name); // Create property (false here means it's not a section) property = userProfileCoreProperties.Create(false); property.Name = userProfilePropertyInfo.Name; property.Type = userProfilePropertyInfo.PropertyDataType; property.Length = userProfilePropertyInfo.Length; property.IsMultivalued = userProfilePropertyInfo.IsMultivalued; } else { this.logger.Info("Updating user profile property '{0}'", userProfilePropertyInfo.Name); } property.DisplayName = userProfilePropertyInfo.DisplayName; property.Description = userProfilePropertyInfo.Description; property.IsAlias = userProfilePropertyInfo.IsAlias; property.IsSearchable = userProfilePropertyInfo.IsSearchable; // Setup localized display name if (userProfilePropertyInfo.DisplayNameLocalized.Count > 0) { foreach (var displayName in userProfilePropertyInfo.DisplayNameLocalized) { property.DisplayNameLocalized[displayName.Key] = displayName.Value; } } // Setup localized description if (userProfilePropertyInfo.DescriptionLocalized.Count > 0) { foreach (var description in userProfilePropertyInfo.DescriptionLocalized) { property.DescriptionLocalized[description.Key] = description.Value; } } // Setup taxonomy mappings if configured if (userProfilePropertyInfo.TermSetInfo != null) { var taxonomyCache = this.siteTaxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper); var termStore = userProfilePropertyInfo.TermSetInfo.ResolveParentTermStore(taxonomyCache.TaxonomySession); property.TermSet = termStore.GetTermSet(userProfilePropertyInfo.TermSetInfo.Id); } property.Commit(); return(property); }
/// <summary> /// Removes the profile property. /// </summary> /// <param name="site">The site.</param> /// <param name="userProfilePropertyInfo">The user profile property information.</param> /// <returns>A boolean value if the property was removed or not.</returns> public bool RemoveProfileProperty(SPSite site, UserProfilePropertyInfo userProfilePropertyInfo) { var userProfileCoreProperties = this.GetCorePropertyManager(site); var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property != null) { userProfileCoreProperties.RemovePropertyByName(userProfilePropertyInfo.Name); return(true); } return(false); }
/// <summary> /// Ensures the profile property. /// </summary> /// <param name="site">The site.</param> /// <param name="userProfilePropertyInfo">The user profile property information.</param> /// <returns>The user profile core property.</returns> public CoreProperty EnsureProfileProperty(SPSite site, UserProfilePropertyInfo userProfilePropertyInfo) { // Ensure core property var property = this.EnsureCoreProperty( site, userProfilePropertyInfo, this.GetCorePropertyManager(site)); // Ensure profile type property var profileTypeProperty = EnsureProfileTypeProperty( property, userProfilePropertyInfo, this.GetProfileTypePropertyManager(site)); // Ensure profile subtype property EnsureProfileSubtypeProperty( profileTypeProperty, userProfilePropertyInfo, this.GetProfileSubtypePropertyManager(site)); return(property); }
/// <summary> /// Ensures the profile property. /// </summary> /// <param name="site">The site.</param> /// <param name="userProfilePropertyInfo">The user profile property information.</param> /// <returns>The user profile core property.</returns> public CoreProperty EnsureProfileProperty(SPSite site, UserProfilePropertyInfo userProfilePropertyInfo) { // Ensure core property var property = this.EnsureCoreProperty( site, userProfilePropertyInfo, this.GetCorePropertyManager(site)); // Ensure profile type property var profileTypeProperty = EnsureProfileTypeProperty( property, userProfilePropertyInfo, this.GetProfileTypePropertyManager(site)); // Ensure profile subtype property EnsureProfileSubtypeProperty( profileTypeProperty, userProfilePropertyInfo, this.GetProfileSubtypePropertyManager(site)); return property; }
private static ProfileSubtypeProperty EnsureProfileSubtypeProperty( ProfileTypeProperty profileTypeProperty, UserProfilePropertyInfo userProfilePropertyInfo, ProfileSubtypePropertyManager profileSubtypePropertyManager) { var profileSubtypeProperty = profileSubtypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileSubtypeProperty == null) { profileSubtypeProperty = profileSubtypePropertyManager.Create(profileTypeProperty); profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } profileSubtypePropertyManager.Add(profileSubtypeProperty); } else { profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } } profileSubtypeProperty.Commit(); return profileSubtypeProperty; }
private static ProfileTypeProperty EnsureProfileTypeProperty( CoreProperty property, UserProfilePropertyInfo userProfilePropertyInfo, ProfileTypePropertyManager profileTypePropertyManager) { var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileTypeProperty == null) { profileTypeProperty = profileTypePropertyManager.Create(property); profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer; profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor; profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable; profileTypePropertyManager.Add(profileTypeProperty); } else { profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer; profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor; profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable; } profileTypeProperty.Commit(); return profileTypeProperty; }
private CoreProperty EnsureCoreProperty( SPSite site, UserProfilePropertyInfo userProfilePropertyInfo, CorePropertyManager userProfileCoreProperties) { // If property is null, create it. Else, update it var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property == null) { this.logger.Info("Creating user profile property '{0}'", userProfilePropertyInfo.Name); // Create property (false here means it's not a section) property = userProfileCoreProperties.Create(false); property.Name = userProfilePropertyInfo.Name; property.Type = userProfilePropertyInfo.PropertyDataType; property.Length = userProfilePropertyInfo.Length; property.IsMultivalued = userProfilePropertyInfo.IsMultivalued; } else { this.logger.Info("Updating user profile property '{0}'", userProfilePropertyInfo.Name); } property.DisplayName = userProfilePropertyInfo.DisplayName; property.Description = userProfilePropertyInfo.Description; property.IsAlias = userProfilePropertyInfo.IsAlias; property.IsSearchable = userProfilePropertyInfo.IsSearchable; // Setup localized display name if (userProfilePropertyInfo.DisplayNameLocalized.Count > 0) { foreach (var displayName in userProfilePropertyInfo.DisplayNameLocalized) { property.DisplayNameLocalized[displayName.Key] = displayName.Value; } } // Setup localized description if (userProfilePropertyInfo.DescriptionLocalized.Count > 0) { foreach (var description in userProfilePropertyInfo.DescriptionLocalized) { property.DescriptionLocalized[description.Key] = description.Value; } } // Setup taxonomy mappings if configured if (userProfilePropertyInfo.TermSetInfo != null) { var taxonomyCache = this.siteTaxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper); var termStore = userProfilePropertyInfo.TermSetInfo.ResolveParentTermStore(taxonomyCache.TaxonomySession); property.TermSet = termStore.GetTermSet(userProfilePropertyInfo.TermSetInfo.Id); } property.Commit(); return property; }
/// <summary> /// Removes the profile property. /// </summary> /// <param name="site">The site.</param> /// <param name="userProfilePropertyInfo">The user profile property information.</param> /// <returns>A boolean value if the property was removed or not.</returns> public bool RemoveProfileProperty(SPSite site, UserProfilePropertyInfo userProfilePropertyInfo) { var userProfileCoreProperties = this.GetCorePropertyManager(site); var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property != null) { userProfileCoreProperties.RemovePropertyByName(userProfilePropertyInfo.Name); return true; } return false; }
public void EnsureProfileProperty_WhenLocalizing_GivenUserProfilePropertyInfo_ThenAddsLocalizedValues() { using (var testScope = SiteTestScope.BlankSite()) { // Arrange var site = testScope.SiteCollection; var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue) { Description = "Test property description" }; userProfilePropertyInfo.DisplayNameLocalized.Add(1036, "Propriété de test"); userProfilePropertyInfo.DescriptionLocalized.Add(1036, "Description propriété de test"); using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { try { // Act var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); // Assert // 2 values: Default (english and french/1036) Assert.IsTrue(userProfileProperty.DisplayNameLocalized.Count == 2); Assert.IsTrue(userProfileProperty.DescriptionLocalized.Count == 2); } finally { this.TestCleanup(); } } } }
public void EnsureProfileProperty_WhenMappedToTermSet_GivenUserProfilePropertyInfo_ThenMapsPropertyToTermSet() { using (var testScope = SiteTestScope.BlankSite()) { // Arrange var site = testScope.SiteCollection; var termSetInfo = new TermSetInfo(Guid.NewGuid(), TermSetName); var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue) { TermSetInfo = termSetInfo }; // Create term set var session = new TaxonomySession(site); var defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore; var defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(site); defaultSiteCollectionGroup.CreateTermSet(termSetInfo.Label, termSetInfo.Id); defaultSiteCollectionTermStore.CommitAll(); using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { try { // Act var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); // Assert Assert.AreEqual(userProfileProperty.TermSet.Id, termSetInfo.Id); } finally { this.TestCleanup(); } } } }
public void EnsureProfileProperty_WhenUpdatingSecurity_GivenUpdatedUserProfilePropertyInfo_ThenUpdatesProperty() { using (var testScope = SiteTestScope.BlankSite()) { // Arrange var site = testScope.SiteCollection; var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue) { IsUserEditable = true }; using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { try { // Act var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); // Make sure the default privacy value is set to private var profileSubtypeManager = userProfileHelper.GetProfileSubtypePropertyManager(site); var profileSubtypeProperty = profileSubtypeManager.GetPropertyByName(userProfilePropertyInfo.Name); Assert.AreEqual(Privacy.Private, profileSubtypeProperty.DefaultPrivacy); userProfilePropertyInfo.IsUserEditable = false; userProfilePropertyInfo.DefaultPrivacy = Privacy.Public; userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); profileSubtypeManager = userProfileHelper.GetProfileSubtypePropertyManager(site); profileSubtypeProperty = profileSubtypeManager.GetPropertyByName(userProfilePropertyInfo.Name); // Assert Assert.AreEqual(profileSubtypeProperty.IsUserEditable, userProfilePropertyInfo.IsUserEditable); Assert.AreEqual(profileSubtypeProperty.DefaultPrivacy, userProfilePropertyInfo.DefaultPrivacy); } finally { this.TestCleanup(); } } } }
public void EnsureProfileProperty_WhenUpdatingVisibility_GivenUpdatedUserProfilePropertyInfo_ThenUpdatesProperty() { using (var testScope = SiteTestScope.BlankSite()) { // Arrange var site = testScope.SiteCollection; var userProfilePropertyInfo = new UserProfilePropertyInfo( ProfilePropertyName, "Test Profile Property", PropertyDataType.StringSingleValue); using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site)) { try { // Act var userProfileHelper = injectionScope.Resolve<IUserProfilePropertyHelper>(); userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); userProfilePropertyInfo.IsVisibleOnEditor = true; userProfilePropertyInfo.IsVisibleOnViewer = true; userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo); // Assert var profileTypeManager = userProfileHelper.GetProfileTypePropertyManager(site); var profileTypeProperty = profileTypeManager.GetPropertyByName(userProfilePropertyInfo.Name); Assert.AreEqual(profileTypeProperty.IsVisibleOnEditor, userProfilePropertyInfo.IsVisibleOnEditor); Assert.AreEqual(profileTypeProperty.IsVisibleOnViewer, userProfilePropertyInfo.IsVisibleOnViewer); } finally { this.TestCleanup(); } } } }