Skip to content

Commit

Permalink
do not allow archiving on taxonomy tables
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed May 16, 2024
1 parent ab655b9 commit a5923a9
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.campudus.tableaux.controller

import com.campudus.tableaux.{TableauxConfig, UnprocessableEntityException}
import com.campudus.tableaux.ArgumentChecker._
import com.campudus.tableaux.ForbiddenException
import com.campudus.tableaux.cache.CacheClient
import com.campudus.tableaux.database.{LanguageNeutral, LocationType}
import com.campudus.tableaux.database.domain._
Expand Down Expand Up @@ -273,6 +274,12 @@ class TableauxController(
} yield row
}

private def checkForTaxonomyTable(table: Table, archivedFlagOpt: Option[Boolean]): Unit = {
if (table.tableType == TaxonomyTable && archivedFlagOpt.isDefined) {
throw ForbiddenException(s"Archived flag is not allowed on taxonomy tables (table: ${table.id})", "archive")
}
}

def updateRowAnnotations(
tableId: TableId,
rowId: RowId,
Expand All @@ -286,6 +293,7 @@ class TableauxController(
for {
table <- repository.retrieveTable(tableId)
_ <- roleModel.checkAuthorization(EditRowAnnotation, ComparisonObjects(table))
_ = checkForTaxonomyTable(table, archivedFlagOpt)
updatedRow <- repository.updateRowAnnotations(table, rowId, finalFlagOpt, archivedFlagOpt)
} yield updatedRow
}
Expand All @@ -298,6 +306,7 @@ class TableauxController(
for {
table <- repository.retrieveTable(tableId)
_ <- roleModel.checkAuthorization(EditRowAnnotation, ComparisonObjects(table))
_ = checkForTaxonomyTable(table, archivedFlagOpt)
_ <- repository.updateRowsAnnotations(table, finalFlagOpt, archivedFlagOpt)
} yield EmptyObject()
}
Expand Down

0 comments on commit a5923a9

Please sign in to comment.