From d84c3accfbf3a467d97dacbe0b9676531625e5f8 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 23 Oct 2024 19:25:46 +0200 Subject: [PATCH] silence the quota manager for updates this should make the quota manager a bit more siltent when updating quotas, i.e. only message when something is changed In https://github.com/galaxyproject/galaxy/pull/18775#issuecomment-2353115734 it was suggested to remove all messages, but I find it quite useful when using bioblend. --- lib/galaxy/managers/quotas.py | 50 ++++++++++---------- lib/galaxy/webapps/galaxy/services/quotas.py | 3 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/galaxy/managers/quotas.py b/lib/galaxy/managers/quotas.py index 8b91b94a94a8..58509f802c1a 100644 --- a/lib/galaxy/managers/quotas.py +++ b/lib/galaxy/managers/quotas.py @@ -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.") @@ -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: @@ -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: @@ -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) @@ -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: diff --git a/lib/galaxy/webapps/galaxy/services/quotas.py b/lib/galaxy/webapps/galaxy/services/quotas.py index 68b24dc6e970..564f864d5993 100644 --- a/lib/galaxy/webapps/galaxy/services/quotas.py +++ b/lib/galaxy/webapps/galaxy/services/quotas.py @@ -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(