From 51c836e935f1bcdbe4817908d04000254bc5fbf0 Mon Sep 17 00:00:00 2001 From: Bruno Calza Date: Thu, 11 May 2023 17:37:09 -0300 Subject: [PATCH] adds support for alter table in policy Signed-off-by: Bruno Calza --- contracts/TablelandPolicy.sol | 2 ++ contracts/TablelandTables.sol | 1 + contracts/test/TestAllowAllTablelandController.sol | 1 + contracts/test/TestReentrancyMutate.sol | 1 + contracts/test/TestReentrancyMutateOne.sol | 1 + contracts/test/TestReentrancyRunSQLLegacy.sol | 1 + contracts/test/TestTablelandController.sol | 1 + contracts/test/TestTablelandTablesNoConstructor.sol | 1 + contracts/test/TestTablelandTablesUpgrade.sol | 1 + test/unit/ITablelandController.ts | 1 + 10 files changed, 11 insertions(+) diff --git a/contracts/TablelandPolicy.sol b/contracts/TablelandPolicy.sol index 423ed41..6f4e82a 100644 --- a/contracts/TablelandPolicy.sol +++ b/contracts/TablelandPolicy.sol @@ -11,6 +11,8 @@ struct TablelandPolicy { bool allowUpdate; // Whether or not the table should allow SQL DELETE statements. bool allowDelete; + // Whether or not the table should allow SQL ALTER TABLE statements. + bool allowAlter; // A conditional clause used with SQL UPDATE and DELETE statements. // For example, a value of "foo > 0" will concatenate all SQL UPDATE // and/or DELETE statements with "WHERE foo > 0". diff --git a/contracts/TablelandTables.sol b/contracts/TablelandTables.sol index d73f810..e205ae6 100644 --- a/contracts/TablelandTables.sol +++ b/contracts/TablelandTables.sol @@ -221,6 +221,7 @@ contract TablelandTables is return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestAllowAllTablelandController.sol b/contracts/test/TestAllowAllTablelandController.sol index dce6666..e0461ed 100644 --- a/contracts/test/TestAllowAllTablelandController.sol +++ b/contracts/test/TestAllowAllTablelandController.sol @@ -12,6 +12,7 @@ contract TestAllowAllTablelandController is TablelandController { // Return allow-all policy return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestReentrancyMutate.sol b/contracts/test/TestReentrancyMutate.sol index 29b90c2..ad6a241 100644 --- a/contracts/test/TestReentrancyMutate.sol +++ b/contracts/test/TestReentrancyMutate.sol @@ -36,6 +36,7 @@ contract TestReentrancyMutate is TablelandController, ERC721, Ownable { // Return allow-all policy return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestReentrancyMutateOne.sol b/contracts/test/TestReentrancyMutateOne.sol index 03dc3d7..d9f137a 100644 --- a/contracts/test/TestReentrancyMutateOne.sol +++ b/contracts/test/TestReentrancyMutateOne.sol @@ -28,6 +28,7 @@ contract TestReentrancyMutateOne is TablelandController, ERC721, Ownable { // Return allow-all policy return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestReentrancyRunSQLLegacy.sol b/contracts/test/TestReentrancyRunSQLLegacy.sol index 2a879fd..a76fbed 100644 --- a/contracts/test/TestReentrancyRunSQLLegacy.sol +++ b/contracts/test/TestReentrancyRunSQLLegacy.sol @@ -31,6 +31,7 @@ contract TestReentrancyRunSQLLegacy is TablelandController, ERC721, Ownable { // Return allow-all policy return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestTablelandController.sol b/contracts/test/TestTablelandController.sol index 0939e75..73a0ed6 100644 --- a/contracts/test/TestTablelandController.sol +++ b/contracts/test/TestTablelandController.sol @@ -57,6 +57,7 @@ contract TestTablelandController is TablelandController, Ownable { // Return policy return TablelandPolicy({ + allowAlter: false, allowInsert: false, allowUpdate: true, allowDelete: false, diff --git a/contracts/test/TestTablelandTablesNoConstructor.sol b/contracts/test/TestTablelandTablesNoConstructor.sol index ebc1ca2..05a08ae 100644 --- a/contracts/test/TestTablelandTablesNoConstructor.sol +++ b/contracts/test/TestTablelandTablesNoConstructor.sol @@ -179,6 +179,7 @@ contract TestTablelandTablesNoConstructor is return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/contracts/test/TestTablelandTablesUpgrade.sol b/contracts/test/TestTablelandTablesUpgrade.sol index 71688c7..15edfc2 100644 --- a/contracts/test/TestTablelandTablesUpgrade.sol +++ b/contracts/test/TestTablelandTablesUpgrade.sol @@ -186,6 +186,7 @@ contract TestTablelandTablesUpgrade is return TablelandPolicy({ + allowAlter: true, allowInsert: true, allowUpdate: true, allowDelete: true, diff --git a/test/unit/ITablelandController.ts b/test/unit/ITablelandController.ts index c5ec9f3..0d28cad 100644 --- a/test/unit/ITablelandController.ts +++ b/test/unit/ITablelandController.ts @@ -536,6 +536,7 @@ describe("ITablelandController", function () { expect(runEvent.args!.tableId).to.equal(tableId); expect(runEvent.args!.statement).to.equal(runStatement); expect(runEvent.args!.policy.allowInsert).to.equal(false); + expect(runEvent.args!.policy.allowAlter).to.equal(false); expect(runEvent.args!.policy.allowUpdate).to.equal(true); expect(runEvent.args!.policy.allowDelete).to.equal(false); expect(runEvent.args!.policy.whereClause).to.equal(