public async Task <IHttpActionResult> PutUserVisibility([FromBody] PutUserVisibilityRequest request) { string className = "UsersController"; string methodName = "PutUserVisibility"; string logEntry = $"NewVisibility = {request?.Visibility}"; this.LogControllerStart(this.log, className, methodName, logEntry); // If user handle is null, return 404 if (this.UserHandle == null) { return(this.NotFound(ResponseStrings.UserNotFound)); } var userProfileEntity = await this.usersManager.ReadUserProfile(this.UserHandle, this.AppHandle); if (userProfileEntity == null) { return(this.NotFound(ResponseStrings.UserNotFound)); } await this.usersManager.UpdateUserVisibility( this.UserHandle, this.AppHandle, request.Visibility, DateTime.UtcNow, userProfileEntity); logEntry = $"OldVisibility = {userProfileEntity?.Visibility}, NewVisibility = {request?.Visibility}"; this.LogControllerEnd(this.log, className, methodName, logEntry); return(this.NoContent()); }
public async Task UpdateUserVisibilityTest() { SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user = await TestUtilities.PostGenericUser(client); var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken); // Call Put User PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth); // Call Get User UserProfileView getUserProfile = await client.Users.GetUserAsync(user.UserHandle, auth); // Clean up first before verifying await client.Users.DeleteUserAsync(auth); // Verify changes ... also verify rest to make sure nothing else wiped out Assert.AreEqual(FollowerStatus.None, getUserProfile.FollowerStatus); Assert.AreEqual(FollowingStatus.None, getUserProfile.FollowingStatus); Assert.AreEqual(null, getUserProfile.PhotoHandle); Assert.AreEqual(null, getUserProfile.PhotoUrl); Assert.AreEqual(ProfileStatus.Active, getUserProfile.ProfileStatus); Assert.AreEqual(0, getUserProfile.TotalFollowers); Assert.AreEqual(0, getUserProfile.TotalFollowing); Assert.AreEqual(0, getUserProfile.TotalTopics); Assert.AreEqual(user.UserHandle, getUserProfile.UserHandle); Assert.AreEqual(Visibility.Private, getUserProfile.Visibility); }
public async Task SocialFollowPrivateUserRejectTest() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile1 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile2 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // make user2 a private user PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth2); // user1 requests to follow user2 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth1); CountResponse getPendingUserCount1 = null; FeedResponseUserCompactView getPendingUsers1 = null; // user2 gets the count of his pending users // user2 gets his feed of pending users getPendingUserCount1 = await client.MyPendingUsers.GetPendingUsersCountAsync(auth2); getPendingUsers1 = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile3 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile4 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // user2 rejects user1's follow request await client.MyPendingUsers.DeletePendingUserAsync(postUserResponse1.UserHandle, auth2); // user2 gets the count of his pending users // user2 gets his feed of pending users CountResponse getPendingUserCount2 = await client.MyPendingUsers.GetPendingUsersCountAsync(auth2); var getPendingUsers2 = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile5 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile6 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // clean up: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that user2's list of pending users includes user1 // check that user2's list of pending users is empty after the reject // check the user profiles to see that follower status and following status are updated correctly Assert.AreEqual(1, getPendingUserCount1.Count); Assert.AreEqual(0, getPendingUserCount2.Count); Assert.AreEqual(postUserResponse1.UserHandle, getPendingUsers1.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, getPendingUsers1.Data[0].FollowerStatus); Assert.AreEqual(Visibility.Public, getPendingUsers1.Data[0].Visibility); // Validate User Profiles Assert.AreEqual(FollowerStatus.None, userProfile1.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile1.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile1.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile2.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile2.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile2.Visibility); Assert.AreEqual(FollowerStatus.Pending, userProfile3.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile3.FollowingStatus); Assert.AreEqual(Visibility.Private, userProfile3.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile4.FollowerStatus); Assert.AreEqual(FollowingStatus.Pending, userProfile4.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile4.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile5.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile5.FollowingStatus); Assert.AreEqual(Visibility.Private, userProfile5.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile6.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile6.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile6.Visibility); }
public async Task SocialFollowPrivateUserTest() { // create the client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // make user2 a private user PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth2); // user2 gets the feed of his followers var followersUsers1 = await client.MyFollowers.GetFollowersAsync(auth2, null, 10); // user1 requests to follow user2 PostFollowingUserRequest postFollowingRequest1 = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest1, auth1); // user2 gets his feed of pending users var pendingUsers = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user2 accepts user1's follow request PostFollowerRequest postFollowerRequest2 = new PostFollowerRequest(postUserResponse1.UserHandle); await client.MyFollowers.PostFollowerAsync(postFollowerRequest2, auth2); // user2 gets the feed of his followers with GET /users/{userhandle}/followers var followersUsers2 = await client.UserFollowers.GetFollowersAsync(postUserResponse2.UserHandle, auth2, null, 10); // user2 gets the feed of his followers with GET /users/me/followers - result is same, just using a different API var followersUsers3 = await client.MyFollowers.GetFollowersAsync(auth2, null, 10); // user1 gets the feed of his following users var followingUsers = await client.MyFollowing.GetFollowingUsersAsync(auth1, null, 10); // clean up: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that user2's list of pending users includes user1 // check that user2's followers feed includes user1 // check that user1's list of following users includes user2 Assert.AreEqual(0, followersUsers1.Data.Count); Assert.AreEqual(1, followersUsers2.Data.Count); Assert.AreEqual(1, followersUsers3.Data.Count); Assert.AreEqual(1, pendingUsers.Data.Count); Assert.AreEqual(1, followingUsers.Data.Count); Assert.AreEqual(postUserResponse1.UserHandle, followersUsers2.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers2.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse1.UserHandle, followersUsers3.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers3.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse1.UserHandle, pendingUsers.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, pendingUsers.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse2.UserHandle, followingUsers.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.Follow, followingUsers.Data[0].FollowerStatus); }
/// <summary> /// Update user visibility /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Put user visibility request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PutUserVisibilityAsync(this IUsers operations, PutUserVisibilityRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PutUserVisibilityWithHttpMessagesAsync(request, authorization, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Update user visibility /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Put user visibility request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> public static object PutUserVisibility(this IUsers operations, PutUserVisibilityRequest request, string authorization) { return(Task.Factory.StartNew(s => ((IUsers)s).PutUserVisibilityAsync(request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }