diff --git a/lib/galaxy/managers/users.py b/lib/galaxy/managers/users.py index 0d53703b0550..ec902bc59fce 100644 --- a/lib/galaxy/managers/users.py +++ b/lib/galaxy/managers/users.py @@ -12,7 +12,6 @@ from markupsafe import escape from sqlalchemy import ( and_, - desc, exc, func, true, @@ -26,7 +25,6 @@ util, ) from galaxy.managers import ( - api_keys, base, deletable, ) @@ -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 @@ -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: @@ -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()} diff --git a/lib/galaxy/webapps/base/controller.py b/lib/galaxy/webapps/base/controller.py index 8ddd2ef49e94..e581491bf002 100644 --- a/lib/galaxy/webapps/base/controller.py +++ b/lib/galaxy/webapps/base/controller.py @@ -24,7 +24,6 @@ ) from galaxy.datatypes.interval import ChromatinInteractions from galaxy.managers import ( - api_keys, base as managers_base, configuration, users, @@ -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.""" diff --git a/lib/galaxy/webapps/galaxy/controllers/user.py b/lib/galaxy/webapps/galaxy/controllers/user.py index 59d72c209804..985fdc60badd 100644 --- a/lib/galaxy/webapps/galaxy/controllers/user.py +++ b/lib/galaxy/webapps/galaxy/controllers/user.py @@ -29,7 +29,6 @@ ) from galaxy.webapps.base.controller import ( BaseUIController, - CreatesApiKeysMixin, UsesFormDefinitionsMixin, ) from ..api import depends @@ -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 diff --git a/lib/tool_shed/webapp/controllers/user.py b/lib/tool_shed/webapp/controllers/user.py index 45649b05fb69..1d8a4ba7fb87 100644 --- a/lib/tool_shed/webapp/controllers/user.py +++ b/lib/tool_shed/webapp/controllers/user.py @@ -8,6 +8,7 @@ util, web, ) +from galaxy.managers.api_keys import ApiKeyManager from galaxy.security.validate_user_input import ( validate_email, validate_password, @@ -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(