<commit_before>package controllers


import javax.inject.Inject

import com.scalableminds.util.reactivemongo.GlobalAccessContext
import com.scalableminds.util.tools.DefaultConverters._
import models.team._
import models.user.UserService
import net.liftweb.common.{Empty, Full}
import oxalis.security.WebknossosSilhouette.SecuredAction
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Json
import play.api.mvc.Action

import scala.concurrent.Future

class TeamController @Inject()(val messagesApi: MessagesApi) extends Controller {


  def list = SecuredAction.async { implicit request =>
    UsingFilters(
      Filter("isEditable", (value: Boolean, el: Team) =>
        el.isEditableBy(request.identity) == value)
    ) { filter =>
      for {
        allTeams <- TeamDAO.findAll
        filteredTeams = filter.applyOn(allTeams)
        js <- Future.traverse(filteredTeams)(Team.teamPublicWrites(_))
      } yield {
        Ok(Json.toJson(js))
      }
    }
  }

  def listAllTeams = Action.async { implicit request =>
    for {
      allTeams <- TeamDAO.findAll(GlobalAccessContext)
      js <- Future.traverse(allTeams)(Team.teamPublicWrites(_)(GlobalAccessContext))
    } yield {
      Ok(Json.toJson(js))
    }
  }

  def delete(id: String) = SecuredAction.async { implicit request =>
    for {
      team <- TeamDAO.findOneById(id)
      _ <- TeamService.remove(team)
      _ <- UserService.removeTeamFromUsers(team)
    } yield {
      JsonOk(Messages("team.deleted"))
    }
  }

  def create = SecuredAction.async(parse.json) { implicit request =>
    withJsonBodyUsing(Team.teamReadsName) { teamName =>
      val team = Team(teamName, request.identity.organization)
      for {
        _ <- bool2Fox(request.identity.isAdmin) ?~> Messages("user.noAdmin")
        _ <- TeamService.create(team, request.identity)
        js <- Team.teamPublicWrites(team)<commit_msg>admins don't need to be teamManager<commit_after>package controllers


import javax.inject.Inject

import com.scalableminds.util.reactivemongo.GlobalAccessContext
import com.scalableminds.util.tools.DefaultConverters._
import models.team._
import models.user.UserService
import net.liftweb.common.{Empty, Full}
import oxalis.security.WebknossosSilhouette.SecuredAction
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Json
import play.api.mvc.Action

import scala.concurrent.Future

class TeamController @Inject()(val messagesApi: MessagesApi) extends Controller {


  def list = SecuredAction.async { implicit request =>
    UsingFilters(
      Filter("isEditable", (value: Boolean, el: Team) =>
        el.isEditableBy(request.identity) == value)
    ) { filter =>
      for {
        allTeams <- TeamDAO.findAll
        filteredTeams = filter.applyOn(allTeams)
        js <- Future.traverse(filteredTeams)(Team.teamPublicWrites(_))
      } yield {
        Ok(Json.toJson(js))
      }
    }
  }

  def listAllTeams = Action.async { implicit request =>
    for {
      allTeams <- TeamDAO.findAll(GlobalAccessContext)
      js <- Future.traverse(allTeams)(Team.teamPublicWrites(_)(GlobalAccessContext))
    } yield {
      Ok(Json.toJson(js))
    }
  }

  def delete(id: String) = SecuredAction.async { implicit request =>
    for {
      team <- TeamDAO.findOneById(id)
      _ <- TeamService.remove(team)
      _ <- UserService.removeTeamFromUsers(team)
    } yield {
      JsonOk(Messages("team.deleted"))
    }
  }

  def create = SecuredAction.async(parse.json) { implicit request =>
    withJsonBodyUsing(Team.teamReadsName) { teamName =>
      val team = Team(teamName, request.identity.organization)
      for {
        _ <- bool2Fox(request.identity.isAdmin) ?~> Messages("user.noAdmin")
        js <- Team.teamPublicWrites(team)
{'fraction_non_alphanumeric': 0.11490683229813664, 'fraction_numerical': 0.0015527950310559005, 'mean_word_length': 3.457900807381776, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 19, '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': '4721837', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1196, 'n_words': 204}