Search in sources :

Example 1 with FlagShare

use of fi.otavanopisto.muikku.model.users.FlagShare in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method deleteFlagShares.

@DELETE
@Path("/flags/share/{FLAGID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteFlagShares(@PathParam("FLAGID") Long flagId) {
    Flag flag = flagController.findFlagById(flagId);
    List<FlagShare> listShares = flagController.listShares(flag);
    for (FlagShare flagShare : listShares) {
        flagController.deleteFlagShare(flagShare);
    }
    return Response.noContent().build();
}
Also used : FlagShare(fi.otavanopisto.muikku.model.users.FlagShare) Flag(fi.otavanopisto.muikku.model.users.Flag) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 2 with FlagShare

use of fi.otavanopisto.muikku.model.users.FlagShare in project muikku by otavanopisto.

the class FlagShareDAO method listFlagsByUserIdentifier.

public List<Flag> listFlagsByUserIdentifier(UserSchoolDataIdentifier userIdentifier) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Flag> criteria = criteriaBuilder.createQuery(Flag.class);
    Root<FlagShare> root = criteria.from(FlagShare.class);
    criteria.select(root.get(FlagShare_.flag));
    criteria.where(criteriaBuilder.equal(root.get(FlagShare_.userIdentifier), userIdentifier));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) FlagShare(fi.otavanopisto.muikku.model.users.FlagShare) Flag(fi.otavanopisto.muikku.model.users.Flag)

Example 3 with FlagShare

use of fi.otavanopisto.muikku.model.users.FlagShare in project muikku by otavanopisto.

the class FlagController method unshareFlag.

public void unshareFlag(Flag flag, UserSchoolDataIdentifier userIdentifier) {
    FlagShare flagShare = flagShareDAO.findByFlagAndUserIdentifier(flag, userIdentifier);
    flagShareDAO.delete(flagShare);
}
Also used : FlagShare(fi.otavanopisto.muikku.model.users.FlagShare)

Example 4 with FlagShare

use of fi.otavanopisto.muikku.model.users.FlagShare in project muikku by otavanopisto.

the class FlagController method hasFlagPermission.

public boolean hasFlagPermission(Flag flag, SchoolDataIdentifier userIdentifier) {
    UserSchoolDataIdentifier owner = flag.getOwnerIdentifier();
    SchoolDataIdentifier ownerIdentfier = toIdentifier(owner);
    if (ownerIdentfier.equals(userIdentifier)) {
        return true;
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find school data user by identifier %s", userIdentifier));
        return false;
    }
    FlagShare flagShare = flagShareDAO.findByFlagAndUserIdentifier(flag, userSchoolDataIdentifier);
    if (flagShare != null) {
        return true;
    }
    return false;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) FlagShare(fi.otavanopisto.muikku.model.users.FlagShare)

Example 5 with FlagShare

use of fi.otavanopisto.muikku.model.users.FlagShare in project muikku by otavanopisto.

the class UserRESTService method createFlagShare.

@DELETE
@Path("/flags/{FLAGID}/shares/{ID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createFlagShare(@PathParam("FLAGID") Long flagId, @PathParam("ID") Long id) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    Flag flag = flagController.findFlagById(flagId);
    if (flag == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Flag#%d not found", id)).build();
    }
    if (flag.getArchived()) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Flag#%d not found", id)).build();
    }
    if (!flagController.hasFlagPermission(flag, sessionController.getLoggedUser())) {
        return Response.status(Status.FORBIDDEN).entity(String.format("You do not have permission to flag#%d", flag.getId())).build();
    }
    FlagShare flagShare = flagController.findFlagShare(id);
    if (flagShare == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Could not find flag share %d", id)).build();
    }
    flagController.deleteFlagShare(flagShare);
    return Response.noContent().build();
}
Also used : FlagShare(fi.otavanopisto.muikku.model.users.FlagShare) Flag(fi.otavanopisto.muikku.model.users.Flag) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Aggregations

FlagShare (fi.otavanopisto.muikku.model.users.FlagShare)9 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Flag (fi.otavanopisto.muikku.model.users.Flag)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 DELETE (javax.ws.rs.DELETE)2 Path (javax.ws.rs.Path)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1