Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/AnnotationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class AnnotationController @Inject()(
def annotationsForTask(@ApiParam(value = "The id of the task") taskId: String): Action[AnyContent] =
sil.SecuredAction.async { implicit request =>
for {
taskIdValidated <- ObjectId.parse(taskId)
taskIdValidated <- ObjectId.fromString(taskId)
task <- taskDAO.findOne(taskIdValidated) ?~> "task.notFound" ~> NOT_FOUND
project <- projectDAO.findOne(task._project)
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team))
Expand Down Expand Up @@ -446,7 +446,7 @@ class AnnotationController @Inject()(
restrictions <- provider.restrictionsFor(typ, id) ?~> "restrictions.notFound" ~> NOT_FOUND
_ <- restrictions.allowFinish(request.identity) ?~> "notAllowed" ~> FORBIDDEN
newUserId <- (request.body \ "userId").asOpt[String].toFox ?~> "user.id.notFound" ~> NOT_FOUND
newUserIdValidated <- ObjectId.parse(newUserId)
newUserIdValidated <- ObjectId.fromString(newUserId)
updated <- annotationService.transferAnnotationToUser(typ, id, newUserIdValidated, request.identity)
json <- annotationService.publicWrites(updated, Some(request.identity), Some(restrictions))
} yield JsonOk(json)
Expand Down Expand Up @@ -515,7 +515,7 @@ class AnnotationController @Inject()(
annotation <- provider.provideAnnotation(typ, id, request.identity)
_ <- bool2Fox(
annotation._user == request.identity._id && annotation.visibility != AnnotationVisibility.Private) ?~> "notAllowed" ~> FORBIDDEN
teamIdsValidated <- Fox.serialCombined(teams)(ObjectId.parse)
teamIdsValidated <- Fox.serialCombined(teams)(ObjectId.fromString)
_ <- Fox.serialCombined(teamIdsValidated)(teamDAO.findOne(_)) ?~> "updateSharedTeams.failed.accessingTeam"
_ <- annotationService.updateTeamsForSharedAnnotation(annotation._id, teamIdsValidated)
} yield Ok(Json.toJson(teamIdsValidated))
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/AnnotationIOController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Expects:
m: MessagesProvider) =
for {
user <- userOpt.toFox ?~> Messages("notAllowed") ~> FORBIDDEN
projectIdValidated <- ObjectId.parse(projectId)
projectIdValidated <- ObjectId.fromString(projectId)
project <- projectDAO.findOne(projectIdValidated) ?~> Messages("project.notFound", projectId) ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(user, project._team)) ?~> "notAllowed" ~> FORBIDDEN
annotations <- annotationDAO.findAllFinishedForProject(projectIdValidated)
Expand Down Expand Up @@ -500,7 +500,7 @@ Expects:

for {
user <- userOpt.toFox ?~> Messages("notAllowed") ~> FORBIDDEN
taskTypeIdValidated <- ObjectId.parse(taskTypeId) ?~> "taskType.id.invalid"
taskTypeIdValidated <- ObjectId.fromString(taskTypeId) ?~> "taskType.id.invalid"
taskType <- taskTypeDAO.findOne(taskTypeIdValidated) ?~> "taskType.notFound" ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(user, taskType._team)) ?~> "notAllowed" ~> FORBIDDEN
zip <- createTaskTypeZip(taskType)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/AuthenticationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class AuthenticationController @Inject()(
} yield organization
case (None, None, Some(annotationId)) =>
for {
annotationObjectId <- ObjectId.parse(annotationId)
annotationObjectId <- ObjectId.fromString(annotationId)
annotation <- annotationDAO.findOne(annotationObjectId) // Note: this does not work for compound annotations.
user <- userDAO.findOne(annotation._user)
organization <- organizationDAO.findOne(user._organization)
Expand Down Expand Up @@ -268,7 +268,7 @@ class AuthenticationController @Inject()(

private def canAccessAnnotation(user: User, ctx: DBAccessContext, annotationId: String): Fox[Boolean] = {
val foundFox = for {
annotationIdParsed <- ObjectId.parse(annotationId)
annotationIdParsed <- ObjectId.fromString(annotationId)
annotation <- annotationDAO.findOne(annotationIdParsed)(GlobalAccessContext)
_ <- bool2Fox(annotation.state != Cancelled)
restrictions <- annotationProvider.restrictionsFor(AnnotationIdentifier(annotation.typ, annotationIdParsed))(ctx)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/DataSetController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Expects:
dataSet <- dataSetDAO.findOneByNameAndOrganization(dataSetName, request.identity._organization) ?~> notFoundMessage(
dataSetName) ~> NOT_FOUND
_ <- Fox.assertTrue(dataSetService.isEditableBy(dataSet, Some(request.identity))) ?~> "notAllowed" ~> FORBIDDEN
teamIdsValidated <- Fox.serialCombined(teams)(ObjectId.parse(_))
teamIdsValidated <- Fox.serialCombined(teams)(ObjectId.fromString(_))
includeMemberOnlyTeams = request.identity.isDatasetManager
userTeams <- if (includeMemberOnlyTeams) teamDAO.findAll else teamDAO.findAllEditable
oldAllowedTeams <- dataSetService.allowedTeamIdsFor(dataSet._id)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/JobsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class JobsController @Inject()(jobDAO: JobDAO,
def cancel(id: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
_ <- bool2Fox(wkconf.Features.jobsEnabled) ?~> "job.disabled"
jobIdValidated <- ObjectId.parse(id)
jobIdValidated <- ObjectId.fromString(id)
job <- jobDAO.findOne(jobIdValidated)
_ <- jobDAO.updateManualState(jobIdValidated, JobState.CANCELLED)
js <- jobService.publicWrites(job)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/LegacyApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ class LegacyApiController @Inject()(annotationController: AnnotationController,
def taskListTasks: Action[JsValue] = sil.SecuredAction.async(parse.json) { implicit request =>
for {
_ <- Fox.successful(logVersioned(request))
userIdOpt <- Fox.runOptional((request.body \ "user").asOpt[String])(ObjectId.parse)
userIdOpt <- Fox.runOptional((request.body \ "user").asOpt[String])(ObjectId.fromString)
projectNameOpt = (request.body \ "project").asOpt[String]
projectOpt <- Fox.runOptional(projectNameOpt)(projectName =>
projectDAO.findOneByNameAndOrganization(projectName, request.identity._organization))
taskIdsOpt <- Fox.runOptional((request.body \ "ids").asOpt[List[String]])(ids =>
Fox.serialCombined(ids)(ObjectId.parse))
taskTypeIdOpt <- Fox.runOptional((request.body \ "taskType").asOpt[String])(ObjectId.parse)
Fox.serialCombined(ids)(ObjectId.fromString))
taskTypeIdOpt <- Fox.runOptional((request.body \ "taskType").asOpt[String])(ObjectId.fromString)
randomizeOpt = (request.body \ "random").asOpt[Boolean]
tasks <- taskDAO.findAllByProjectAndTaskTypeAndIdsAndUser(projectOpt.map(_._id),
taskTypeIdOpt,
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/MeshController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MeshController @Inject()(meshDAO: MeshDAO,

def get(id: String): Action[AnyContent] = sil.UserAwareAction.async { implicit request =>
for {
idValidated <- ObjectId.parse(id)
idValidated <- ObjectId.fromString(id)
meshInfo <- meshDAO.findOne(idValidated) ?~> "mesh.notFound" ~> NOT_FOUND
_ <- annotationDAO.findOne(meshInfo._annotation) ?~> "annotation.notFound" ~> NOT_FOUND
meshInfoJs <- meshService.publicWrites(meshInfo) ?~> "mesh.write.failed"
Expand All @@ -44,7 +44,7 @@ class MeshController @Inject()(meshDAO: MeshDAO,
implicit request =>
val params = request.body
for {
idValidated <- ObjectId.parse(id)
idValidated <- ObjectId.fromString(id)
meshInfo <- meshDAO.findOne(idValidated) ?~> "mesh.notFound" ~> NOT_FOUND
_ <- annotationDAO.assertUpdateAccess(meshInfo._annotation) ?~> "notAllowed" ~> FORBIDDEN
_ <- annotationDAO.assertUpdateAccess(params.annotationId) ?~> "notAllowed" ~> FORBIDDEN
Expand All @@ -57,7 +57,7 @@ class MeshController @Inject()(meshDAO: MeshDAO,

def getData(id: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
idValidated <- ObjectId.parse(id)
idValidated <- ObjectId.fromString(id)
meshInfo <- meshDAO.findOne(idValidated) ?~> "mesh.notFound" ~> NOT_FOUND
_ <- annotationDAO.findOne(meshInfo._annotation) ?~> "annotation.notFound" ~> NOT_FOUND
data <- meshDAO.getData(idValidated) ?~> "mesh.data.get.failed"
Expand All @@ -66,7 +66,7 @@ class MeshController @Inject()(meshDAO: MeshDAO,

def updateData(id: String): Action[RawBuffer] = sil.SecuredAction.async(parse.raw) { implicit request =>
for {
idValidated <- ObjectId.parse(id)
idValidated <- ObjectId.fromString(id)
meshInfo <- meshDAO.findOne(idValidated) ?~> "mesh.notFound" ~> NOT_FOUND
_ <- annotationDAO.assertUpdateAccess(meshInfo._annotation) ?~> "notAllowed" ~> FORBIDDEN
byteString <- request.body.asBytes(maxLength = 1024 * 1024 * 1024) ?~> "mesh.data.read.failed"
Expand All @@ -76,7 +76,7 @@ class MeshController @Inject()(meshDAO: MeshDAO,

def delete(id: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
idValidated <- ObjectId.parse(id)
idValidated <- ObjectId.fromString(id)
meshInfo <- meshDAO.findOne(idValidated) ?~> "mesh.notFound" ~> NOT_FOUND
_ <- annotationDAO.assertUpdateAccess(meshInfo._annotation) ?~> "notAllowed" ~> FORBIDDEN
_ <- meshDAO.deleteOne(idValidated) ?~> "mesh.delete.failed"
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/ProjectController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ProjectController @Inject()(projectService: ProjectService,
def read(@ApiParam(value = "The id of the project") id: String): Action[AnyContent] = sil.SecuredAction.async {
implicit request =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
js <- projectService.publicWrites(project)
} yield Ok(js)
Expand All @@ -81,7 +81,7 @@ class ProjectController @Inject()(projectService: ProjectService,
@ApiOperation(hidden = true, value = "")
def delete(id: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
_ <- bool2Fox(project.isDeletableBy(request.identity)) ?~> "project.remove.notAllowed" ~> FORBIDDEN
_ <- projectService.deleteOne(project._id) ?~> "project.remove.failure"
Expand Down Expand Up @@ -127,7 +127,7 @@ Expects:
def update(id: String): Action[JsValue] = sil.SecuredAction.async(parse.json) { implicit request =>
withJsonBodyUsing(Project.projectPublicReads) { updateRequest =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated)(GlobalAccessContext) ?~> "project.notFound" ~> NOT_FOUND
_ <- Fox
.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team)) ?~> "notAllowed" ~> FORBIDDEN
Expand All @@ -152,7 +152,7 @@ Expects:
@ApiOperation(hidden = true, value = "")
private def updatePauseStatus(id: String, isPaused: Boolean)(implicit request: SecuredRequest[WkEnv, _]) =
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team)) ?~> "notAllowed" ~> FORBIDDEN
_ <- projectDAO.updatePaused(project._id, isPaused) ?~> "project.update.failed"
Expand All @@ -163,7 +163,7 @@ Expects:
@ApiOperation(hidden = true, value = "")
def projectsForTaskType(taskTypeId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
taskTypeIdValidated <- ObjectId.parse(taskTypeId)
taskTypeIdValidated <- ObjectId.fromString(taskTypeId)
_ <- taskTypeDAO.findOne(taskTypeIdValidated) ?~> "taskType.notFound" ~> NOT_FOUND
projects <- projectDAO.findAllWithTaskType(taskTypeId) ?~> "project.list.failed"
allCounts <- taskDAO.countOpenInstancesAndTimeByProject
Expand Down Expand Up @@ -194,7 +194,7 @@ Expects:
Boolean]): Action[AnyContent] =
sil.SecuredAction.async { implicit request =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team)) ?~> "notAllowed" ~> FORBIDDEN
tasks <- taskDAO.findAllByProject(project._id, limit.getOrElse(Int.MaxValue), pageNumber.getOrElse(0))
Expand All @@ -215,7 +215,7 @@ Expects:
sil.SecuredAction.async { implicit request =>
for {
_ <- bool2Fox(delta.getOrElse(1L) >= 0) ?~> "project.increaseTaskInstances.negative"
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
_ <- taskDAO.incrementTotalInstancesOfAllWithProject(project._id, delta.getOrElse(1L))
openInstancesAndTime <- taskDAO.countOpenInstancesAndTimeForProject(project._id)
Expand All @@ -226,7 +226,7 @@ Expects:
@ApiOperation(hidden = true, value = "")
def usersWithActiveTasks(id: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
usersWithActiveTasks <- projectDAO.findUsersWithActiveTasks(project._id)
} yield {
Expand All @@ -238,12 +238,12 @@ Expects:
@ApiOperation(hidden = true, value = "")
def transferActiveTasks(id: String): Action[JsValue] = sil.SecuredAction.async(parse.json) { implicit request =>
for {
projectIdValidated <- ObjectId.parse(id)
projectIdValidated <- ObjectId.fromString(id)
project <- projectDAO.findOne(projectIdValidated) ?~> "project.notFound" ~> NOT_FOUND
_ <- Fox
.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team)) ?~> "notAllowed" ~> FORBIDDEN
newUserId <- (request.body \ "userId").asOpt[String].toFox ?~> "user.id.notFound" ~> NOT_FOUND
newUserIdValidated <- ObjectId.parse(newUserId)
newUserIdValidated <- ObjectId.fromString(newUserId)
activeAnnotations <- annotationDAO.findAllActiveForProject(project._id)
_ <- Fox.serialCombined(activeAnnotations) { id =>
annotationService.transferAnnotationToUser(AnnotationType.Task.toString,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/ReportController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class ReportController @Inject()(reportDAO: ReportDAO,

def projectProgressOverview(teamId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
teamIdValidated <- ObjectId.parse(teamId)
teamIdValidated <- ObjectId.fromString(teamId)
_ <- teamDAO.findOne(teamIdValidated) ?~> "team.notFound" ~> NOT_FOUND
entries <- reportDAO.projectProgress(teamIdValidated)
} yield Ok(Json.toJson(entries))
}

def openTasksOverview(teamId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
teamIdValidated <- ObjectId.parse(teamId)
teamIdValidated <- ObjectId.fromString(teamId)
team <- teamDAO.findOne(teamIdValidated) ?~> "team.notFound" ~> NOT_FOUND
users <- userDAO.findAllByTeams(List(team._id))
nonUnlistedUsers = users.filter(!_.isUnlisted)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/ScriptController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScriptController @Inject()(scriptDAO: ScriptDAO,

def get(scriptId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
scriptIdValidated <- ObjectId.parse(scriptId)
scriptIdValidated <- ObjectId.fromString(scriptId)
script <- scriptDAO.findOne(scriptIdValidated) ?~> "script.notFound" ~> NOT_FOUND
js <- scriptService.publicWrites(script) ?~> "script.write.failed"
} yield {
Expand All @@ -61,7 +61,7 @@ class ScriptController @Inject()(scriptDAO: ScriptDAO,
def update(scriptId: String): Action[JsValue] = sil.SecuredAction.async(parse.json) { implicit request =>
withJsonBodyUsing(scriptPublicReads) { scriptFromForm =>
for {
scriptIdValidated <- ObjectId.parse(scriptId)
scriptIdValidated <- ObjectId.fromString(scriptId)
oldScript <- scriptDAO.findOne(scriptIdValidated) ?~> "script.notFound" ~> NOT_FOUND
_ <- bool2Fox(oldScript._owner == request.identity._id) ?~> "script.notOwner" ~> FORBIDDEN
updatedScript = scriptFromForm.copy(_id = oldScript._id)
Expand All @@ -75,7 +75,7 @@ class ScriptController @Inject()(scriptDAO: ScriptDAO,

def delete(scriptId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
scriptIdValidated <- ObjectId.parse(scriptId)
scriptIdValidated <- ObjectId.fromString(scriptId)
oldScript <- scriptDAO.findOne(scriptIdValidated) ?~> "script.notFound" ~> NOT_FOUND
_ <- bool2Fox(oldScript._owner == request.identity._id) ?~> "script.notOwner" ~> FORBIDDEN
_ <- scriptDAO.deleteOne(scriptIdValidated) ?~> "script.removalFailed"
Expand Down
Loading