Пример #1
0
  public Result approve(Long key) {
    if (log.isDebugEnabled()) log.debug("approve <- " + key);

    Post post = postDAO.get(key);
    if (log.isDebugEnabled()) log.debug("post : " + post);
    if (post == null) return notFound();

    ContentStatus status = post.getStatus();
    if (status == NEW || status == UPDATED) {
      User user = HttpUtils.loginUser(ctx());
      post.setStatus(APPROVED);
      post.setApprovedBy(user);
      post.setApprovedOn(new Date());
      postDAO.update(post);

      List<ContentReport> reports = contentReportDAO.findForContent(ContentType.POST, key);
      for (ContentReport report : reports) {
        if (report.getStatus() == ContentReport.Status.NEW) {
          report.setStatus(ContentReport.Status.IGNORED);
          report.setUpdatedBy(user);
          contentReportDAO.update(report);
        }
      }
      return ok(toJson(ImmutableMap.of("status", "ok", "key", key)));
    } else {
      return badRequest(
          toJson(
              ImmutableMap.of(
                  "status", "error", "message", "wrong status", "status", status.name())));
    }
  }
Пример #2
0
 public void initialize(Application app) {
   if (log.isDebugEnabled()) log.debug("initialize <-");
   KeyConverterRegistry converters = new ClasspathScanningKeyConverterRegistry(app);
   ModelRegistry models = new ClasspathScanningModelRegistry(app, converters);
   CrudControllerRegistry crudControllers =
       new ClasspathScanningControllerRegistry(app, global, models);
   restController = new DynamicRestController(crudControllers, models);
 }
Пример #3
0
 public Result delete(String name, String key) {
   if (log.isDebugEnabled()) log.debug("delete <- " + name + ", " + key);
   F.Either<ControllerProxy, ? extends Result> cnf = controllerOrNotFound(name);
   if (cnf.right.isDefined()) return cnf.right.get();
   ControllerProxy controller = cnf.left.get();
   if (controller == null) {
     return controllerNotFound(name);
   }
   return controller.delete(key);
 }
Пример #4
0
  public Result list(String name) {
    if (log.isDebugEnabled()) log.debug("list <-");

    F.Either<ControllerProxy, ? extends Result> cnf = controllerOrNotFound(name);
    if (cnf.right.isDefined()) return cnf.right.get();
    ControllerProxy controller = cnf.left.get();
    if (controller == null) {
      return controllerNotFound(name);
    }
    return controller.list();
  }
  private boolean isAllowed(Context ctx, DeadboltHandler deadboltHandler) {
    if (log.isDebugEnabled()) log.debug("isAllowed() <-");

    Subject roleHolder = getSubject(ctx, deadboltHandler);

    boolean roleOk = false;
    if (roleHolder != null) {
      roleOk = checkRole(roleHolder, configuration.roles());
    }

    if (!roleOk) {
      roleOk = checkPermission(roleHolder, configuration.with(), ctx);
    }

    return roleOk;
  }
Пример #6
0
 public F.Promise<Result> call(Http.Context ctx) throws Throwable {
   final Request request = ctx.request();
   guiLogger.info(
       request.method()
           + " "
           + request.uri()
           + " ("
           + Controller.session(Users.SESSION_EMAIL)
           + ")");
   return delegate.call(ctx);
 }
Пример #7
0
  public Result remove(Long key) {
    if (log.isDebugEnabled()) log.debug("remove <- " + key);

    Post post = postDAO.get(key);
    if (log.isDebugEnabled()) log.debug("post : " + post);
    if (post == null) return notFound();

    User user = HttpUtils.loginUser(ctx());
    post.setStatus(REMOVED);
    post.setUpdatedBy(user);
    postDAO.update(post);

    List<ContentReport> reports = contentReportDAO.findForContent(ContentType.POST, key);
    for (ContentReport report : reports) {
      if (report.getStatus() == ContentReport.Status.NEW) {
        report.setStatus(ContentReport.Status.PROCESSED);
        report.setUpdatedBy(user);
        contentReportDAO.update(report);
      }
    }
    return ok(toJson(ImmutableMap.of("status", "ok", "key", key)));
  }
  private boolean checkPermission(
      Subject roleHolder, Class<? extends RequestPermission> permissionClass, Context ctx) {
    if (log.isDebugEnabled()) log.debug("checkPermission() <-");

    RequestPermission permission = null;
    try {
      permission = permissionClass.newInstance();
    } catch (Exception e) {
      log.error("cannot create permission", e);
      return false;
    }

    List<? extends Permission> permissions = roleHolder.getPermissions();

    Request request = ctx.request();
    if (log.isDebugEnabled()) log.debug("request : " + request);
    String path = request.path();
    if (log.isDebugEnabled()) log.debug("path : " + path);
    return permission.isAllowed(request, permissions);
  }