use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class UserConfigResource method getSettingsSchema.
@GET
@Path("/notification-preference")
@Produces(APPLICATION_JSON)
@Operation(hidden = true)
public Response getSettingsSchema(@Context SecurityContext sec, @QueryParam("bundleName") String bundleName) {
final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
final String account = principal.getAccount();
final String name = principal.getName();
SettingsValues settingsValues = getSettingsValueForUser(account, name, bundleName);
String jsonFormString = settingsValuesToJsonForm(settingsValues);
Response.ResponseBuilder builder;
builder = Response.ok(jsonFormString);
EntityTag etag = new EntityTag(String.valueOf(jsonFormString.hashCode()));
builder.header("ETag", etag);
return builder.build();
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class UserConfigResource method getPreferences.
@GET
@Path("/notification-preference/{bundleName}/{applicationName}")
@Produces(APPLICATION_JSON)
@Operation(hidden = true)
public UserConfigPreferences getPreferences(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName) {
final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
final String account = principal.getAccount();
final String name = principal.getName();
final UserConfigPreferences preferences = new UserConfigPreferences();
// TODO Get the DAILY and INSTANT subscriptions with a single SQL query and return UserConfigPreferences directly from Hibernate.
EmailSubscription daily = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.DAILY);
preferences.setDailyEmail(daily != null);
EmailSubscription instant = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.INSTANT);
preferences.setInstantEmail(instant != null);
return preferences;
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method getEndpointHistory.
@GET
@Path("/{id}/history")
@Produces(APPLICATION_JSON)
@Parameters({ @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page, if not specified or 0 is used, returns a maximum of " + MAX_NOTIFICATION_HISTORY_RESULTS + " elements.", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "pageNumber", in = ParameterIn.QUERY, description = "Page number. Starts at first page (0), if not specified starts at first page.", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "includeDetail", description = "Include the detail in the reply", schema = @Schema(type = SchemaType.BOOLEAN)) })
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
public List<NotificationHistory> getEndpointHistory(@Context SecurityContext sec, @PathParam("id") UUID id, @QueryParam("includeDetail") Boolean includeDetail, @BeanParam Query query) {
// TODO We need globally limitations (Paging support and limits etc)
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
boolean doDetail = includeDetail != null && includeDetail;
return notificationRepository.getNotificationHistory(principal.getAccount(), id, doDetail, query);
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method disableEndpoint.
@DELETE
@Path("/{id}/enable")
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "204", description = "The integration has been disabled", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response disableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
endpointRepository.disableEndpoint(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 enableEndpoint.
@PUT
@Path("/{id}/enable")
@Produces(TEXT_PLAIN)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response enableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
endpointRepository.enableEndpoint(principal.getAccount(), id);
return Response.ok().build();
}
Aggregations