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
  • Loading branch information
sofyenne committed Jan 26, 2024
1 parent d989c8f commit f9df3c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 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 @@ -40,6 +41,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 @@ -63,9 +72,13 @@ 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);
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);
LOG.debug("External info added in gatein profile for user {}, {}ms", username, System.currentTimeMillis() - startTimeForUser);
}
} 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 f9df3c2

Please sign in to comment.