Skip to content
Snippets Groups Projects

feat: Add additional ways to fetch profile data for current request user

@@ -11,6 +11,8 @@
**********************************************************************/
package org.eclipsefoundation.efservices.models;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
@@ -98,16 +100,50 @@ public class RequestUserWrapper {
}
/**
* Retrieves the token user's profile data by performing a user search by uid.
* Fetches public profile data for the user bound to the request chain. Throws a
* FinalForbiddenException if there is no current user, or if the profile
* fetches fail to retrieve data.
*
* @return The EfUser profile data for the user associated with the current
* token.
*/
public EfUser getUserPublicProfileData() {
if (currentUser == null) {
throw new FinalForbiddenException(NO_USER_ERR_MSG);
}
// Fetch by username. Then fetch by gh handle if not found
Optional<EfUser> result = accountService.fetchUserByUsername(getCurrentUserEfName(), false)
.or(() -> accountService.fetchUserByGhHandle(getCurrentUserGithubHandle(), false));
if (result.isEmpty()) {
throw new FinalForbiddenException(NO_USER_ERR_MSG);
}
return result.get();
}
/**
* Retrieves the token user's private profile data by performing a user search
* by uid and name. It will then fetch via GH id if it can't find the user.
* Throws a FinalForbiddenException if there is no current user, or if the
* profile fetches fail to retrieve data.
*
* @return The EfUser profile data for the user associated with the current
* token.
*/
public EfUser getCurrentUserProfileData() {
public EfUser getUserPrivateProfileData() {
if (currentUser == null) {
throw new FinalForbiddenException(NO_USER_ERR_MSG);
}
return accountService.performUserSearch(UserSearchParams.builder().setUid(getCurrentUserUid()).build())
.orElseThrow(() -> new FinalForbiddenException(NO_USER_ERR_MSG));
// Perform user search, then fetch by Gh handle if not found.
Optional<EfUser> result = accountService
.performUserSearch(
UserSearchParams.builder().setUid(getCurrentUserUid()).setName(getCurrentUserEfName()).build())
.or(() -> accountService.fetchUserByGhHandle(getCurrentUserGithubHandle(), true));
if (result.isEmpty()) {
throw new FinalForbiddenException(NO_USER_ERR_MSG);
}
return result.get();
}
}
\ No newline at end of file
Loading