From 985e578a84aac7813dec3dff1424a4de4dfbf498 Mon Sep 17 00:00:00 2001 From: Manfred Zingl Date: Tue, 10 Oct 2023 16:23:32 +0200 Subject: [PATCH] revert test changes we don't need default action "viewRow" and "viewAuthorization" --- .../database/model/tableaux/RowModel.scala | 37 ++---------- .../api/auth/SystemControllerAuthTest.scala | 3 +- .../api/auth/TableauxControllerAuthTest.scala | 47 ++++++++-------- .../tableaux/api/content/IdentifierTest.scala | 1 - .../tableaux/api/content/LinkTest.scala | 56 +++++++++---------- .../api/content/RetrieveGroupColumnTest.scala | 3 +- .../api/content/RowLevelAnnotationsTest.scala | 1 - 7 files changed, 54 insertions(+), 94 deletions(-) diff --git a/src/main/scala/com/campudus/tableaux/database/model/tableaux/RowModel.scala b/src/main/scala/com/campudus/tableaux/database/model/tableaux/RowModel.scala index 561440ac..178c4cd5 100644 --- a/src/main/scala/com/campudus/tableaux/database/model/tableaux/RowModel.scala +++ b/src/main/scala/com/campudus/tableaux/database/model/tableaux/RowModel.scala @@ -1136,13 +1136,15 @@ class RetrieveRowModel(val connection: DatabaseConnection)( assert(row.size >= 3) val liftedRow = row.lift - (row.headOption, liftedRow(1), liftedRow(2), liftedRow(3)) match { + // Row should have at least = row_id, final_flag, cell_annotations, row_permissions + (liftedRow(0), liftedRow(1), liftedRow(2), liftedRow(3)) match { + // values in case statement are nullable even if they are wrapped in Some, see lift function of Seq case (Some(rowId: RowId), Some(finalFlag: Boolean), Some(cellAnnotationsStr), Some(permissionsStr)) => val cellAnnotations = Option(cellAnnotationsStr) .map(_.asInstanceOf[String]) .map(Json.fromArrayString) .getOrElse(Json.emptyArr()) - val rawValues = row.drop(3) + val rawValues = row.drop(4) val rowPermissions = Option(permissionsStr) match { case Some(permissionsArrayString: String) => new JsonArray(permissionsArrayString) @@ -1161,37 +1163,6 @@ class RetrieveRowModel(val connection: DatabaseConnection)( } } - // private def mapRowToRawRow2(columns: Seq[ColumnType[_]])(row: Seq[Any]): RawRow = { - - // val liftedRow = row.lift - - // // Row should have at least = row_id, final_flag, cell_annotations, row_permissions - // (liftedRow(0), liftedRow(1), liftedRow(2), liftedRow(3)) match { - // // values in case statement are nullable even if they are wrapped in Some, see lift function of Seq - // case (Some(rowId: RowId), Some(finalFlag: Boolean), Some(cellAnnotationsStr), Some(permissions)) => - // val cellAnnotations = Option(cellAnnotationsStr) - // .map(_.asInstanceOf[String]) - // .map(Json.fromArrayString) - // .getOrElse(Json.emptyArr()) - // val rowPermissions = Option(permissions) match { - // case Some(permissionsArrayString: String) => new JsonArray(permissionsArrayString) - // case _ => Json.arr() - // } - // // All row annotations, currently final and permissions - // val rowAnnotations = Seq(FinalFlag(finalFlag), RowPermissions(rowPermissions)) - // val rawValues = row.drop(4) - - // RawRow( - // rowId, - // rowAnnotations, - // CellLevelAnnotations(columns, cellAnnotations), - // (columns, rawValues).zipped.map(mapValueByColumnType) - // ) - // case _ => - // throw UnknownServerException(s"Please check generateProjection!") - // } - // } - def size(tableId: TableId): Future[Long] = { val select = s"SELECT COUNT(*) FROM user_table_$tableId" diff --git a/src/test/scala/com/campudus/tableaux/api/auth/SystemControllerAuthTest.scala b/src/test/scala/com/campudus/tableaux/api/auth/SystemControllerAuthTest.scala index 7b59e732..03b16244 100644 --- a/src/test/scala/com/campudus/tableaux/api/auth/SystemControllerAuthTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/auth/SystemControllerAuthTest.scala @@ -300,8 +300,7 @@ class SystemControllerAuthTest_checkAuthorization extends SystemControllerAuthTe | "viewColumn", | "viewCellValue", | "editCellValue", - | "viewTable", - | "viewRow" + | "viewTable" | ] | } | ] diff --git a/src/test/scala/com/campudus/tableaux/api/auth/TableauxControllerAuthTest.scala b/src/test/scala/com/campudus/tableaux/api/auth/TableauxControllerAuthTest.scala index 4452135e..0d9ec521 100644 --- a/src/test/scala/com/campudus/tableaux/api/auth/TableauxControllerAuthTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/auth/TableauxControllerAuthTest.scala @@ -6,7 +6,6 @@ import com.campudus.tableaux.api.media.MediaTestBase import com.campudus.tableaux.controller.{StructureController, TableauxController} import com.campudus.tableaux.database._ import com.campudus.tableaux.database.domain.{InfoAnnotationType, Pagination} -import com.campudus.tableaux.database.domain.FinalFlag import com.campudus.tableaux.database.model.{StructureModel, TableauxModel} import com.campudus.tableaux.database.model.TableauxModel.TableId import com.campudus.tableaux.helper.JsonUtils.{toCreateColumnSeq, toRowValueSeq} @@ -209,7 +208,7 @@ class TableauxControllerAuthTest_cell extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -245,7 +244,7 @@ class TableauxControllerAuthTest_cell extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -289,7 +288,7 @@ class TableauxControllerAuthTest_cell extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -322,7 +321,7 @@ class TableauxControllerAuthTest_cell extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -355,7 +354,7 @@ class TableauxControllerAuthTest_cell extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -501,7 +500,7 @@ class TableauxControllerAuthTest_row extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -541,7 +540,7 @@ class TableauxControllerAuthTest_row extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -862,7 +861,7 @@ class TableauxControllerAuthTest_row extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -923,7 +922,7 @@ class TableauxControllerAuthTest_row extends TableauxControllerAuthTest { | "view-rows": [ | { | "type": "grant", - | "action": ["viewTable", "viewColumn", "viewCellValue", "viewRow"] + | "action": ["viewTable", "viewColumn", "viewCellValue"] | } | ] |}""".stripMargin) @@ -1079,7 +1078,7 @@ class TableauxControllerAuthTest_history extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1115,7 +1114,7 @@ class TableauxControllerAuthTest_history extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1146,7 +1145,7 @@ class TableauxControllerAuthTest_history extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1194,7 +1193,7 @@ class TableauxControllerAuthTest_history extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1225,7 +1224,7 @@ class TableauxControllerAuthTest_history extends TableauxControllerAuthTest { | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1447,7 +1446,7 @@ class TableauxControllerAuthTest_annotation extends TableauxControllerAuthTest { for { _ <- createTestTable() - _ <- controller.updateRowAnnotations(1, 1, Seq(FinalFlag(true))) + _ <- controller.updateRowAnnotations(1, 1, Some(true)) } yield () } @@ -1467,7 +1466,7 @@ class TableauxControllerAuthTest_annotation extends TableauxControllerAuthTest { for { _ <- createTestTable() - ex <- controller.updateRowAnnotations(1, 1, Seq(FinalFlag(true))).recover({ case ex => ex }) + ex <- controller.updateRowAnnotations(1, 1, Some(true)).recover({ case ex => ex }) } yield { assertEquals(UnauthorizedException(EditRowAnnotation, Seq("view-cells")), ex) } @@ -1489,7 +1488,7 @@ class TableauxControllerAuthTest_annotation extends TableauxControllerAuthTest { for { _ <- createTestTable() - _ <- controller.updateRowsAnnotations(1, Seq(FinalFlag(true))) + _ <- controller.updateRowsAnnotations(1, Some(true)) } yield () } @@ -1513,7 +1512,7 @@ class TableauxControllerAuthTest_annotation extends TableauxControllerAuthTest { for { _ <- createTestTable() - ex <- controller.updateRowsAnnotations(1, Seq(FinalFlag(true))).recover({ case ex => ex }) + ex <- controller.updateRowsAnnotations(1, Some(true)).recover({ case ex => ex }) } yield { assertEquals(UnauthorizedException(EditRowAnnotation, Seq("view-cells")), ex) } @@ -1738,7 +1737,7 @@ class TableauxControllerAuthTest_linkCell extends LinkTestBase with TableauxCont | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1778,7 +1777,7 @@ class TableauxControllerAuthTest_linkCell extends LinkTestBase with TableauxCont | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1816,7 +1815,7 @@ class TableauxControllerAuthTest_linkCell extends LinkTestBase with TableauxCont | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) @@ -1856,7 +1855,7 @@ class TableauxControllerAuthTest_linkCell extends LinkTestBase with TableauxCont | "view-all-cells": [ | { | "type": "grant", - | "action": ["viewTable", "viewRow"], + | "action": ["viewTable"], | "condition": { | "table": { | "id": "2" @@ -2148,7 +2147,7 @@ class TableauxControllerAuthTest_completeTable extends TableauxControllerAuthTes | }, | { | "type": "grant", - | "action": ["viewTable", "viewRow"] + | "action": ["viewTable"] | } | ] |}""".stripMargin) diff --git a/src/test/scala/com/campudus/tableaux/api/content/IdentifierTest.scala b/src/test/scala/com/campudus/tableaux/api/content/IdentifierTest.scala index 0c2eed52..c2187b35 100644 --- a/src/test/scala/com/campudus/tableaux/api/content/IdentifierTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/content/IdentifierTest.scala @@ -312,7 +312,6 @@ class IdentifierTest extends TableauxTestBase { // single link into table 3 row 1 Json.obj( "id" -> rowIds3.head, - "viewAuthorization" -> true, "value" -> Json.arr( 321, Json.obj("de-DE" -> "table3col3row1-de", "en_GB" -> "table3col3row1-gb"), diff --git a/src/test/scala/com/campudus/tableaux/api/content/LinkTest.scala b/src/test/scala/com/campudus/tableaux/api/content/LinkTest.scala index 47b2f47a..a2992f49 100644 --- a/src/test/scala/com/campudus/tableaux/api/content/LinkTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/content/LinkTest.scala @@ -542,7 +542,7 @@ class LinkTest extends LinkTestBase { assertEquals( Json.obj( "status" -> "ok", - "value" -> Json.arr(Json.obj("id" -> rowId1, "value" -> "Lala", "viewAuthorization" -> true)) + "value" -> Json.arr(Json.obj("id" -> rowId1, "value" -> "Lala")) ), addLink1 ) @@ -550,8 +550,8 @@ class LinkTest extends LinkTestBase { Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> rowId1, "value" -> "Lala", "viewAuthorization" -> true), - Json.obj("id" -> rowId2, "value" -> "Lulu", "viewAuthorization" -> true) + Json.obj("id" -> rowId1, "value" -> "Lala"), + Json.obj("id" -> rowId2, "value" -> "Lulu") ) ), addLink2 @@ -560,8 +560,8 @@ class LinkTest extends LinkTestBase { val expectedJson2 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> rowId1, "value" -> "Lala", "viewAuthorization" -> true), - Json.obj("id" -> rowId2, "value" -> "Lulu", "viewAuthorization" -> true) + Json.obj("id" -> rowId1, "value" -> "Lala"), + Json.obj("id" -> rowId2, "value" -> "Lulu") ) ) @@ -685,21 +685,21 @@ class LinkTest extends LinkTestBase { val expected1 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true), - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table2row1"), + Json.obj("id" -> 2, "value" -> "table2row2") ) ) val expected2 = Json.obj("status" -> "ok", "value" -> Json.arr()) val expected3 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table1row1", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table1row1") ) ) val expected4 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table1row1", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table1row1") ) ) @@ -780,16 +780,14 @@ class LinkTest extends LinkTestBase { "value" -> Json.obj( "en-GB" -> "Hello, Table 2 World!", "de-DE" -> "Hallo, Table 2 Welt!" - ), - "viewAuthorization" -> true + ) ), Json.obj( "id" -> 2, "value" -> Json.obj( "en-GB" -> "Hello, Table 2 World2!", "de-DE" -> "Hallo, Table 2 Welt2!" - ), - "viewAuthorization" -> true + ) ) ) ) @@ -803,8 +801,7 @@ class LinkTest extends LinkTestBase { "value" -> Json.obj( "de-DE" -> "Hallo, Table 1 Welt!", "en-GB" -> "Hello, Table 1 World!" - ), - "viewAuthorization" -> true + ) ) ) ) @@ -858,16 +855,14 @@ class LinkTest extends LinkTestBase { "value" -> Json.obj( "en-GB" -> "Hello, Table 2 World!", "de-DE" -> "Hallo, Table 2 Welt!" - ), - "viewAuthorization" -> true + ) ), Json.obj( "id" -> 2, "value" -> Json.obj( "en-GB" -> "Hello, Table 2 World2!", "de-DE" -> "Hallo, Table 2 Welt2!" - ), - "viewAuthorization" -> true + ) ) ) ) @@ -881,8 +876,7 @@ class LinkTest extends LinkTestBase { "value" -> Json.obj( "de-DE" -> "Hallo, Table 1 Welt!", "en-GB" -> "Hello, Table 1 World!" - ), - "viewAuthorization" -> true + ) ) ) ) @@ -921,15 +915,15 @@ class LinkTest extends LinkTestBase { val expected1 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true), - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table2row1"), + Json.obj("id" -> 2, "value" -> "table2row2") ) ) val expected2 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true) + Json.obj("id" -> 2, "value" -> "table2row2") ) ) @@ -986,22 +980,22 @@ class LinkTest extends LinkTestBase { val expected1 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table2row1") ) ) val expected2 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true) + Json.obj("id" -> 2, "value" -> "table2row2") ) ) val expected3 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true), - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true) + Json.obj("id" -> 2, "value" -> "table2row2"), + Json.obj("id" -> 1, "value" -> "table2row1") ) ) @@ -1037,15 +1031,15 @@ class LinkTest extends LinkTestBase { val expected1 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true), - Json.obj("id" -> 2, "value" -> "table2row2", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table2row1"), + Json.obj("id" -> 2, "value" -> "table2row2") ) ) val expected2 = Json.obj( "status" -> "ok", "value" -> Json.arr( - Json.obj("id" -> 1, "value" -> "table2row1", "viewAuthorization" -> true) + Json.obj("id" -> 1, "value" -> "table2row1") ) ) diff --git a/src/test/scala/com/campudus/tableaux/api/content/RetrieveGroupColumnTest.scala b/src/test/scala/com/campudus/tableaux/api/content/RetrieveGroupColumnTest.scala index cda6783c..a255817b 100644 --- a/src/test/scala/com/campudus/tableaux/api/content/RetrieveGroupColumnTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/content/RetrieveGroupColumnTest.scala @@ -216,8 +216,7 @@ class RetrieveGroupColumnTest extends TableauxTestBase { def expectedLinkCell(s: String) = Json.arr( Json.obj( "id" -> rowId11, - "value" -> Json.arr(s, true), - "viewAuthorization" -> true + "value" -> Json.arr(s, true) ) ) diff --git a/src/test/scala/com/campudus/tableaux/api/content/RowLevelAnnotationsTest.scala b/src/test/scala/com/campudus/tableaux/api/content/RowLevelAnnotationsTest.scala index 662423b8..66bc2d76 100644 --- a/src/test/scala/com/campudus/tableaux/api/content/RowLevelAnnotationsTest.scala +++ b/src/test/scala/com/campudus/tableaux/api/content/RowLevelAnnotationsTest.scala @@ -46,7 +46,6 @@ class RowLevelAnnotationsTest extends TableauxTestBase { val expectedRowJson2 = Json.obj( "status" -> "ok", "id" -> rowId, - "final" -> false, "values" -> Json.arr(null, null) )