Skip to content

Commit

Permalink
feat: Avoid using Profile Setting Administration for AboutMe and Expe…
Browse files Browse the repository at this point in the history
…riences Profile fields - MEED-7810 - Meeds-io/meeds#2577 (#4194)

Prior to this change, the User Profile fields `AboutMe` and
`experiences` was controlled by `ProfileSettingService` API which was
considered due to Meeds-io/si#3 issue. This change will avoid using such
control explicitly on 'AboutMe' and 'Experiences' field since it's
displayed in dedicated sections in the profile page of the user, and
thus will be displayed all time for all users when not empty.

At the same time, the field `gender` isn't retrieved automatically in
Profile REST calls since it's deprecated functionally.
  • Loading branch information
boubaker authored and exo-swf committed Nov 15, 2024
1 parent db5f9c7 commit cd6e05f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static ProfileEntity buildEntityProfile(Profile profile, String expand) {
return buildEntityProfile(profile, null, expand);
}

public static ProfileEntity buildEntityProfile(Profile profile, String restPath, String expand) {
public static ProfileEntity buildEntityProfile(Profile profile, String restPath, String expand) { // NOSONAR
ProfileEntity userEntity = new ProfileEntity(profile.getId());
userEntity.setHref(RestUtils.getRestUrl(USERS_TYPE, profile.getIdentity().getRemoteId(), restPath));
userEntity.setIdentity(RestUtils.getRestUrl(IDENTITIES_TYPE, profile.getIdentity().getId(), restPath));
Expand All @@ -318,19 +318,14 @@ public static ProfileEntity buildEntityProfile(Profile profile, String restPath,
if (canViewProperties || isProfilePropertyVisible(Profile.FULL_NAME)) {
userEntity.setFullname(profile.getFullName());
}
if (canViewProperties || isProfilePropertyVisible(Profile.GENDER)) {
userEntity.setGender(profile.getGender());
}
if (canViewProperties || isProfilePropertyVisible(Profile.POSITION)) {
userEntity.setPosition(profile.getPosition());
}
if (canViewProperties || isProfilePropertyVisible(Profile.EMAIL)) {
userEntity.setEmail(profile.getEmail());
}
if (canViewProperties || isProfilePropertyVisible(Profile.ABOUT_ME)) {
userEntity.setAboutMe((String) profile.getProperty(Profile.ABOUT_ME));
}

userEntity.setAboutMe((String) profile.getProperty(Profile.ABOUT_ME));
userEntity.setAvatar(profile.getAvatarUrl());
userEntity.setBanner(profile.getBannerUrl());
userEntity.setDefaultAvatar(profile.isDefaultAvatar());
Expand Down Expand Up @@ -367,9 +362,7 @@ public static ProfileEntity buildEntityProfile(Profile profile, String restPath,
if (canViewProperties || isProfilePropertyVisible(Profile.CONTACT_URLS)) {
buildUrlEntities(profile, userEntity);
}
if (canViewProperties || isProfilePropertyVisible(Profile.EXPERIENCES)) {
buildExperienceEntities(profile, userEntity);
}
buildExperienceEntities(profile, userEntity);
userEntity.setDeleted(profile.getIdentity().isDeleted());
userEntity.setEnabled(profile.getIdentity().isEnable());
if (profile.getProperty(Profile.EXTERNAL) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class ProfileEntity extends BaseEntity {

public static final String EMAIL = "email";

public static final String GENDER = "gender";

public static final String FULLNAME = "fullname";

public static final String LASTNAME = "lastname";
Expand Down Expand Up @@ -311,15 +309,6 @@ public String getFullname() {
return getString(FULLNAME);
}

public ProfileEntity setGender(String gender) {
setProperty(GENDER, gender);
return this;
}

public String getGender() {
return getString(GENDER);
}

public ProfileEntity setEmail(String email) {
setProperty(EMAIL, email);
return this;
Expand Down Expand Up @@ -607,8 +596,6 @@ public static String getFieldName(String name) {
return Profile.FULL_NAME;
} else if (StringUtils.equals(EMAIL, name)) {
return Profile.EMAIL;
} else if (StringUtils.equals(GENDER, name)) {
return Profile.GENDER;
} else if (StringUtils.equals(POSITION, name)) {
return Profile.POSITION;
} else if (StringUtils.equals(AVATAR, name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -59,7 +58,6 @@
import org.exoplatform.social.rest.entity.CollectionEntity;
import org.exoplatform.social.rest.entity.DataEntity;
import org.exoplatform.social.rest.entity.IdentityEntity;
import org.exoplatform.social.rest.entity.ProfileEntity;
import org.exoplatform.social.service.rest.api.VersionResources;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -82,9 +80,7 @@ public IdentityRest(IdentityManager identityManager, ProfilePropertyService prof
this.identityManager = identityManager;
this.profilePropertyService = profilePropertyService;
}
/**
* {@inheritDoc}
*/

@GET
@RolesAllowed("users")
@Operation(
Expand All @@ -105,7 +101,6 @@ public Response getIdentities(@Context UriInfo uriInfo,
offset = offset > 0 ? offset : RestUtils.getOffset(uriInfo);
limit = limit > 0 ? limit : RestUtils.getLimit(uriInfo);

IdentityManager identityManager = CommonsUtils.getService(IdentityManager.class);
String providerId = (type != null && type.equals("space")) ? SpaceIdentityProvider.NAME : OrganizationIdentityProvider.NAME;
ListAccess<Identity> listAccess = identityManager.getIdentitiesByProfileFilter(providerId, new ProfileFilter(), true);
Identity[] identities = listAccess.load(offset, limit);
Expand All @@ -124,9 +119,6 @@ public Response getIdentities(@Context UriInfo uriInfo,
}
}

/**
* {@inheritDoc}
*/
@GET
@Path("{id}")
@RolesAllowed("users")
Expand All @@ -142,7 +134,7 @@ public Response getIdentities(@Context UriInfo uriInfo,
public Response getIdentityById(@Context UriInfo uriInfo,
@Context Request request,
@Parameter(description = "Identity id which is a UUID such as 40487b7e7f00010104499b339f056aa4", required = true) @PathParam("id") String id,
@Parameter(description = "Asking for a full representation of a specific subresource if any", required = false) @QueryParam("expand") String expand) throws Exception {
@Parameter(description = "Asking for a full representation of a specific subresource if any", required = false) @QueryParam("expand") String expand) {
Identity identity = identityManager.getIdentity(id);
if (identity == null) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
Expand Down Expand Up @@ -263,13 +255,6 @@ public Response getIdentityByProviderIdAndRemoteId(@Context UriInfo uriInfo,
return builder.build();
}

/**
*
* @param uriInfo
* @param id
* @return
* @throws IOException
*/
@GET
@Path("{id}/avatar")
@RolesAllowed("users")
Expand All @@ -286,7 +271,7 @@ public Response getIdentityAvatarById(@Context UriInfo uriInfo,
@Context Request request,
@Parameter(description = "Identity id which is a UUID", required = true)@PathParam("id") String id) throws IOException {

Identity identity = identityManager.getIdentity(id, true);
Identity identity = identityManager.getIdentity(id);
if (identity == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Expand Down Expand Up @@ -319,13 +304,6 @@ public Response getIdentityAvatarById(@Context UriInfo uriInfo,
return builder.cacheControl(cc).build();
}

/**
*
* @param uriInfo
* @param id
* @return
* @throws IOException
*/
@GET
@Path("{id}/banner")
@RolesAllowed("users")
Expand All @@ -342,7 +320,7 @@ public Response getIdentityBannerById(@Context UriInfo uriInfo,
@Context Request request,
@Parameter(description = "Identity id which is a UUID", required = true)@PathParam("id") String id) throws IOException {

Identity identity = identityManager.getIdentity(id, true);
Identity identity = identityManager.getIdentity(id);
if (identity == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Expand Down Expand Up @@ -374,31 +352,7 @@ public Response getIdentityBannerById(@Context UriInfo uriInfo,
builder.cacheControl(cc);
return builder.cacheControl(cc).build();
}

private Profile fillProfileFromEntity(ProfileEntity model, Identity identity) {
Profile profile = identity.getProfile();
setProperty(profile, Profile.FIRST_NAME, model.getFirstname());
setProperty(profile, Profile.LAST_NAME, model.getLastname());
setProperty(profile, Profile.EMAIL, model.getEmail());
setProperty(profile, Profile.POSITION, model.getPosition());
setProperty(profile, Profile.GENDER, model.getGender());
// setProperty(profile, Profile.CONTACT_PHONES, model.getPhones());
// setProperty(profile, Profile.CONTACT_IMS, model.getIMs());
// setProperty(profile, Profile.CONTACT_URLS, model.getUrls());
setProperty(profile, Profile.DELETED, model.getDeleted());
return profile;
}

private Profile setProperty(Profile profile, String key, Object value) {
if (value != null) {
profile.setProperty(key, value);
}
return profile;
}

/**
* {@inheritDoc}
*/
@GET
@Path("{id}/relationships")
@RolesAllowed("users")
Expand All @@ -419,21 +373,20 @@ public Response getRelationshipsOfIdentity(@Context UriInfo uriInfo,
@Schema(defaultValue = "0") @QueryParam("offset") int offset,
@Parameter(description = "Limit", required = false)
@Schema(defaultValue = "20") @QueryParam("limit") int limit,
@Parameter(description = "Asking for a full representation of a specific subresource if any", required = false) @QueryParam("expand") String expand) throws Exception {
@Parameter(description = "Asking for a full representation of a specific subresource if any", required = false) @QueryParam("expand") String expand) {

offset = offset > 0 ? offset : RestUtils.getOffset(uriInfo);
limit = limit > 0 ? limit : RestUtils.getLimit(uriInfo);

IdentityManager identityManager = CommonsUtils.getService(IdentityManager.class);
Identity identity = identityManager.getIdentity(id, true);
Identity identity = identityManager.getIdentity(id);
if (identity == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}

RelationshipManager relationshipManager = CommonsUtils.getService(RelationshipManager.class);

if (with != null && with.length() > 0) {
Identity withUser = identityManager.getIdentity(with, true);
Identity withUser = identityManager.getIdentity(with);
if (withUser == null) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
Expand Down Expand Up @@ -485,14 +438,14 @@ public Response getCommonConnectionsWithIdentity(@Context UriInfo uriInfo,

List<Identity> currentUserConnections = Arrays.asList(relationshipManager.getConnections(authenticatedUser).load(0, 0));

Identity withIdentity = CommonsUtils.getService(IdentityManager.class).getIdentity(id, true);
Identity withIdentity = CommonsUtils.getService(IdentityManager.class).getIdentity(id);
List<Identity> withConnections = Arrays.asList(relationshipManager.getConnections(withIdentity).load(0, 0));

List<Identity> commonConnections = currentUserConnections.stream()
.filter(withConnections::contains)
.collect(Collectors.toList());
.toList();

List<DataEntity> identityEntities = new ArrayList<DataEntity>();
List<DataEntity> identityEntities = new ArrayList<>();
for (Identity identity : commonConnections) {
identityEntities.add(EntityBuilder.buildEntityIdentity(identity, uriInfo.getPath(), expand).getDataEntity());
}
Expand Down

0 comments on commit cd6e05f

Please sign in to comment.