<commit_before>package controllers

import scala.None
import models.{RepositoryAccess, UserDAO, User}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Writes
import models.auth.UserCache
import play.api.libs.json.Json
import braingames.mvc.Filter
import braingames.util.DefaultConverters._

/**
 * Company: scalableminds
 * User: tmbo
 * Date: 18.08.13
 * Time: 16:43
 */
object UserController extends Controller {
  val DefaultAccessRole = None

  def list = Authenticated.async {
    implicit request =>
      for {
        users <- UserDAO.findAll
      } yield {
        Ok(Writes.list(User.publicUserWrites).writes(users))
      }
  }

  def read(id: Int) = Authenticated.async {
    implicit request =>
      for {
        user <- UserDAO.findOneByUserId(id)
      } yield {
        Ok(User.publicUserWrites.writes(user))
      }
  }

  def showSettings() = Authenticated {
    implicit request =>
      Ok(views.html.user.settings(request.user.asInstanceOf[User]))
  }

  def listRepositories = Authenticated{ implicit request =>
    UsingFilters[RepositoryAccess](
      Filter("isAdmin", (isAdmin: Boolean, repoAccess) => repoAccess == isAdmin)
    ){ filter =>
      Ok(Json.toJson(filter.applyOn(request.user.repositories)))
    }
  }

  def createAccessKey() = Authenticated.async {
    implicit request =>
      val a = User.generateAccessKey
      val user = request.user
      for {<commit_msg>fixed isAdmin check on repositories<commit_after>package controllers

import scala.None
import models.{RepositoryAccess, UserDAO, User}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Writes
import models.auth.UserCache
import play.api.libs.json.Json
import braingames.mvc.Filter
import braingames.util.DefaultConverters._

/**
 * Company: scalableminds
 * User: tmbo
 * Date: 18.08.13
 * Time: 16:43
 */
object UserController extends Controller {
  val DefaultAccessRole = None

  def list = Authenticated.async {
    implicit request =>
      for {
        users <- UserDAO.findAll
      } yield {
        Ok(Writes.list(User.publicUserWrites).writes(users))
      }
  }

  def read(id: Int) = Authenticated.async {
    implicit request =>
      for {
        user <- UserDAO.findOneByUserId(id)
      } yield {
        Ok(User.publicUserWrites.writes(user))
      }
  }

  def showSettings() = Authenticated {
    implicit request =>
      Ok(views.html.user.settings(request.user.asInstanceOf[User]))
  }

  def listRepositories = Authenticated{ implicit request =>
    UsingFilters[RepositoryAccess](
      Filter("isAdmin", (isAdmin: Boolean, repoAccess) => repoAccess.isAdmin == isAdmin)
    ){ filter =>
      Ok(Json.toJson(filter.applyOn(request.user.repositories)))
    }
  }

  def createAccessKey() = Authenticated.async {
    implicit request =>
      val a = User.generateAccessKey
      val user = request.user
      for {
{'fraction_non_alphanumeric': 0.11030927835051546, 'fraction_numerical': 0.006872852233676976, 'mean_word_length': 3.182471264367816, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1348822', 'n_tokens_mistral': 931, 'n_tokens_neox': 900, 'n_words': 180}