Beispiel #1
0
 /**
  * Unblock a {@link User}.
  *
  * @param username the username of the {@link User} to be unblocked.
  */
 public static void unblockUser(String username) {
   User user = Database.users().get(username);
   User mod = Session.user();
   if (mod.isModerator() && mod != user) {
     user.unblock();
     flash.success("secure.unlockuserflash");
   }
   Application.showprofile(user.getName());
 }
Beispiel #2
0
 /** Clear the entire database except for the administrator users. */
 public static void clearDB() {
   if (!Session.user().isModerator()) {
     flash.error("secure.cleardberror");
     Application.index(0);
   }
   Database.clearKeepAdmins();
   flash.success("secure.cleardbflash");
   Application.admin();
 }
Beispiel #3
0
  /** Clear new notifications. Notifications will no longer appear as new. */
  public static void clearNewNotifications() {
    User user = Session.user();
    for (Notification n : user.getNewNotifications()) {
      n.unsetNew();
    }
    flash.success("secure.notificationsmarkedasreadflash");

    if (!redirectToCallingPage()) {
      Application.index(0);
    }
  }
Beispiel #4
0
 /**
  * Deletes the {@link User} and all it's {@link Question}' {@link Answer}'s {@link Vote}'s.
  *
  * <p>Instead of deleting all {@link Entry}'s of a {@link User}, these entries can optionally be
  * kept in anonymized form by setting their owners to <code>null</code> first.
  *
  * @param anonymize whether to anonymize or just plain delete the user's entries
  * @throws Throwable
  */
 public static void deleteUser(boolean anonymize) throws Throwable {
   User user = Session.user();
   if (anonymize) {
     user.anonymize(true);
   } else {
     Cache.delete("index.questions");
   }
   user.delete();
   flash.success("secure.userdeletedflash");
   Secure.logout();
   Application.index(0);
 }
Beispiel #5
0
 /**
  * Block a {@link User}.
  *
  * @param username the username of the {@link User} to be unblocked.
  * @param reason the reason the {@link User} is being blocked.
  */
 public static void blockUser(String username, String reason) {
   User user = Database.users().get(username);
   User mod = Session.user();
   if (mod.isModerator() && mod != user) {
     if (reason.equals("")) {
       reason = "secure.blockreasonerror";
     }
     user.block(reason);
     flash.success("secure.blockuserflash");
   }
   Application.showprofile(user.getName());
 }
Beispiel #6
0
  /**
   * Delete a notification.
   *
   * @param id the id of the notification to be deleted.
   */
  public static void deleteNotification(int id) {
    User user = Session.user();
    Notification n = user.getNotification(id);
    if (n != null) {
      n.delete();
      flash.success("secure.deletenotificationflash");
    }

    if (!redirectToCallingPage()) {
      Application.index(0);
    }
  }
Beispiel #7
0
  /**
   * Load an XML database file
   *
   * @param xml the XML database file to be loaded. This field is mandatory.
   */
  public static void loadXML(@Required File xml) {
    if (!Session.user().isModerator()) {
      Application.index(0);
    }
    if (xml == null) {
      flash.error("secure.xmlselecterror");
      Application.admin();
    }

    try {
      Database.importXML(xml);
      flash.success("secure.xmlloadflash");
    } catch (Throwable e) {
      flash.error("secure.xmlloaderror", e.getMessage());
      e.printStackTrace();
      Application.admin();
    }
    if (xml != null) {
      xml.delete();
    }
    Application.index(0);
  }
Beispiel #8
0
  /**
   * Follow notification.
   *
   * @param id the id of the notification.
   */
  public static void followNotification(int id) {
    User user = Session.user();
    Notification notification = user.getNotification(id);
    if (notification != null) {
      notification.unsetNew();
      Entry about = notification.getAbout();

      if (about instanceof Answer) {
        ActionDefinition action = reverse();
        Answer answer = (Answer) about;
        Application.question(answer.getQuestion().id());
        redirect(action.addRef("answer-" + answer.id()).toString());
      } else if (about instanceof Question) {
        Application.question(((Question) about).id());
      } else if (about instanceof Comment) {
        ActionDefinition action = reverse();
        Comment comment = (Comment) about;
        Application.question(comment.getQuestion().id());
        redirect(action.addRef("comment-" + comment.id()).toString());
      }
    } else if (!redirectToCallingPage()) {
      Application.notifications(0);
    }
  }