Skip to content

Commit

Permalink
#30156 include in 23.10.24 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Oct 23, 2024
1 parent 23ee021 commit a4473bd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ This maintenance release includes the following code fixes:
159. https://github.com/dotCMS/core/issues/30420 : Fix Test CircuitBreakerUrlTest.testGet and RemoteAnnouncementsLoaderIntegrationTest.TestAnnouncementsLoader #30420
160. https://github.com/dotCMS/core/issues/29535 : Investigate and Resolve Session Already Invalidated Issue for PATCH API Call with Bearer Token #29535
161. https://github.com/dotCMS/core/issues/29938 : Many to One Relationship Not Maintained When Copied to New Host #29938
162. https://github.com/dotCMS/core/issues/30156 : Create Notifications for LTS already EOL or upcoming EOL #30156
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.dotcms.cms.login;

import static com.dotcms.util.CollectionsUtils.list;
import static com.dotmarketing.util.CookieUtil.createJsonWebTokenCookie;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dotcms.api.system.event.message.MessageSeverity;
import com.dotcms.api.system.event.message.MessageType;
import com.dotcms.api.system.event.message.SystemMessageEventUtil;
import com.dotcms.api.system.event.message.builder.SystemMessageBuilder;
import com.dotcms.concurrent.DotConcurrentFactory;
import com.liferay.portal.language.LanguageException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -291,7 +302,11 @@ public boolean doActionLogin(String userId,

this.doAuthentication(userId, rememberMe, request, response);
authenticated = true;
LicenseUtil.licenseExpiresMessage(APILocator.getUserAPI().loadUserById(userId));
final User logInUser = APILocator.getUserAPI().loadUserById(userId);
LicenseUtil.licenseExpiresMessage(logInUser);
if (Config.getBooleanProperty("show.lts.eol.message", false)) {
messageLTSVersionEOL(logInUser);
}
}

if (authResult != Authenticator.SUCCESS) {
Expand Down Expand Up @@ -547,6 +562,48 @@ public User getLoggedInUser( ){
}
}


/**
* Message to show LTS version is reaching or already reached EOL.
* Must set the property date.lts.eol in dotmarketing-config.properties, the date should be in MM/dd/yyyy format.
* Must set the property show.lts.eol.message in dotmarketing-config.properties to true.
* If the user has the CMSAdmin role, show the message when the days left for LTS to EOL is less than 30.
* If the LTS already went EOL, show the message to everyone.
*/
public static void messageLTSVersionEOL(final User user) throws DotDataException, LanguageException, ParseException {
final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
final Date dateLTSEOL = dateFormat.parse(Config.getStringProperty("date.lts.eol", "12/31/2099")); //LTS EOL Date
final long daysleftToEOL = DateUtil.diffDates(new Date(), dateLTSEOL).get("diffDays"); //days left for LTS to EOL
SystemMessageBuilder message = null;
if (APILocator.getRoleAPI().doesUserHaveRole(user, APILocator.getRoleAPI().loadCMSAdminRole()) && //check if user have CMSAdmin Role
(daysleftToEOL <= 30) && (daysleftToEOL > 0)) { //check if days left for LTS to EOL is less than 30 and over 0
//Message Admins that EOL is less than 30 days
message = new SystemMessageBuilder()
.setMessage(LanguageUtil.format(
user.getLocale(),
"lts.expires.soon.message",
daysleftToEOL))
.setSeverity(MessageSeverity.WARNING)
.setType(MessageType.SIMPLE_MESSAGE)
.setLife(86400000);
}
//if LTS already EOL show message to everyone
if (daysleftToEOL <= 0) {
message = new SystemMessageBuilder()
.setMessage(LanguageUtil.get(
user.getLocale(),
"lts.expired.message"))
.setSeverity(MessageSeverity.ERROR)
.setType(MessageType.SIMPLE_MESSAGE)
.setLife(86400000);
}
if (null != message) {
final SystemMessageBuilder finalMessage = message;
DotConcurrentFactory.getInstance().getSubmitter().delay(() -> {
SystemMessageEventUtil.getInstance().pushMessage(finalMessage.create(), list(user.getUserId()));
Logger.info("", finalMessage.create().getMessage().toString());
},
3000, TimeUnit.MILLISECONDS);
}
}

} // E:O:F:LoginServiceAPIFactory.
4 changes: 4 additions & 0 deletions dotCMS/src/main/resources/dotmarketing-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,7 @@ DOT_FEATURE_FLAG_TEMPLATE_BUILDER_2=true

## Experiments - A/B Testing
FEATURE_FLAG_EXPERIMENTS=true

##LTS properties to show EOL message
show.lts.eol.message=true
date.lts.eol=05/19/2025
5 changes: 4 additions & 1 deletion dotCMS/src/main/webapp/WEB-INF/messages/Language.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5561,4 +5561,7 @@ block-editor.extension.ai-image.auto-text.placeholder=E.g. 1200x800px, vibrant c
block-editor.extension.ai-image.auto-text.tooltip=Describe the size, color palette, style, mood, etc.
block-editor.extension.ai-image.api-error.missing-token=Error: Incorrect API key provided. You can find your API key at https://platform.openai.com/account/api-keys.
block-editor.extension.ai-image.api-error.error-publishing-ai-image=Error publishing AI image
block-editor.extension.ai-image.api-error.no-choice-returned=No choices returned
block-editor.extension.ai-image.api-error.no-choice-returned=No choices returned
lts.expired.message = This version of dotCMS already reached EOL. Please contact your CSM to schedule an upgrade.
lts.expires.soon.message = Your dotCMS version will reach EOL in {0} days. Please contact your CSM to schedule an upgrade.

0 comments on commit a4473bd

Please sign in to comment.