Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence the quota manager for updates #19046

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 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,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:
Expand All @@ -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."
jdavcs marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -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)
Expand Down Expand Up @@ -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:
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
Loading