Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nschmid committed May 30, 2024
2 parents 680610e + 4c5c89d commit 369064b
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ BEGIN
INSERT INTO dashboard_user
SELECT nextval('dashboard_user_id_seq'), new.user_id, dashboards.id from dashboards;

--- Handle ownership of charts
DELETE FROM slice_user WHERE user_id = new.user_id;
INSERT INTO slice_user
SELECT nextval('slice_user_id_seq'), new.user_id, slices.id from slices;

--- Handle ownership of datasets
DELETE FROM sqlatable_user WHERE user_id = new.user_id;
INSERT INTO sqlatable_user
Expand Down Expand Up @@ -295,6 +300,10 @@ BEGIN
IF old.role_id = BI_EDITOR_role_id THEN
--- Delete ownership of dashboards
DELETE FROM dashboard_user WHERE user_id = old.user_id;

--- Delete ownership of charts
DELETE FROM slice_user WHERE user_id = old.user_id;

--- Delete ownership of datasets
DELETE FROM sqlatable_user WHERE user_id = old.user_id;
END IF;
Expand Down Expand Up @@ -350,4 +359,43 @@ DROP TRIGGER IF EXISTS insert_owners_on_new_dataset on tables;
CREATE TRIGGER insert_owners_on_new_dataset
AFTER INSERT ON tables
FOR EACH ROW
EXECUTE FUNCTION insert_owners_on_new_dataset();
EXECUTE FUNCTION insert_owners_on_new_dataset();



--
-- Trigger function for inserts on slices table that sets all BI_EDITOR users as owner of the corresponding chart
--
-- DROP FUNCTION insert_owners_on_new_slice;
CREATE OR REPLACE FUNCTION insert_owners_on_new_slice() RETURNS TRIGGER AS
$$
BEGIN

INSERT INTO slice_user(id, user_id, slice_id)

SELECT
nextval('slice_user_id_seq'),
ab_user.id,
new.id
FROM
ab_user
LEFT JOIN ab_user_role ON ab_user.id = ab_user_role.user_id
LEFT JOIN ab_role ON ab_role.id = ab_user_role.role_id
WHERE
ab_role.name = 'BI_EDITOR'
AND ab_user.id <> new.created_by_fk;

RETURN new;
END;
$$
LANGUAGE plpgsql;


--
-- After insert Trigger on slices that sets all BI_EDITOR users as owner of the corresponding chart
--
DROP TRIGGER IF EXISTS insert_owners_on_new_slice on slices;
CREATE TRIGGER insert_owners_on_new_dataset
AFTER INSERT ON slices
FOR EACH ROW
EXECUTE FUNCTION insert_owners_on_new_slice();
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
-- Deletes potential duplicate entries in the sqlatable_user table.
-- This script is repeatable.
--
TRUNCATE sqlatable_user RESTART IDENTITY;

WITH
editor_user_ids AS(
SELECT
Expand All @@ -42,6 +44,4 @@ WITH
role_id = (SELECT id FROM ab_role WHERE name = 'BI_EDITOR')
)

INSERT INTO sqlatable_user (id, user_id, table_id) SELECT nextval('sqlatable_user_id_seq'), editor_user_ids.user_id, tables.id FROM tables, editor_user_ids;

DELETE FROM sqlatable_user WHERE id NOT IN (SELECT min(id) FROM sqlatable_user GROUP BY user_id, table_id);
INSERT INTO sqlatable_user (id, user_id, table_id) SELECT nextval('sqlatable_user_id_seq'), editor_user_ids.user_id, tables.id FROM tables, editor_user_ids;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--
-- Copyright © 2024, Kanton Bern
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the <organization> nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--

--
-- Adds all current BI_EDITORs as owners of all charts.
-- Deletes potential duplicate entries in the slice_user table.
-- This script is repeatable.
--
TRUNCATE slice_user RESTART IDENTITY;

WITH
editor_user_ids AS(
SELECT
user_id

FROM
ab_user_role

WHERE
role_id = (SELECT id FROM ab_role WHERE name = 'BI_EDITOR')
)

INSERT INTO slice_user (id, user_id, slice_id) SELECT nextval('slice_user_id_seq'), editor_user_ids.user_id, slices.id FROM slices, editor_user_ids;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--
-- Copyright © 2024, Kanton Bern
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the <organization> nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--

--
-- Adds all current BI_EDITORs as owners of all charts.
-- Deletes potential duplicate entries in the dashboard_user table.
-- This script is repeatable.
--
TRUNCATE dashboard_user RESTART IDENTITY;

WITH
editor_user_ids AS(
SELECT
user_id

FROM
ab_user_role

WHERE
role_id = (SELECT id FROM ab_role WHERE name = 'BI_EDITOR')
)

INSERT INTO dashboard_user (id, user_id, dashboard_id) SELECT nextval('dashboard_user_id_seq'), editor_user_ids.user_id, dashboards.id FROM dashboards, editor_user_ids;
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@
<changeSet id="0004" author="hellodata" runOnChange="true">
<sqlFile path="changelogs/04_triggers.sql" relativeToChangelogFile="true" splitStatements="false" />
</changeSet>
<changeSet id="0005" author="hellodata" runAlways="true">
<changeSet id="0005" author="hellodata">
<sqlFile path="changelogs/05_delete_duplicate_owners.sql" relativeToChangelogFile="true" splitStatements="false" />
</changeSet>
<changeSet id="0006" author="hellodata" runAlways="true">
<sqlFile path="changelogs/06_handle_owners_on_datasets.sql" relativeToChangelogFile="true" splitStatements="false" />
</changeSet>

<changeSet id="0007" author="hellodata" runAlways="true">
<sqlFile path="changelogs/07_handle_owners_on_charts.sql" relativeToChangelogFile="true" splitStatements="false" />
</changeSet>
<changeSet id="0008" author="hellodata" runAlways="true">
<sqlFile path="changelogs/08_handle_owners_on_dashboards.sql" relativeToChangelogFile="true" splitStatements="false" />
</changeSet>
</databaseChangeLog>

0 comments on commit 369064b

Please sign in to comment.