From f02f23b0da21b1a5d2f9e2d1f4b529545570cf83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Mon, 4 Jul 2022 08:35:57 +0200
Subject: [PATCH] ENH: add procedure to collect ACL for a set of entities

---
 procedures/getACLForEntitySet.sql | 48 +++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 procedures/getACLForEntitySet.sql

diff --git a/procedures/getACLForEntitySet.sql b/procedures/getACLForEntitySet.sql
new file mode 100644
index 0000000..525bb10
--- /dev/null
+++ b/procedures/getACLForEntitySet.sql
@@ -0,0 +1,48 @@
+/*
+ * This file is a part of the CaosDB Project.
+ *
+ * Copyright (C) 2022 IndiScale GmbH
+ * Copyright (C) 2022 Henrik tom Wörden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ * Creates a table with the columns (entity ID, acl) from a given table with
+ *  entity IDs. Here, acl in the string representation of the acl.
+ * Parameters
+ * ----------
+ *
+ * entitySet: table with list of IDs
+ */
+DELIMITER //
+DROP PROCEDURE IF EXISTS db_5_0.applyPOV;
+CREATE OR REPLACE PROCEDURE db_5_0.getACLForEntitySet(in entitySet VARCHAR(255))
+BEGIN
+    -- TODO in future one might want to retrieve only a distinct set of acl
+    -- with (acl_id, acl) and a table with (entity_id, acl_id) to reduce the
+    -- amount of data being transfered
+
+    -- TODO Double check: Versioning is not an issue here since acl is not
+    -- versioned.
+    SET @stmtStr = CONCAT('SELECT entity_n_acl.id, entity_acl.acl from ',
+        '(select entities.id, entities.acl from entities where id in (select id from `',
+        entitySet,
+        '`) ) as entity_n_acl inner join entity_acl on entity_n_acl.acl=entity_acl.id;',)
+    PREPARE stmt FROM @stmtStr;
+    EXECUTE stmt;
+
+END
+//
-- 
GitLab