<commit_before>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.util;

import foam.core.X;
import foam.dao.DAO;
import foam.nanos.auth.User;
import foam.nanos.session.Session;

import static foam.mlang.MLang.AND;
import static foam.mlang.MLang.EQ;

public class Auth {

  public static X sudo(X x, Object id) {
    return sudo(x, (User) ((DAO) x.get("userDAO")).inX(x).find(id));
  }

  public static X sudo(X x, String email) {
    return sudo(x, (User) ((DAO) x.get("userDAO")).inX(x).find(AND(
      EQ(User.EMAIL, email),
      EQ(User.LOGIN_ENABLED, true)
    )));
  }

  public static X sudo(X x, User user) {
    if ( user == null ) throw new RuntimeException("Unknown user");

    Session session = new Session();
    x = x.put(Session.class, session);
    x = x.put("user", user);
    x = x.put("group", ((DAO) x.get("groupDAO")).inX(x).find(user.getGroup()));
    session.setUserId(user.getId());
    session.setContext(x);

    return x;
  }
}<commit_msg>Fix failing tests<commit_after>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.util;

import foam.core.X;
import foam.dao.DAO;
import foam.nanos.auth.User;
import foam.nanos.session.Session;

import static foam.mlang.MLang.AND;
import static foam.mlang.MLang.EQ;

public class Auth {

  public static X sudo(X x, Object id) {
    return sudo(x, (User) ((DAO) x.get("userDAO")).inX(x).find(id));
  }

  public static X sudo(X x, String email) {
    return sudo(x, (User) ((DAO) x.get("userDAO")).inX(x).find(AND(
      EQ(User.EMAIL, email),
      EQ(User.LOGIN_ENABLED, true)
    )));
  }

  public static X sudo(X x, User user) {
    if ( user == null ) throw new RuntimeException("Unknown user");

    Session session = new Session();
    x = x.put(Session.class, session);
    x = x.put("user", user);
    x = x.put("group", ((DAO) x.get("localGroupDAO")).inX(x).find(user.getGroup()));
    session.setUserId(user.getId());
    session.setContext(x);

    return x;
  }
}
{'fraction_non_alphanumeric': 0.17288615965989607, 'fraction_numerical': 0.005668398677373642, 'mean_word_length': 3.421711899791232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '203311', 'n_tokens_mistral': 794, 'n_tokens_neox': 770, 'n_words': 182}