Skip to content

Commit

Permalink
silence the quota manager for updates
Browse files Browse the repository at this point in the history
this should make the quota manager a bit more siltent when
updating quotas, i.e. only message when something is changed

In #18775 (comment)
it was suggested to remove all messages, but I find it quite useful
when using bioblend.
  • Loading branch information
bernt-matthias committed Oct 23, 2024
1 parent e6d1b30 commit d84c3ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
50 changes: 25 additions & 25 deletions lib/galaxy/managers/quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _parse_amount(self, amount: str) -> Optional[Union[int, bool]]:
except ValueError:
return False

def rename_quota(self, quota, params) -> str:
def rename_quota(self, quota, params) -> Optional[str]:
stmt = select(Quota).where(and_(Quota.name == params.name, Quota.id != quota.id)).limit(1)
if not params.name:
raise ActionInputError("Enter a valid name.")
Expand All @@ -131,10 +131,10 @@ def rename_quota(self, quota, params) -> str:
self.sa_session.add(quota)
with transaction(self.sa_session):
self.sa_session.commit()
message = f"Quota '{old_name}' has been renamed to '{params.name}'."
return message
if old_name != params.name:
return f"Quota '{old_name}' has been renamed to '{params.name}'."

def manage_users_and_groups_for_quota(self, quota, params, decode_id=None) -> str:
def manage_users_and_groups_for_quota(self, quota, params, decode_id=None) -> Optional[str]:
if quota.default:
raise ActionInputError("Default quotas cannot be associated with specific users and groups.")
else:
Expand All @@ -151,10 +151,10 @@ def manage_users_and_groups_for_quota(self, quota, params, decode_id=None) -> st
raise ActionInputError("One or more invalid group id has been provided.")
self.quota_agent.set_entity_quota_associations(quotas=[quota], users=in_users, groups=in_groups)
self.sa_session.refresh(quota)
message = f"Quota '{quota.name}' has been updated with {len(in_users)} associated users and {len(in_groups)} associated groups."
return message
if len(quota.users) != len(in_users) or len(quota.groups) != len(in_groups):
return f"Quota '{quota.name}' has been updated with {len(in_users)} associated users and {len(in_groups)} associated groups."

def edit_quota(self, quota, params) -> str:
def edit_quota(self, quota, params) -> Optional[str]:
if params.amount.lower() in ("unlimited", "none", "no limit"):
new_amount = None
else:
Expand All @@ -169,36 +169,36 @@ def edit_quota(self, quota, params) -> str:
elif params.operation not in model.Quota.valid_operations:
raise ActionInputError("Enter a valid operation.")
else:
old_display_amount = quota.display_amount
old_operation = quota.operation
quota.amount = new_amount
quota.operation = params.operation
self.sa_session.add(quota)
with transaction(self.sa_session):
self.sa_session.commit()
message = f"Quota '{quota.name}' is now '{quota.operation}{quota.display_amount}'."
return message
if old_display_amount != quota.display_amount or old_operation != quota.operation:
return f"Quota '{quota.name}' is now '{quota.operation}{quota.display_amount}'."

def set_quota_default(self, quota, params) -> str:
def set_quota_default(self, quota, params) -> Optional[str]:
if params.default != "no" and params.default not in model.DefaultQuotaAssociation.types.__members__.values():
raise ActionInputError("Enter a valid default type.")
else:
message = ""
old_default = quota.default
if params.default != "no":
self.quota_agent.set_default_quota(params.default, quota)
message = f"Quota '{quota.name}' is now the default for {params.default} users."
else:
if quota.default:
message = f"Quota '{quota.name}' is no longer the default for {quota.default[0].type} users."
for dqa in quota.default:
self.sa_session.delete(dqa)
with transaction(self.sa_session):
self.sa_session.commit()
else:
message = f"Quota '{quota.name}' is not a default."
return message
elif quota.default:
message = f"Quota '{quota.name}' is no longer the default for {quota.default[0].type} users."
for dqa in quota.default:
self.sa_session.delete(dqa)
with transaction(self.sa_session):
self.sa_session.commit()
if old_default != quota.default and message:
return message

def unset_quota_default(self, quota, params=None) -> str:
if not quota.default:
raise ActionInputError(f"Quota '{quota.name}' is not a default.")
else:
def unset_quota_default(self, quota, params=None) -> Optional[str]:
if quota.default:
message = f"Quota '{quota.name}' is no longer the default for {quota.default[0].type} users."
for dqa in quota.default:
self.sa_session.delete(dqa)
Expand Down Expand Up @@ -248,7 +248,7 @@ def undelete_quota(self, quota, params=None) -> str:
message += ", ".join(names)
return message

def purge_quota(self, quota, params=None):
def purge_quota(self, quota, params=None) -> str:
"""
This method should only be called for a Quota that has previously been deleted.
Purging a deleted Quota deletes all of the following from the database:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/webapps/galaxy/services/quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def update(self, trans: ProvidesUserContext, id: DecodedDatabaseIdField, params:
messages = []
for method in methods:
message = method(quota, params)
messages.append(message)
if message:
messages.append(message)
return "; ".join(messages)

def delete(
Expand Down

0 comments on commit d84c3ac

Please sign in to comment.