Skip to content

Commit

Permalink
fix: Unexpected attributes displayed - EXO-71322 - Meeds-io/meeds#1915 (
Browse files Browse the repository at this point in the history
#3717)

Prior to this change, all attributes are displayed on the edit mode of
profile of all users, this may display some technical/private data to
all users, so only editable or visible attributes should be visible in
the edit drawer of profiles. This fix filter the list of attributes to
be retrieved to simple users.

(cherry picked from commit c29f065)
  • Loading branch information
mkrout committed Apr 26, 2024
1 parent 5c24945 commit ee8752f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static List<ProfilePropertySettingEntity> buildProperties(Profile profile

Map<Long, ProfilePropertySettingEntity> properties = new HashMap<>();
ProfilePropertyService profilePropertyService = CommonsUtils.getService(ProfilePropertyService.class);
List<ProfilePropertySetting> settings = profilePropertyService.getPropertySettings();
List<ProfilePropertySetting> settings = profilePropertyService.getPropertySettings().stream().filter(prop -> prop.isVisible() || prop.isEditable()).toList();
List<ProfilePropertySetting> subProperties = new ArrayList<>();
List<Long> parents = new ArrayList<>();
boolean internal = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.social.core.profileproperty.ProfilePropertyService;
import org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting;
import org.exoplatform.social.rest.entity.ProfilePropertySettingEntity;
Expand All @@ -51,6 +52,8 @@ public class ProfileSettingsRest implements ResourceContainer {

private static final Log LOG = ExoLogger.getLogger(ProfileSettingsRest.class);

private static final String GROUP_ADMINISTRATORS = "/platform/administrators";

private final ProfilePropertyService profilePropertyService;

public ProfileSettingsRest(ProfilePropertyService profilePropertyService) {
Expand Down Expand Up @@ -78,6 +81,9 @@ public Response getPropertySettings(@Context
}
try {
List<ProfilePropertySetting> properties = profilePropertyService.getPropertySettings();
if (!ConversationState.getCurrent().getIdentity().isMemberOf(GROUP_ADMINISTRATORS)) {
properties = properties.stream().filter(prop -> prop.isVisible() || prop.isEditable()).toList();
}
List<ProfilePropertySettingEntity> propertySettingEntities = EntityBuilder.buildEntityProfilePropertySettingList(properties, profilePropertyService, ProfilePropertyService.LABELS_OBJECT_TYPE);
return Response.ok(propertySettingEntities).build();
}catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public Response getUserById(@Context UriInfo uriInfo,

String expandedSettings = expand;
if (expand != null && expand.contains("settings")) {
expandedSettings = String.valueOf(Objects.hash(EntityBuilder.buildEntityProfilePropertySettingList(profilePropertyService.getPropertySettings(),profilePropertyService, ProfilePropertyService.LABELS_OBJECT_TYPE)));
expandedSettings = String.valueOf(Objects.hash(EntityBuilder.buildEntityProfilePropertySettingList(profilePropertyService.getPropertySettings().stream().filter(prop -> prop.isVisible() || prop.isEditable()).toList(),profilePropertyService, ProfilePropertyService.LABELS_OBJECT_TYPE)));
}

long cacheTime = identity.getCacheTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,33 @@ public void setUp() throws Exception {
ProfilePropertySetting urlsPropertySetting = new ProfilePropertySetting();
urlsPropertySetting.setPropertyName("urls");
urlsPropertySetting.setMultiValued(true);
urlsPropertySetting.setVisible(true);
urlsPropertySetting.setEditable(true);
urlsPropertySetting = profilePropertyService.createPropertySetting(urlsPropertySetting);
tearDownProfilePropertyList.add(urlsPropertySetting);

// Create profile properties
ProfilePropertySetting phonesPropertySetting = new ProfilePropertySetting();
phonesPropertySetting.setPropertyName("phones");
phonesPropertySetting.setVisible(true);
phonesPropertySetting.setEditable(true);
phonesPropertySetting = profilePropertyService.createPropertySetting(phonesPropertySetting);
tearDownProfilePropertyList.add(phonesPropertySetting);

ProfilePropertySetting workPhonePropertySetting = new ProfilePropertySetting();
workPhonePropertySetting.setPropertyName("phones.work");
workPhonePropertySetting.setMultiValued(false);
workPhonePropertySetting.setVisible(true);
workPhonePropertySetting.setEditable(true);
workPhonePropertySetting.setParentId(phonesPropertySetting.getId());
workPhonePropertySetting = profilePropertyService.createPropertySetting(workPhonePropertySetting);
tearDownProfilePropertyList.add(workPhonePropertySetting);

ProfilePropertySetting homePhonePropertySetting = new ProfilePropertySetting();
homePhonePropertySetting.setPropertyName("phones.home");
homePhonePropertySetting.setMultiValued(false);
homePhonePropertySetting.setVisible(true);
homePhonePropertySetting.setEditable(true);
homePhonePropertySetting.setParentId(phonesPropertySetting.getId());
homePhonePropertySetting = profilePropertyService.createPropertySetting(homePhonePropertySetting);
tearDownProfilePropertyList.add(homePhonePropertySetting);
Expand All @@ -184,12 +192,16 @@ public void setUp() throws Exception {
ProfilePropertySetting imsPropertySetting = new ProfilePropertySetting();
imsPropertySetting.setPropertyName("ims");
imsPropertySetting.setMultiValued(false);
imsPropertySetting.setVisible(true);
imsPropertySetting.setEditable(true);
imsPropertySetting = profilePropertyService.createPropertySetting(imsPropertySetting);
tearDownProfilePropertyList.add(imsPropertySetting);

ProfilePropertySetting facebookPropertySetting = new ProfilePropertySetting();
facebookPropertySetting.setPropertyName("ims.facebook");
facebookPropertySetting.setMultiValued(false);
facebookPropertySetting.setVisible(true);
facebookPropertySetting.setEditable(true);
facebookPropertySetting.setParentId(imsPropertySetting.getId());
facebookPropertySetting = profilePropertyService.createPropertySetting(facebookPropertySetting);
tearDownProfilePropertyList.add(facebookPropertySetting);
Expand All @@ -199,6 +211,7 @@ public void setUp() throws Exception {
ProfilePropertySetting basicProfilePropertySetting = new ProfilePropertySetting();
basicProfilePropertySetting.setPropertyName(profileProperty);
basicProfilePropertySetting.setMultiValued(false);
basicProfilePropertySetting.setVisible(true);
try {
basicProfilePropertySetting = profilePropertyService.createPropertySetting(basicProfilePropertySetting);
tearDownProfilePropertyList.add(basicProfilePropertySetting);
Expand Down Expand Up @@ -486,6 +499,7 @@ public void testGetUserById() throws Exception {

ProfilePropertySetting profilePropertySetting = new ProfilePropertySetting();
profilePropertySetting.setPropertyName(Profile.LOCATION);
profilePropertySetting.setEditable(true);
profilePropertyService.createPropertySetting(profilePropertySetting);
ContainerResponse response1 = service("GET", getURLResource("users/john?expand=settings"), "", null, null);
String etag1 = response1.getHttpHeaders().get("etag").toString();
Expand All @@ -496,7 +510,7 @@ public void testGetUserById() throws Exception {
label.setLabel("labelTest");
label.setLanguage("en");
label.setObjectType("profileProperty");
label.setObjectId(profilePropertyService.getProfileSettingByName(Profile.FIRST_NAME).getId().toString());
label.setObjectId(profilePropertyService.getProfileSettingByName(Profile.LOCATION).getId().toString());
profileLabelService.createLabel(label);
ContainerResponse response2 = service("GET", getURLResource("users/john?expand=settings"), "", null, null);
String etag2 = response2.getHttpHeaders().get("etag").toString();
Expand Down

0 comments on commit ee8752f

Please sign in to comment.