Skip to content

Commit

Permalink
fix: Prevent external users from receiving notifications of published…
Browse files Browse the repository at this point in the history
… news from a space which they are not members - EXO-69079 (#200)

Prior to this change, external users were receiving notifications of published news from a space in which they were not members. This issue was caused by the absence of external property information in the gatein profile, which was only present in the social profile.
After updating the ExternalUersLinstenerImp to set the external status in the gatein profile for the newly created users , this change will re-execute the ExternalUserUpgradePlugin to set the external status in the gatein profile for the previously created users.
  • Loading branch information
sofyenne committed Jan 31, 2024
1 parent 03b3f33 commit 4484b89
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.exoplatform.migration;

import org.exoplatform.commons.upgrade.UpgradePluginExecutionContext;
import org.exoplatform.commons.upgrade.UpgradeProductPlugin;
import org.exoplatform.commons.utils.ListAccess;
import org.exoplatform.container.ExoContainerContext;
Expand All @@ -29,6 +30,7 @@
import org.exoplatform.services.organization.UserProfile;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

public class UserSetExternalInGateinPortal extends UpgradeProductPlugin {
private static final Log LOG = ExoLogger.getExoLogger(UserSetExternalInGateinPortal.class);
Expand All @@ -40,6 +42,14 @@ public UserSetExternalInGateinPortal(OrganizationService organizationService,Ini

}
@Override
public boolean shouldProceedToUpgrade(String newVersion,
String previousGroupVersion,
UpgradePluginExecutionContext previousUpgradePluginExecution) {

int executionCount = previousUpgradePluginExecution == null ? 0 : previousUpgradePluginExecution.getExecutionCount();
return !isExecuteOnlyOnce() || executionCount == 0;
}
@Override
public void processUpgrade(String oldVersion, String newVersion) {
LOG.info("Start upgrade process to add external info in gatein user profile");
long startupTime = System.currentTimeMillis();
Expand All @@ -50,7 +60,8 @@ public void processUpgrade(String oldVersion, String newVersion) {
LOG.info("Number of users to update : " + total);

int pageSize = 100;
int current=0;
int current = 0;
AtomicInteger updatedUserProfiles = new AtomicInteger(0);
while (current<total) {
RequestLifeCycle.begin(ExoContainerContext.getCurrentContainer());

Expand All @@ -63,9 +74,16 @@ public void processUpgrade(String oldVersion, String newVersion) {
if (profile==null) {
profile=organizationService.getUserProfileHandler().createUserProfileInstance(username);
}
profile.setAttribute(UserProfile.OTHER_KEYS[2],"true");
organizationService.getUserProfileHandler().saveUserProfile(profile,true);
LOG.debug("External info added in gatein profile for user {}, {}ms", username, System.currentTimeMillis() - startTimeForUser);
// do not update the profiles of users who already have the correct external property value
if (profile.getAttribute(UserProfile.OTHER_KEYS[2]) != null && String.valueOf(true).equals(profile.getAttribute(UserProfile.OTHER_KEYS[2]))) {
LOG.debug("External info already set in gatein profile for user {}", username);
} else {
profile.setAttribute(UserProfile.OTHER_KEYS[2],"true");
organizationService.getUserProfileHandler().saveUserProfile(profile,true);
updatedUserProfiles.getAndIncrement();
LOG.debug("External info added in gatein profile for user {}", username);
LOG.info("Progession : {} users updated on {} total users", updatedUserProfiles.get(), total);
}
} catch (Exception e) {
LOG.error("Unable to get profile for user {}",username);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<external-component-plugins>
<target-component>org.exoplatform.commons.upgrade.UpgradeProductService</target-component>
<component-plugin>
<name>ExternalUserUpgradePlugin</name>
<name>ExternalUserUpgradePluginV1</name>
<set-method>addUpgradePlugin</set-method>
<type>org.exoplatform.migration.UserSetExternalInGateinPortal</type>
<description>Add external information in gatein portal profile</description>
Expand All @@ -74,7 +74,7 @@
<name>plugin.upgrade.target.version</name>
<description>The plugin target version (will not be executed if previous version is equal or higher than 6.3.1)
</description>
<value>6.3.0</value>
<value>6.6.x</value>
</value-param>
<value-param>
<name>plugin.execution.order</name>
Expand Down

0 comments on commit 4484b89

Please sign in to comment.