Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent external users from receiving notifications of published news from a space which they are not members - EXO-69079 #200

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
@@ -40,6 +42,14 @@ public UserSetExternalInGateinPortal(OrganizationService organizationService,Ini

}
@Override
public boolean shouldProceedToUpgrade(String newVersion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need that @sofyenne ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure that the upgrade plugin executes only once!

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();
@@ -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());

@@ -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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add log here to show progression: nb of users executed/ total number of users

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

} catch (Exception e) {
LOG.error("Unable to get profile for user {}",username);
}
Original file line number Diff line number Diff line change
@@ -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>
@@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.6.x -> 6.6.0 @sofyenne ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just to test acceptance, we set the correct version for the merge!

</value-param>
<value-param>
<name>plugin.execution.order</name>