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();
}
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();
}
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);
}
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;
}
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();
}
Aggregations