Skip to content

Commit

Permalink
Add notification for users with disabled SCC data forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
wweellddeerr committed Dec 17, 2024
1 parent 0eaada1 commit 44b2b20
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.redhat.rhn.domain.notification.types.OnboardingFailed;
import com.redhat.rhn.domain.notification.types.PaygAuthenticationUpdateFailed;
import com.redhat.rhn.domain.notification.types.PaygNotCompliantWarning;
import com.redhat.rhn.domain.notification.types.SCCOptOutWarning;
import com.redhat.rhn.domain.notification.types.StateApplyFailed;
import com.redhat.rhn.domain.notification.types.SubscriptionWarning;
import com.redhat.rhn.domain.notification.types.UpdateAvailable;
Expand Down Expand Up @@ -141,6 +142,8 @@ public NotificationData getNotificationData() {
return new Gson().fromJson(getData(), UpdateAvailable.class);
case PaygNotCompliantWarning:
return new Gson().fromJson(getData(), PaygNotCompliantWarning.class);
case SCCOptOutWarning:
return new Gson().fromJson(getData(), SCCOptOutWarning.class);
default: throw new RhnRuntimeException("Notification type not found");
}
}
Expand All @@ -162,6 +165,7 @@ public String getTypeAsString() {
case SubscriptionWarning: return "Subscription Warning";
case UpdateAvailable: return "Updates are Available";
case PaygNotCompliantWarning: return "PAYG instance is not compliant";
case SCCOptOutWarning: return "SCC Data Sync Disabled";
default: return getType().name();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.redhat.rhn.common.messaging.Mail;
import com.redhat.rhn.common.messaging.SmtpMail;
import com.redhat.rhn.domain.notification.types.NotificationData;
import com.redhat.rhn.domain.notification.types.NotificationType;
import com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.user.User;
Expand Down Expand Up @@ -237,6 +238,22 @@ public static List<UserNotification> listAllByUser(User userIn) {
return getSession().createQuery(criteria).getResultList();
}

/**
* Fetch the most recent {@link NotificationMessage} of a given type.
*
* @param messageType the type of the notification message
* @return the latest NotificationMessage of the specified type, or null if none found
*/
public static NotificationMessage getLastNotificationMessageByType(NotificationType messageType) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<NotificationMessage> criteria = builder.createQuery(NotificationMessage.class);
Root<NotificationMessage> root = criteria.from(NotificationMessage.class);
criteria.where(builder.equal(root.get("type"), messageType));
criteria.orderBy(builder.desc(root.get("created")));
List<NotificationMessage> result = getSession().createQuery(criteria).setMaxResults(1).getResultList();
return result.isEmpty() ? null : result.get(0);
}

/**
* Lookup for unread {@link UserNotification}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public enum NotificationType {
SubscriptionWarning,
UpdateAvailable,
PaygNotCompliantWarning,
SCCOptOutWarning,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.rhn.domain.notification.types;

import com.redhat.rhn.common.localization.LocalizationService;
import com.redhat.rhn.domain.notification.NotificationMessage;

public class SCCOptOutWarning implements NotificationData {

private static final LocalizationService LOCALIZATION_SERVICE = LocalizationService.getInstance();

@Override
public NotificationMessage.NotificationMessageSeverity getSeverity() {
return NotificationMessage.NotificationMessageSeverity.WARNING;
}

@Override
public NotificationType getType() {
return NotificationType.SCCOptOutWarning;
}

@Override
public String getSummary() {
return LOCALIZATION_SERVICE.getMessage("notification.sccoptoutwarning.summary");
}

@Override
public String getDetails() {
return LOCALIZATION_SERVICE.getMessage("notification.sccoptoutwarning.detail");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9511,6 +9511,17 @@ For a detailed analysis, please refer to the log files.</source>
<source>&lt;p&gt;@@PRODUCT_NAME@@ {0} is approaching the end of its lifecycle. Please consider upgrading this server instance before general support ends on &lt;strong&gt;{1}&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For Additional information on how to upgrade @@PRODUCT_NAME@@, please review the section &lt;em&gt;Upgrade&lt;/em&gt; of the &lt;em&gt;Installation/Upgrade Guide&lt;/em&gt; in the official documentation.&lt;/p&gt;</source>
</trans-unit>
<trans-unit id="notification.sccoptoutwarning.summary">
<source>Data is not being synchronized with SCC</source>
</trans-unit>
<trans-unit id="notification.sccoptoutwarning.detail" xml:space="preserve">
<source>
&lt;p&gt;Disabling data synchronizing with SCC will lead to reduced visibility of your managed clients between RMT, SMT, @@PRODUCT_NAME@@ and SCC-directly registered clients.
By synchronizing data, you ensure a uniform view of all registered clients. Please consider enabling data forwarding again by changing the 'server.susemanager.forward_registration'
property in the rhn.conf file.&lt;/p&gt;
&lt;a href="https://suselinux.fra1.qualtrics.com/jfe/form/SV_0ooNnrY0rYuQScS" target="_blank"&gt;Help us improve our services by sharing your reason for opting out&lt;/a&gt;
</source>
</trans-unit>
<trans-unit id="task.action.rejection.reason">
<source>This action was not executed because its earliest execution date was too old. When more than {0} hours pass between the scheduling and the picking up, the action is discarded because it is considered no longer relevant.
Please reschedule this action if you really want it to be executed.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import com.redhat.rhn.common.conf.ConfigDefaults;
import com.redhat.rhn.domain.credentials.CredentialsFactory;
import com.redhat.rhn.domain.credentials.SCCCredentials;
import com.redhat.rhn.domain.notification.NotificationMessage;
import com.redhat.rhn.domain.notification.UserNotificationFactory;
import com.redhat.rhn.domain.notification.types.NotificationType;
import com.redhat.rhn.domain.notification.types.SCCOptOutWarning;
import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.scc.SCCCachingFactory;
import com.redhat.rhn.domain.scc.SCCRegCacheItem;
import com.redhat.rhn.manager.content.ContentSyncManager;
Expand All @@ -29,11 +34,14 @@
import com.suse.scc.client.SCCWebClient;
import com.suse.scc.model.SCCVirtualizationHostJson;

import org.apache.commons.lang3.time.DateUtils;
import org.quartz.JobExecutionContext;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -53,6 +61,16 @@ public String getConfigNamespace() {
@Override
public void execute(JobExecutionContext arg0) {
if (!ConfigDefaults.get().isForwardRegistrationEnabled()) {
NotificationMessage lastNotification = UserNotificationFactory
.getLastNotificationMessageByType(NotificationType.SCCOptOutWarning);

if (lastNotification == null || lastNotification.getCreated().before(DateUtils.addMonths(new Date(), -3))) {
NotificationMessage notificationMessage =
UserNotificationFactory.createNotificationMessage(new SCCOptOutWarning());
UserNotificationFactory.storeNotificationMessageFor(notificationMessage,
Collections.singleton(RoleFactory.ORG_ADMIN), Optional.empty());
}

if (GlobalInstanceHolder.PAYG_MANAGER.isPaygInstance() &&
GlobalInstanceHolder.PAYG_MANAGER.hasSCCCredentials()) {
log.warn("SUSE Manager PAYG instances must forward registration data to SCC when " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add notification for users with disabled SCC data forwarding (jsc#SUMA-431)

Check failure on line 1 in java/spacewalk-java.changes.welder.scc-data-forwarding-warning

View workflow job for this annotation

GitHub Actions / Changelog tests

Line exceeds 67 characters in file java/spacewalk-java.changes.welder.scc-data-forwarding-warning#L1

Check failure on line 1 in java/spacewalk-java.changes.welder.scc-data-forwarding-warning

View workflow job for this annotation

GitHub Actions / Changelog tests

SUMA-431 is not mentioned in PR title or in commit messages in file java/spacewalk-java.changes.welder.scc-data-forwarding-warning#L1
4 changes: 4 additions & 0 deletions web/html/src/manager/notifications/notification-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const _MESSAGE_TYPE = {
id: "PaygNotCompliantWarning",
text: t("PAYG instance is not compliant"),
},
SCCOptOutWarning: {
id: "SCCOptOutWarning",
text: t("SCC Data Sync Disabled"),
},
};

function reloadData(dataUrlSlice: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add notification for users with disabled SCC data forwarding (jsc#SUMA-431)

Check failure on line 1 in web/spacewalk-web.changes.welder.scc-data-forwarding-warning

View workflow job for this annotation

GitHub Actions / Changelog tests

Line exceeds 67 characters in file web/spacewalk-web.changes.welder.scc-data-forwarding-warning#L1

Check failure on line 1 in web/spacewalk-web.changes.welder.scc-data-forwarding-warning

View workflow job for this annotation

GitHub Actions / Changelog tests

SUMA-431 is not mentioned in PR title or in commit messages in file web/spacewalk-web.changes.welder.scc-data-forwarding-warning#L1

0 comments on commit 44b2b20

Please sign in to comment.