Search in sources :

Example 41 with WebApplicationException

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);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Store(org.rembx.jeeshop.catalog.model.Store) Test(org.junit.jupiter.api.Test)

Example 42 with WebApplicationException

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);
    }
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 43 with WebApplicationException

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);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) SKU(org.rembx.jeeshop.catalog.model.SKU) Test(org.junit.jupiter.api.Test)

Example 44 with WebApplicationException

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();
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 45 with WebApplicationException

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);
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Aggregations

WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)55 Test (org.junit.jupiter.api.Test)34 RolesAllowed (javax.annotation.security.RolesAllowed)19 Transactional (javax.transaction.Transactional)9 Catalog (org.rembx.jeeshop.catalog.model.Catalog)9 User (org.rembx.jeeshop.user.model.User)9 Store (org.rembx.jeeshop.catalog.model.Store)7 TestUser (org.rembx.jeeshop.user.test.TestUser)7 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)5 Category (org.rembx.jeeshop.catalog.model.Category)4 SKU (org.rembx.jeeshop.catalog.model.SKU)4 TestCatalog (org.rembx.jeeshop.catalog.test.TestCatalog)4 Order (org.rembx.jeeshop.order.model.Order)4 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)3 Product (org.rembx.jeeshop.catalog.model.Product)3 Address (org.rembx.jeeshop.user.model.Address)3 TestMailTemplate (org.rembx.jeeshop.user.test.TestMailTemplate)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PermitAll (javax.annotation.security.PermitAll)2