use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class StoresCT method delete_shouldThrowForbidden_for_store_admin.
@Test
public void delete_shouldThrowForbidden_for_store_admin() {
try {
tester.setStoreAdminUser();
Store store = new Store("Superstore");
store.setOwner("test@test.org");
tester.test_delete(store);
fail("Should have throw an exception");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class CategoriesCT method delete_NonManagedEntry_shouldThrowForbiddenEx.
@Test
public void delete_NonManagedEntry_shouldThrowForbiddenEx() {
try {
tester.setStoreAdminUser();
Category category = new Category("Test category", "");
category.setOwner("test@test.com");
tester.test_delete(category);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class SKUsCT method delete_shouldThrow_Forbidden_for_store_Admin.
@Test
public void delete_shouldThrow_Forbidden_for_store_Admin() {
try {
tester.setStoreAdminUser();
SKU sku = new SKU("Test", "");
sku.setOwner("test@test.org");
tester.test_delete(sku);
fail("should have throw an exception");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Categories method findPresentationsLocales.
@GET
@Path("/{categoryId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("categoryId") @NotNull Long categoryId) {
Category category = entityManager.find(Category.class, categoryId);
checkNotNull(category);
if (!isAdminUser(securityContext) && !isOwner(securityContext, category.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
return category.getPresentationByLocale().keySet();
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Discounts method delete.
@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{discountId}")
public void delete(@Context SecurityContext securityContext, @PathParam("discountId") Long discountId) {
Discount discount = entityManager.find(Discount.class, discountId);
checkNotNull(discount);
if (isAdminUser(securityContext) || isOwner(securityContext, discount.getOwner())) {
List<Product> productHolders = catalogItemFinder.findForeignHolder(QProduct.product, QProduct.product.discounts, discount);
for (Product product : productHolders) {
product.getDiscounts().remove(discount);
}
List<SKU> skuHolders = catalogItemFinder.findForeignHolder(QSKU.sKU, QSKU.sKU.discounts, discount);
for (SKU sku : skuHolders) {
sku.getDiscounts().remove(discount);
}
entityManager.remove(discount);
} else
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
Aggregations