airajena commented on code in PR #102: URL: https://github.com/apache/fineract-business-intelligence/pull/102#discussion_r4318212957
########## warehouse/schema/access_control.sql: ########## @@ -0,0 +1,51 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, + +CREATE TABLE IF NOT EXISTS meta.user_office_mapping ( + scope_id BIGSERIAL PRIMARY KEY, + username TEXT NOT NULL, + role_name TEXT NOT NULL CHECK (role_name IN ('ADMIN', 'REGION_MANAGER', 'BRANCH_MANAGER', 'ANALYST')), + region TEXT, + source_id TEXT, + office_id BIGINT, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT branch_scope_is_qualified CHECK ( + role_name <> 'BRANCH_MANAGER' OR (source_id IS NOT NULL AND office_id IS NOT NULL) + ) +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_user_office_mapping_scope + ON meta.user_office_mapping (username, COALESCE(region, ''), COALESCE(source_id, ''), COALESCE(office_id, -1)); + +CREATE OR REPLACE VIEW meta.v_user_access_scope AS +SELECT DISTINCT + m.username, + m.role_name, + r.source_id, + m.office_id +FROM meta.user_office_mapping m +JOIN meta.source_registry r Review Comment: Fixed. The CHECK now requires every non-admin row to have a scope (REGION_MANAGER needs a region). The view also drops rows where all scope columns are NULL. I added a case to test_rls_isolation.py showing an unscoped ANALYST sees zero rows. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
