use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method subscribeEmail.
@PUT
@Path("/email/subscription/{bundleName}/{applicationName}/{type}")
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@Transactional
public boolean subscribeEmail(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName, @PathParam("type") EmailSubscriptionType type) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
Application app = applicationRepository.getApplication(bundleName, applicationName);
if (app == null) {
throw new NotFoundException();
} else {
return emailSubscriptionRepository.subscribe(principal.getAccount(), principal.getName(), bundleName, applicationName, type);
}
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method deleteEndpoint.
@DELETE
@Path("/{id}")
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "204", description = "The integration has been deleted", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response deleteEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
if (obEnabled) {
Endpoint e = endpointRepository.getEndpoint(principal.getAccount(), id);
if (e != null) {
EndpointProperties properties = e.getProperties();
if (properties instanceof CamelProperties) {
CamelProperties cp = (CamelProperties) properties;
// Special case wrt OpenBridge
if (e.getSubType().equals("slack")) {
String processorId = cp.getExtras().get(OB_PROCESSOR_ID);
if (processorId != null) {
// Should not be null under normal operations.
try {
bridgeApiService.deleteProcessor(bridge.getId(), processorId, bridgeAuth.getToken());
} catch (Exception ex) {
LOGGER.warn("Removal of OB processor failed:" + ex.getMessage());
// Nothing more we can do
}
} else {
LOGGER.warn("ProcessorId was null for endpoint " + id.toString());
}
}
}
}
}
endpointRepository.deleteEndpoint(principal.getAccount(), id);
return Response.noContent().build();
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method updateEndpoint.
@PUT
@Path("/{id}")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response updateEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id, @NotNull @Valid Endpoint endpoint) {
// This prevents from updating an endpoint from whatever EndpointType to a system EndpointType
checkSystemEndpoint(endpoint.getType());
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
endpoint.setAccountId(principal.getAccount());
endpoint.setId(id);
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
// This prevents from updating an endpoint from system EndpointType to a whatever EndpointType
checkSystemEndpoint(endpointType);
endpointRepository.updateEndpoint(endpoint);
return Response.ok().build();
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method unsubscribeEmail.
@DELETE
@Path("/email/subscription/{bundleName}/{applicationName}/{type}")
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@Transactional
public boolean unsubscribeEmail(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName, @PathParam("type") EmailSubscriptionType type) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
Application app = applicationRepository.getApplication(bundleName, applicationName);
if (app == null) {
throw new NotFoundException();
} else {
return emailSubscriptionRepository.unsubscribe(principal.getAccount(), principal.getName(), bundleName, applicationName, type);
}
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class UserConfigResource method saveSettings.
@POST
@Path("/notification-preference")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
@Operation(hidden = true)
@Transactional
public Response saveSettings(@Context SecurityContext sec, @Valid SettingsValues values) {
final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
final String account = principal.getAccount();
final String name = principal.getName();
final List<Boolean> subscriptionRequests = new ArrayList<>();
values.bundles.forEach((bundleName, bundleSettingsValue) -> bundleSettingsValue.applications.forEach((applicationName, applicationSettingsValue) -> {
Application app = applicationRepository.getApplication(bundleName, applicationName);
applicationSettingsValue.notifications.forEach((emailSubscriptionType, subscribed) -> {
if (subscribed) {
if (app != null) {
subscriptionRequests.add(emailSubscriptionRepository.subscribe(account, name, bundleName, applicationName, emailSubscriptionType));
}
} else {
subscriptionRequests.add(emailSubscriptionRepository.unsubscribe(account, name, bundleName, applicationName, emailSubscriptionType));
}
});
}));
boolean allisSuccess = subscriptionRequests.stream().allMatch(Boolean.TRUE::equals);
Response.ResponseBuilder builder;
if (allisSuccess) {
builder = Response.ok();
} else {
// Prevent from saving
builder = Response.serverError().entity("Storing of settings Failed.");
builder.type("text/plain");
}
return builder.build();
}
Aggregations