66# it under the terms of the MIT License; see LICENSE file for more details.
77
88import logging
9+
910from flask import current_app
1011from invenio_access .permissions import system_identity
1112from invenio_search .engine import dsl
13+
1214from invenio_rdm_records .records .models import RDMRecordQuota
1315
1416logger = logging .getLogger (__name__ )
1517
18+
1619class StorageService :
1720 """Service providing per-user storage quota information."""
1821
@@ -28,7 +31,10 @@ def default_quota(self):
2831 @property
2932 def max_additional_quota (self ):
3033 """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
34+ return (
35+ current_app .config .get ("RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE" )
36+ or 150 * 10 ** 9
37+ )
3238
3339 def _search_user_resources (self , user , drafts = False ):
3440 """Fetch user records or drafts."""
@@ -47,7 +53,9 @@ def _search_user_resources(self, user, drafts=False):
4753
4854 def _resolve_records_and_quotas (self , items , draft = False ):
4955 """Resolve search hits and fetch quotas."""
50- cls = self .records_service .draft_cls if draft else self .records_service .record_cls
56+ cls = (
57+ self .records_service .draft_cls if draft else self .records_service .record_cls
58+ )
5159
5260 records = []
5361 parent_ids = set ()
@@ -90,14 +98,16 @@ def _compute_usage(self, records, quotas):
9098 total_extra += extra_quota
9199 total_used += additional_used
92100
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- })
101+ results .append (
102+ {
103+ "item" : item ,
104+ "record" : record ,
105+ "quota" : quota ,
106+ "used_bytes" : used_bytes ,
107+ "extra_quota" : extra_quota ,
108+ "additional_used" : additional_used ,
109+ }
110+ )
101111
102112 return results , total_extra , total_used
103113
@@ -115,8 +125,7 @@ def get_user_storage_usage(self, user, include_drafts=True):
115125 draft_data , extra_d , used_d = [], 0 , 0
116126 if include_drafts :
117127 draft_data , extra_d , used_d = self ._process_resources (
118- self ._search_user_resources (user , drafts = True ),
119- draft = True
128+ self ._search_user_resources (user , drafts = True ), draft = True
120129 )
121130
122131 return {
0 commit comments