55# Invenio-RDM-Records is free software; you can redistribute it and/or modify
66# it under the terms of the MIT License; see LICENSE file for more details.
77
8+ """Storage Service."""
9+
810import logging
11+
912from flask import current_app
1013from invenio_access .permissions import system_identity
1114from invenio_search .engine import dsl
15+
1216from invenio_rdm_records .records .models import RDMRecordQuota
1317
1418logger = logging .getLogger (__name__ )
1519
20+
1621class StorageService :
1722 """Service providing per-user storage quota information."""
1823
@@ -28,7 +33,10 @@ def default_quota(self):
2833 @property
2934 def max_additional_quota (self ):
3035 """Get the maximum additional quota allowed per user."""
31- return current_app .config .get ("RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE" ) or 150 * 10 ** 9
36+ return (
37+ current_app .config .get ("RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE" )
38+ or 150 * 10 ** 9
39+ )
3240
3341 def _search_user_resources (self , user , drafts = False ):
3442 """Fetch user records or drafts."""
@@ -47,7 +55,9 @@ def _search_user_resources(self, user, drafts=False):
4755
4856 def _resolve_records_and_quotas (self , items , draft = False ):
4957 """Resolve search hits and fetch quotas."""
50- cls = self .records_service .draft_cls if draft else self .records_service .record_cls
58+ cls = (
59+ self .records_service .draft_cls if draft else self .records_service .record_cls
60+ )
5161
5262 records = []
5363 parent_ids = set ()
@@ -90,14 +100,16 @@ def _compute_usage(self, records, quotas):
90100 total_extra += extra_quota
91101 total_used += additional_used
92102
93- results .append ({
94- "item" : item ,
95- "record" : record ,
96- "quota" : quota ,
97- "used_bytes" : used_bytes ,
98- "extra_quota" : extra_quota ,
99- "additional_used" : additional_used ,
100- })
103+ results .append (
104+ {
105+ "item" : item ,
106+ "record" : record ,
107+ "quota" : quota ,
108+ "used_bytes" : used_bytes ,
109+ "extra_quota" : extra_quota ,
110+ "additional_used" : additional_used ,
111+ }
112+ )
101113
102114 return results , total_extra , total_used
103115
@@ -115,8 +127,7 @@ def get_user_storage_usage(self, user, include_drafts=True):
115127 draft_data , extra_d , used_d = [], 0 , 0
116128 if include_drafts :
117129 draft_data , extra_d , used_d = self ._process_resources (
118- self ._search_user_resources (user , drafts = True ),
119- draft = True
130+ self ._search_user_resources (user , drafts = True ), draft = True
120131 )
121132
122133 return {
0 commit comments