def create_access_request(session, ds_type, ds_name, role_name, username): # TODO: generalize datasource names if ds_type == "table": ds = session.query(SqlaTable).filter( SqlaTable.table_name == ds_name).first() else: # This function will only work for ds_type == "table" raise NotImplementedError() ds_perm_view = security_manager.find_permission_view_menu( "datasource_access", ds.perm) security_manager.add_permission_role(security_manager.find_role(role_name), ds_perm_view) access_request = DatasourceAccessRequest( datasource_id=ds.id, datasource_type=ds_type, created_by_fk=security_manager.find_user(username=username).id, ) session.add(access_request) session.commit() return access_request
def create_access_request(session, ds_type, ds_name, role_name, user_name): ds_class = ConnectorRegistry.sources[ds_type] # TODO: generalize datasource names if ds_type == "table": ds = session.query(ds_class).filter(ds_class.table_name == ds_name).first() else: ds = session.query(ds_class).filter(ds_class.datasource_name == ds_name).first() ds_perm_view = security_manager.find_permission_view_menu( "datasource_access", ds.perm ) security_manager.add_permission_role( security_manager.find_role(role_name), ds_perm_view ) access_request = DatasourceAccessRequest( datasource_id=ds.id, datasource_type=ds_type, created_by_fk=security_manager.find_user(username=user_name).id, ) session.add(access_request) session.commit() return access_request