Skip to content

Commit

Permalink
service: refactor set_quota method
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Sep 14, 2023
1 parent 6fec4a3 commit 7707738
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions invenio_rdm_records/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ def read(self, identity, id_, expand=False, with_deleted=False):
#
# Record file quota handling
#

def _update_quota(self, record, quota_size, max_file_size, notes):
"""Update record with quota values"""
record.quota_size = quota_size
if max_file_size:
record.max_file_size = max_file_size
if notes:
record.notes = notes

@unit_of_work()
def set_quota(
self,
Expand Down Expand Up @@ -458,9 +467,7 @@ def set_quota(
)
else:
# update record quota
draft_quota.quota_size = quota_size
draft_quota.max_file_size = max_file_size
draft_quota.notes = notes
self._update_quota(draft_quota, quota_size, max_file_size, notes)

db.session.add(draft_quota)

Expand Down Expand Up @@ -501,9 +508,7 @@ def set_user_quota(
)
else:
# update user quota
user_quota.quota_size = quota_size
user_quota.max_file_size = max_file_size
user_quota.notes = notes
self._update_quota(user_quota, quota_size, max_file_size, notes)

db.session.add(user_quota)

Expand Down

0 comments on commit 7707738

Please sign in to comment.