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

Remove tags used #19576

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8535,11 +8535,6 @@ export interface components {
* @description Percentage of the storage quota applicable to the user.
*/
quota_percent?: number | null;
/**
* Tags used
* @description Tags used by the user
*/
tags_used: string[];
/**
* Total disk usage
* @description Size of all non-purged, unique datasets of the user in bytes.
Expand Down
1 change: 0 additions & 1 deletion client/src/app/__mocks__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function getGalaxyInstance() {
total_disk_usage: 61815527,
nice_total_disk_usage: "59.0 MB",
email: "test@test.test",
tags_used: ["test"],
model_class: "User",
id: "f2db41e1fa331b3e",
attributes: {},
Expand Down
1 change: 0 additions & 1 deletion client/src/components/History/Modals/SelectorModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const CURRENT_HISTORY_INDICATION_TEXT = "(Current)";
const CURRENT_USER = {
email: "email",
id: "user_id",
tags_used: [],
total_disk_usage: 0,
};

Expand Down
1 change: 0 additions & 1 deletion client/src/components/History/SwitchToHistoryLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function mountSwitchToHistoryLinkForHistory(history: HistorySummaryExtended) {
userStore.currentUser = {
email: "email",
id: "user_id",
tags_used: [],
isAnonymous: false,
total_disk_usage: 0,
nice_total_disk_usage: "0 bytes",
Expand Down
1 change: 0 additions & 1 deletion client/tests/test-data/bootstrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default {
total_disk_usage: 61815527,
nice_total_disk_usage: "59.0 MB",
email: "test@test.test",
tags_used: ["test"],
model_class: "User",
id: "f2db41e1fa331b3e",
},
Expand Down
1 change: 0 additions & 1 deletion client/tests/test-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export function getFakeRegisteredUser(data: Partial<RegisteredUser> = {}): Regis
return {
id: "fake_user_id",
email: "fake_user_email",
tags_used: [],
isAnonymous: false,
username: "fake_username",
total_disk_usage: 0,
Expand Down
33 changes: 0 additions & 33 deletions lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hashlib
import logging
import random
import re
import string
import time
from datetime import datetime
Expand Down Expand Up @@ -428,35 +427,6 @@ def quota(self, user, total=False, quota_source_label=None):
def quota_bytes(self, user, quota_source_label: Optional[str] = None):
return self.app.quota_agent.get_quota(user=user, quota_source_label=quota_source_label)

def tags_used(self, user, tag_models=None):
"""
Return a list of distinct 'user_tname:user_value' strings that the
given user has used.
"""
# TODO: simplify and unify with tag manager
if self.is_anonymous(user):
return []

# get all the taggable model TagAssociations
if not tag_models:
tag_models = [v.tag_assoc_class for v in self.app.tag_handler.item_tag_assoc_info.values()]

if not tag_models:
return []

# create a union of select statements for each tag model for this user - getting only the tname and user_value
all_stmts = []
for tag_model in tag_models:
stmt = select(tag_model.user_tname, tag_model.user_value).where(tag_model.user == user)
all_stmts.append(stmt)
union_stmt = all_stmts[0].union(*all_stmts[1:]) # union the first select with the rest

# boil the tag tuples down into a sorted list of DISTINCT name:val strings
tag_tuples = self.session().execute(union_stmt) # no need for DISTINCT: union is a set operation.
tags = [(f"{name}:{val}" if val else name) for name, val in tag_tuples]
# consider named tags while sorting
return sorted(tags, key=lambda str: re.sub("^name:", "#", str))

def change_password(self, trans, password=None, confirm=None, token=None, id=None, current=None):
"""
Allows to change a user password with a token.
Expand Down Expand Up @@ -702,8 +672,6 @@ def __init__(self, app: MinimalManagerApp):
"purged",
# 'active',
"preferences",
# all tags
"tags_used",
# all annotations
# 'annotations'
"preferred_object_store_id",
Expand All @@ -726,7 +694,6 @@ def add_serializers(self):
"quota_percent": lambda i, k, **c: self.user_manager.quota(i),
"quota": lambda i, k, **c: self.user_manager.quota(i, total=True),
"quota_bytes": lambda i, k, **c: self.user_manager.quota_bytes(i),
"tags_used": lambda i, k, **c: self.user_manager.tags_used(i),
}
)

Expand Down
1 change: 0 additions & 1 deletion lib/galaxy/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ class DetailedUserModel(BaseUserModel, AnonUserModel):
quota_bytes: Optional[int] = Field(
default=None, title="Quota in bytes", description="Quota applicable to the user in bytes."
)
tags_used: List[str] = Field(default=..., title="Tags used", description="Tags used by the user")


class UserUpdatePayload(Model):
Expand Down
33 changes: 0 additions & 33 deletions lib/galaxy/webapps/base/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class JSAppLauncher(BaseUIController):
"email",
"username",
"is_admin",
"tags_used",
"total_disk_usage",
"nice_total_disk_usage",
"quota_percent",
Expand Down Expand Up @@ -1163,38 +1162,6 @@ def _get_item_tag_assoc(self, trans, item_class_name, id, tag_name):
def set_tags_from_list(self, trans, item, new_tags_list, user=None):
return trans.tag_handler.set_tags_from_list(user, item, new_tags_list)

def get_user_tags_used(self, trans, user=None):
"""
Return a list of distinct 'user_tname:user_value' strings that the
given user has used.

user defaults to trans.user.
Returns an empty list if no user is given and trans.user is anonymous.
"""
# TODO: for lack of a UsesUserMixin - placing this here - maybe into UsesTags, tho
user = user or trans.user
if not user:
return []

# get all the taggable model TagAssociations
tag_models = [v.tag_assoc_class for v in trans.tag_handler.item_tag_assoc_info.values()]
# create a union of subqueries for each for this user - getting only the tname and user_value
all_tags_query = None
for tag_model in tag_models:
subq = trans.sa_session.query(tag_model.user_tname, tag_model.user_value).filter(
tag_model.user == trans.user
)
all_tags_query = subq if all_tags_query is None else all_tags_query.union(subq)

# if nothing init'd the query, bail
if all_tags_query is None:
return []

# boil the tag tuples down into a sorted list of DISTINCT name:val strings
tags = all_tags_query.distinct().all()
tags = [(f"{name}:{val}" if val else name) for name, val in tags]
return sorted(tags)


class UsesExtendedMetadataMixin(SharableItemSecurityMixin):
"""Mixin for getting and setting item extended metadata."""
Expand Down
9 changes: 0 additions & 9 deletions lib/tool_shed/webapp/templates/galaxy_client_app.mako
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ ${ h.dumps( dictionary, indent=( 2 if trans.debug else 0 ) ) }
user_dict[ 'quota_percent' ] = trans.app.quota_agent.get_percent( trans=trans )
user_dict[ 'is_admin' ] = trans.user_is_admin

# tags used
users_api_controller = trans.webapp.api_controllers[ 'users' ]
tags_used = []
for tag in users_api_controller.get_user_tags_used( trans, user=trans.user ):
tag = escape( tag )
if tag:
tags_used.append( tag )
user_dict[ 'tags_used' ] = tags_used

return user_dict

usage = 0
Expand Down
9 changes: 0 additions & 9 deletions templates/galaxy_client_app.mako
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ ${ h.dumps( get_config_dict() )}
user_dict[ 'quota_percent' ] = trans.app.quota_agent.get_percent( trans=trans )
user_dict[ 'is_admin' ] = trans.user_is_admin

# tags used
users_api_controller = trans.webapp.api_controllers[ 'users' ]
tags_used = []
for tag in users_api_controller.get_user_tags_used( trans, user=trans.user ):
tag = escape( tag )
if tag:
tags_used.append( tag )
user_dict[ 'tags_used' ] = tags_used

return user_dict

usage = 0
Expand Down
5 changes: 2 additions & 3 deletions test/unit/app/managers/test_UserManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def test_views_and_keys(self):
self.assertKeys(serialized, self.user_serializer.views["summary"] + ["create_time"])

self.log("should be able to use keys on their own")
serialized = self.user_serializer.serialize_to_view(user, keys=["tags_used", "is_admin"])
self.assertKeys(serialized, ["tags_used", "is_admin"])
serialized = self.user_serializer.serialize_to_view(user, keys=["is_admin"])
self.assertKeys(serialized, ["is_admin"])

def test_serializers(self):
user = self.user_manager.create(**user2_data)
Expand All @@ -326,7 +326,6 @@ def test_serializers(self):
assert isinstance(serialized["total_disk_usage"], float)
assert isinstance(serialized["nice_total_disk_usage"], str)
assert isinstance(serialized["quota_percent"], (type(None), float))
assert isinstance(serialized["tags_used"], list)

self.log("serialized should jsonify well")
self.assertIsJsonifyable(serialized)
Expand Down
Loading