def at_least_one_schema_is_allowed(database): """ If the user has access to the database or all datasource 1. if schemas_allowed_for_csv_upload is empty a) if database does not support schema user is able to upload csv without specifying schema name b) if database supports schema user is able to upload csv to any schema 2. if schemas_allowed_for_csv_upload is not empty a) if database does not support schema This situation is impossible and upload will fail b) if database supports schema user is able to upload to schema in schemas_allowed_for_csv_upload elif the user does not access to the database or all datasource 1. if schemas_allowed_for_csv_upload is empty a) if database does not support schema user is unable to upload csv b) if database supports schema user is unable to upload csv 2. if schemas_allowed_for_csv_upload is not empty a) if database does not support schema This situation is impossible and user is unable to upload csv b) if database supports schema user is able to upload to schema in schemas_allowed_for_csv_upload """ if (security_manager.database_access(database) or security_manager.all_datasource_access()): return True schemas = database.get_schema_access_for_csv_upload() if schemas and security_manager.schemas_accessible_by_user( database, schemas, False): return True return False
def at_least_one_schema_is_allowed(database): """ If the user has access to the database or all datasource 1. if schemas_allowed_for_csv_upload is empty a) if database does not support schema user is able to upload csv without specifying schema name b) if database supports schema user is able to upload csv to any schema 2. if schemas_allowed_for_csv_upload is not empty a) if database does not support schema This situation is impossible and upload will fail b) if database supports schema user is able to upload to schema in schemas_allowed_for_csv_upload elif the user does not access to the database or all datasource 1. if schemas_allowed_for_csv_upload is empty a) if database does not support schema user is unable to upload csv b) if database supports schema user is unable to upload csv 2. if schemas_allowed_for_csv_upload is not empty a) if database does not support schema This situation is impossible and user is unable to upload csv b) if database supports schema user is able to upload to schema in schemas_allowed_for_csv_upload """ if (security_manager.database_access(database) or security_manager.all_datasource_access()): return True schemas = database.get_schema_access_for_csv_upload() if (schemas and security_manager.schemas_accessible_by_user( database, schemas, False)): return True return False
def is_schema_allowed(self, database, schema): if not database.allow_csv_upload: return False schemas = database.get_schema_access_for_csv_upload() if schemas: return schema in schemas return (security_manager.database_access(database) or security_manager.all_datasource_access())
def schema_allows_csv_upload(database: Database, schema: Optional[str]) -> bool: if not database.allow_csv_upload: return False schemas = database.get_schema_access_for_csv_upload() if schemas: return schema in schemas return (security_manager.database_access(database) or security_manager.all_datasource_access())
def _is_schema_allowed_for_csv_upload(self, database: Database, schema: str = None) -> bool: """ Checks whether the specified schema is allowed for csv-uploads Keyword Arguments: database -- The database object which will be used for the import schema -- the schema to be used for the import :return if schema allow csv upload """ if not database.allow_csv_upload: return False schemas = database.get_schema_access_for_csv_upload() if schemas: return schema in schemas return (security_manager.database_access(database) or security_manager.all_datasource_access())
def _allow_csv_upload_databases(self) -> list: """ Get all databases which allow csv upload as database dto :returns list of database dto """ databases = db.session().query(Database).filter_by( allow_csv_upload=True).all() permitted_databases: list = [] for database in databases: if security_manager.database_access(database): permitted_databases.append(database) databases_json = [ DatabaseDto(NEW_DATABASE_ID, "In a new database", []) ] for database in permitted_databases: databases_json.append( DatabaseDto( database.id, database.name, json.loads( database.extra)["schemas_allowed_for_csv_upload"], )) return databases_json