def get_library_storages(request): """ Return all storages info. 1. If not enable user role feature OR haven't configured `storage_ids` option in user role setting: Return storage info getted from seafile_api. And always put the default storage as the first item in the returned list. 2. If have configured `storage_ids` option in user role setting: Only return storage info in `storage_ids`. Filter out the wrong stotage id(s). Not change the order of the `storage_ids` list. """ all_storages = [] for storage in seafile_api.get_all_storage_classes(): storage_info = { 'storage_id': storage.storage_id, 'storage_name': storage.storage_name, 'is_default': storage.is_default, } if storage.is_default: all_storages.insert(0, storage_info) else: all_storages.append(storage_info) user_role_storage_ids = request.user.permissions.storage_ids() if not user_role_storage_ids: return all_storages user_role_storages = [] for user_role_storage_id in user_role_storage_ids: for storage in all_storages: if storage['storage_id'] == user_role_storage_id: user_role_storages.append(storage) continue return user_role_storages
def get_library_storages(request): """ Return info of storages can be used. 1. If not enable user role feature OR haven't configured `storage_ids` option in user role setting: Return storage info getted from seafile_api. And always put the default storage as the first item in the returned list. 2. If have configured `storage_ids` option in user role setting: Only return storage info in `storage_ids`. Filter out the wrong stotage id(s). Not change the order of the `storage_ids` list. """ if not is_pro_version(): return [] if not ENABLE_STORAGE_CLASSES: return [] # get all storages info try: storage_classes = seafile_api.get_all_storage_classes() except Exception as e: logger.error(e) return [] all_storages = [] for storage in storage_classes: storage_info = { 'storage_id': storage.storage_id, 'storage_name': storage.storage_name, 'is_default': storage.is_default, } if storage.is_default: all_storages.insert(0, storage_info) else: all_storages.append(storage_info) if STORAGE_CLASS_MAPPING_POLICY == 'USER_SELECT': return all_storages elif STORAGE_CLASS_MAPPING_POLICY == 'ROLE_BASED': user_role_storage_ids = request.user.permissions.storage_ids() if not user_role_storage_ids: return [] user_role_storages = [] for user_role_storage_id in user_role_storage_ids: for storage in all_storages: if storage['storage_id'] == user_role_storage_id: user_role_storages.append(storage) continue return user_role_storages else: # STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING' return []
def get_library_storages(request): """ Return info of storages can be used. 1. If not enable user role feature OR haven't configured `storage_ids` option in user role setting: Return storage info getted from seafile_api. And always put the default storage as the first item in the returned list. 2. If have configured `storage_ids` option in user role setting: Only return storage info in `storage_ids`. Filter out the wrong stotage id(s). Not change the order of the `storage_ids` list. """ if not is_pro_version(): return [] if not ENABLE_STORAGE_CLASSES: return [] # get all storages info try: storage_classes = seafile_api.get_all_storage_classes() except Exception as e: logger.error(e) return [] all_storages = [] for storage in storage_classes: storage_info = { 'storage_id': storage.storage_id, 'storage_name': storage.storage_name, 'is_default': storage.is_default, } if storage.is_default: all_storages.insert(0, storage_info) else: all_storages.append(storage_info) if STORAGE_CLASS_MAPPING_POLICY == 'USER_SELECT': return all_storages elif STORAGE_CLASS_MAPPING_POLICY == 'ROLE_BASED': user_role_storage_ids = request.user.permissions.storage_ids() if not user_role_storage_ids: return [] user_role_storages = [] for user_role_storage_id in user_role_storage_ids: for storage in all_storages: if storage['storage_id'] == user_role_storage_id: user_role_storages.append(storage) continue return user_role_storages else: # STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING' return []