Skip to content

Commit

Permalink
RHCLOUD-29294 Setup emails for RBAC request-access event type (RedHat…
Browse files Browse the repository at this point in the history
…Insights#2329)

* RHCLOUD-29294 Setup emails for RBAC request-access event type

* Updated tests to include request-access
 - Updated email template to use "action" instead of "data"
  • Loading branch information
josejulio authored Nov 14, 2023
1 parent 1271855 commit 0bf5c09
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public List<String> migrate() {
"Rbac/platformGroupToCustomBody", "html", "Rbac platform group to custom drawer body"
);

createDrawerIntegrationTemplate(
warnings, "console", "rbac", List.of("request-access"),
"Rbac/requestAccess", "html", "Rbac platform group to custom drawer body"
);

// Sources
createDrawerIntegrationTemplate(
warnings, "console", "sources", List.of("availability-status"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ public List<String> migrate() {
"Rbac/platformGroupToCustomEmailTitle", "txt", "Rbac platform group to custom email title",
"Rbac/platformGroupToCustomEmailBody", "html", "Rbac platform group to custom email body"
);
createInstantEmailTemplate(
warnings, "console", "rbac", List.of("request-access"),
"Rbac/requestAccessEmailTitle", "txt", "Rbac request access email title",
"Rbac/requestAccessEmailBody", "html", "Rbac request access email body"
);

/*
* Former src/main/resources/templates/ResourceOptimization folder.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{@boolean renderSection1=true}
{@boolean renderButtonSection1=true}
{#include Common/insightsEmailBody}
{#content-title}
User Access - Console
{/content-title}
{#content-title-section1}
Request for access received
{/content-title-section1}
{#content-body-section1}
<p>
This message is to inform you that a user within your organization has requested access to a page or feature
within console.redhat.com. Please review this request and decide whether to grant or deny access.
</p>
<p>
<strong>User's Request:</strong>
<ul>
<li><strong>URL Path:</strong> {action.events[0].payload.url_path}</li>
<li><strong>Username:</strong> {action.events[0].payload.username}</li>
<li><strong>Email Address:</strong> {action.events[0].payload.user.email}</li>
<li><strong>Message from User:</strong> "{action.events[0].payload.user.request}"</li>
</ul>
<br/>
<strong>Action Required:</strong>
<ul>
<li><strong>Granting Access:</strong>If you decide to grant access, please log in to the console and add the user to the appropriate <a target="blank" href="{environment.url}/iam/user-access/groups/">User Access Group(s).</a></li>
<li><strong>Denying Access:</strong> If you choose to deny access, kindly reach out to the user directly to explain the reason for the denial.</li>
</ul>
</p>
{/content-body-section1}
{#content-button-section1}
<a target="_blank" href="{environment.url}/iam/user-access/groups/}">Review your user access groups in the console</a>
{/content-button-section1}
{/include}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Instant notification - Request access - User Access - Console
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<b>{data.events[0].payload.username}</b> has requested access to <b>{data.events[0].payload.url_path}</b>.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ORG_ID;
Expand Down Expand Up @@ -38,6 +39,13 @@ public static Action createRbacAction() {
.withAdditionalProperty("username", "testUser1")
.withAdditionalProperty("principal", "testUser1")
.withAdditionalProperty("operation", "added")
// Used by request-access
.withAdditionalProperty("url_path", "https://console.redhat.com/stuff")
.withAdditionalProperty("user", Map.of(
"email", "testUser AT somewhere",
"request", "I want access to stuff"
))

.build()
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.redhat.cloud.notifications.ingress.Action;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.List;

Expand All @@ -29,6 +29,14 @@ public class TestRbacTemplate extends EmailTemplatesInDbHelper {
static final String GROUP_UPDATED = "group-updated";
static final String GROUP_DELETED = "group-deleted";
static final String PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM = "platform-default-group-turned-into-custom";
static final String REQUEST_ACCESS = "request-access";

static String[] RBAC_EVENT_TYPE_NAMES() {
return new String[]{RH_NEW_ROLE_AVAILABLE, RH_PLATFORM_DEFAULT_ROLE_UPDATED, RH_NON_PLATFORM_DEFAULT_ROLE_UPDATED, CUSTOM_ROLE_CREATED,
CUSTOM_ROLE_UPDATED, CUSTOM_ROLE_DELETED, RH_NEW_ROLE_ADDED_TO_DEFAULT_ACCESS, RH_ROLE_REMOVED_FROM_DEFAULT_ACCESS,
CUSTOM_DEFAULT_ACCESS_UPDATED, GROUP_CREATED, GROUP_UPDATED, GROUP_DELETED, PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM,
REQUEST_ACCESS};
}

@Override
protected String getBundle() {
Expand All @@ -42,10 +50,10 @@ protected String getApp() {

@Override
protected List<String> getUsedEventTypeNames() {
return List.of(RH_NEW_ROLE_AVAILABLE, RH_PLATFORM_DEFAULT_ROLE_UPDATED, RH_NON_PLATFORM_DEFAULT_ROLE_UPDATED, CUSTOM_ROLE_CREATED, CUSTOM_ROLE_UPDATED, CUSTOM_ROLE_DELETED, RH_NEW_ROLE_ADDED_TO_DEFAULT_ACCESS, RH_ROLE_REMOVED_FROM_DEFAULT_ACCESS, CUSTOM_DEFAULT_ACCESS_UPDATED, GROUP_CREATED, GROUP_UPDATED, GROUP_DELETED, PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM);
return List.of(RBAC_EVENT_TYPE_NAMES());
}

@ValueSource(strings = { RH_NEW_ROLE_AVAILABLE, RH_PLATFORM_DEFAULT_ROLE_UPDATED, RH_NON_PLATFORM_DEFAULT_ROLE_UPDATED, CUSTOM_ROLE_CREATED, CUSTOM_ROLE_UPDATED, CUSTOM_ROLE_DELETED, RH_NEW_ROLE_ADDED_TO_DEFAULT_ACCESS, RH_ROLE_REMOVED_FROM_DEFAULT_ACCESS, CUSTOM_DEFAULT_ACCESS_UPDATED, GROUP_CREATED, GROUP_UPDATED, GROUP_DELETED, PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM })
@MethodSource("RBAC_EVENT_TYPE_NAMES")
@ParameterizedTest
void shouldTestAllEventTypeTemplateTitles(String eventType) {
Action action = RbacTestHelpers.createRbacAction();
Expand All @@ -54,7 +62,7 @@ void shouldTestAllEventTypeTemplateTitles(String eventType) {
testTitle(eventType, result);
}

@ValueSource(strings = { RH_NEW_ROLE_AVAILABLE, RH_PLATFORM_DEFAULT_ROLE_UPDATED, RH_NON_PLATFORM_DEFAULT_ROLE_UPDATED, CUSTOM_ROLE_CREATED, CUSTOM_ROLE_UPDATED, CUSTOM_ROLE_DELETED, RH_NEW_ROLE_ADDED_TO_DEFAULT_ACCESS, RH_ROLE_REMOVED_FROM_DEFAULT_ACCESS, CUSTOM_DEFAULT_ACCESS_UPDATED, GROUP_CREATED, GROUP_UPDATED, GROUP_DELETED, PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM })
@MethodSource("RBAC_EVENT_TYPE_NAMES")
@ParameterizedTest
void shouldTestAllEventTypeTemplateBodies(String eventType) {
Action action = RbacTestHelpers.createRbacAction();
Expand Down Expand Up @@ -104,6 +112,9 @@ private void testTitle(String eventType, String result) {
case PLATFORM_DEFAULT_GROUP_TURNED_INTO_CUSTOM:
assertEquals("Instant notification - Platform default group is turned into custom - User Access - Console", result);
break;
case REQUEST_ACCESS:
assertEquals("Instant notification - Request access - User Access - Console", result);
break;
default:
break;
}
Expand Down Expand Up @@ -174,6 +185,16 @@ private void testBody(String eventType, String result) {
assertTrue(result.contains("Red Hat will not be responsible for managing it from now on."));
assertTrue(result.contains(TestHelpers.HCC_LOGO_TARGET));
break;
case REQUEST_ACCESS:
assertTrue(result.contains("Request for access received"));
assertTrue(result.contains("within console.redhat.com. Please review this request and decide whether to grant or deny access."));
assertTrue(result.contains("Granting Access:"));
assertTrue(result.contains("Denying Access:"));
assertTrue(result.contains("https://console.redhat.com/stuff"));
assertTrue(result.contains("I want access to stuff"));
assertTrue(result.contains("testUser AT somewhere"));
assertTrue(result.contains(TestHelpers.HCC_LOGO_TARGET));
break;
default:
break;
}
Expand Down

0 comments on commit 0bf5c09

Please sign in to comment.