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

Add notification for users with disabled SCC data forwarding (jsc#SUMA-431) #9582

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 @@ -59,7 +59,9 @@ public class GeneralConfigAction extends BaseConfigAction {
ConfigDefaults.HTTP_PROXY_USERNAME, ConfigDefaults.HTTP_PROXY_PASSWORD,
ConfigDefaults.MOUNT_POINT};

private static final String[] BOOLEAN_CONFIG_ARRAY = { ConfigDefaults.DISCONNECTED };
private static final String[] BOOLEAN_CONFIG_ARRAY = { ConfigDefaults.DISCONNECTED,
ConfigDefaults.FORWARD_REGISTRATION
};

private static final List<String> ALLOWED_CONFIGS = new LinkedList<>();
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9511,6 +9511,16 @@ 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. &lt;a href="/rhn/admin/config/GeneralConfig.do"&gt;Enable data forwarding&lt;/a&gt;.&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 @@ -8603,6 +8603,12 @@ administrator privileges.</source>
<context context-type="sourcefile">/rhn/admin/config/GeneralConfig.do</context>
</context-group>
</trans-unit>
<trans-unit id="general.jsp.scc_data_forwarding" xml:space="preserve">
<source>Synchronize client registration data with SCC</source>
<context-group name="ctx">
<context context-type="sourcefile">/rhn/admin/config/GeneralConfig.do</context>
</context-group>
</trans-unit>
<trans-unit id="config.update" xml:space="preserve">
<source>Update</source>
<context-group name="ctx">
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
11 changes: 11 additions & 0 deletions java/code/webapp/WEB-INF/pages/admin/config/general.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@
styleId="mount_point" />
</div>
</div>
<div class="form-group">
<label for="forward_registration" class="col-lg-3 control-label">
<bean:message key="general.jsp.scc_data_forwarding"/>
</label>
<div class="col-lg-6">
<div class="checkbox">
<html:checkbox property="server|susemanager|forward_registration"
styleId="forward_registration" />
</div>
</div>
</div>
<div class="form-group hidden">
<label class="col-lg-3 control-label" for="disconnected">
<bean:message key="general.jsp.disconnected"/>
Expand Down
1 change: 1 addition & 0 deletions java/code/webapp/WEB-INF/struts-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
<form-property name="server|satellite|http_proxy_password" type="java.lang.String"/>
<form-property name="server|satellite|http_proxy_password_confirm" type="java.lang.String"/>
<form-property name="mount_point" type="java.lang.String"/>
<form-property name="server|susemanager|forward_registration" type="java.lang.Boolean"/>
<form-property name="disconnected" type="java.lang.Boolean"/>
<form-property name="submitted" type="java.lang.Boolean"/>
<form-property name="no_scrub" type="java.lang.String"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add notification for users with disabled SCC data forwarding
(jsc#SUMA-431)
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
2 changes: 2 additions & 0 deletions web/spacewalk-web.changes.welder.scc-data-forwarding-warning
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add notification for users with disabled SCC data forwarding
(jsc#SUMA-431)
Loading