Skip to content

Commit

Permalink
Cleanup unused code and mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Sep 30, 2022
1 parent 3f86751 commit fd299bd
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 49 deletions.
34 changes: 0 additions & 34 deletions lib/galaxy/managers/users.py
Expand Up @@ -12,7 +12,6 @@
from markupsafe import escape
from sqlalchemy import (
and_,
desc,
exc,
func,
true,
Expand All @@ -26,7 +25,6 @@
util,
)
from galaxy.managers import (
api_keys,
base,
deletable,
)
Expand Down Expand Up @@ -66,7 +64,6 @@ class UserManager(base.ModelManager, deletable.PurgableManagerMixin):
# most of which it may be unneccessary to have here

# TODO: incorp BaseAPIController.validate_in_users_and_groups
# TODO: incorp CreatesApiKeysMixin
# TODO: incorporate UsesFormDefinitionsMixin?
def __init__(self, app: BasicSharedApp):
self.model_class = app.model.User
Expand Down Expand Up @@ -358,15 +355,6 @@ def current_user(self, trans):
# TODO: trans
return trans.user

# ---- api keys
def create_api_key(self, user: model.User) -> model.APIKeys:
"""
Create and return an API key for `user`.
"""
# TODO: seems like this should return the model
# Also TODO: seems unused? drop and see what happens? -John
return api_keys.ApiKeyManager(self.app).create_api_key(user)

def user_can_do_run_as(self, user) -> bool:
run_as_users = [u for u in self.app.config.get("api_allow_run_as", "").split(",") if u]
if not run_as_users:
Expand All @@ -376,28 +364,6 @@ def user_can_do_run_as(self, user) -> bool:
can_do_run_as = user_in_run_as_users or user.bootstrap_admin_user
return can_do_run_as

# TODO: possibly move to ApiKeyManager
def valid_api_key(self, user):
"""
Return this most recent APIKey for this user or None if none have been created.
"""
query = self.session().query(model.APIKeys).filter_by(user=user).order_by(desc(model.APIKeys.create_time))
all = query.all()
if len(all):
return all[0]
return None

# TODO: possibly move to ApiKeyManager
def get_or_create_valid_api_key(self, user):
"""
Return this most recent APIKey for this user or create one if none have been
created.
"""
existing = self.valid_api_key(user)
if existing:
return existing
return self.create_api_key(self, user)

# ---- preferences
def preferences(self, user):
return {key: value for key, value in user.preferences.items()}
Expand Down
12 changes: 0 additions & 12 deletions lib/galaxy/webapps/base/controller.py
Expand Up @@ -24,7 +24,6 @@
)
from galaxy.datatypes.interval import ChromatinInteractions
from galaxy.managers import (
api_keys,
base as managers_base,
configuration,
users,
Expand Down Expand Up @@ -382,17 +381,6 @@ def __init__(self, extension, dtype, type_extension, mimetype, display_in_upload
#


class CreatesApiKeysMixin:
"""
Mixing centralizing logic for creating API keys for user objects.
Deprecated - please use api_keys.ApiKeyManager for new development.
"""

def create_api_key(self, trans, user: model.User) -> model.APIKeys:
return api_keys.ApiKeyManager(trans.app).create_api_key(user)


class SharableItemSecurityMixin:
"""Mixin for handling security for sharable items."""

Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/webapps/galaxy/controllers/user.py
Expand Up @@ -29,7 +29,6 @@
)
from galaxy.webapps.base.controller import (
BaseUIController,
CreatesApiKeysMixin,
UsesFormDefinitionsMixin,
)
from ..api import depends
Expand All @@ -41,7 +40,7 @@ def _filtered_registration_params_dict(payload):
return {k: v for (k, v) in payload.items() if k in ["email", "username", "password", "confirm", "subscribe"]}


class User(BaseUIController, UsesFormDefinitionsMixin, CreatesApiKeysMixin):
class User(BaseUIController, UsesFormDefinitionsMixin):
user_manager: users.UserManager = depends(users.UserManager)
installed_len_files = None

Expand Down
3 changes: 2 additions & 1 deletion lib/tool_shed/webapp/controllers/user.py
Expand Up @@ -8,6 +8,7 @@
util,
web,
)
from galaxy.managers.api_keys import ApiKeyManager
from galaxy.security.validate_user_input import (
validate_email,
validate_password,
Expand Down Expand Up @@ -313,7 +314,7 @@ def api_keys(self, trans, cntrller, **kwd):
message = escape(util.restore_text(params.get("message", "")))
status = params.get("status", "done")
if params.get("new_api_key_button", False):
self.create_api_key(trans, trans.user)
ApiKeyManager(trans.app).create_api_key(trans.user)
message = "Generated a new web API key"
status = "done"
return trans.fill_template(
Expand Down

0 comments on commit fd299bd

Please sign in to comment.