diff --git a/lib/galaxy/managers/quotas.py b/lib/galaxy/managers/quotas.py index 8b91b94a94a8..932e77a91348 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,12 @@ 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}'." + else: + return None - 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 +153,16 @@ 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) and 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." + elif len(quota.users) != len(in_users): + return f"Quota '{quota.name}' has been updated with {len(in_users)} associated users." + elif len(quota.groups) != len(in_groups): + return f"Quota '{quota.name}' has been updated with {len(in_groups)} associated groups." + else: + return None - 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,42 +177,43 @@ 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}'." + else: + return None - 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 = None 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." + 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() 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]: + message = None + 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() - return message + return message def delete_quota(self, quota, params=None) -> str: quotas = util.listify(quota) @@ -248,7 +257,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(