Skip to content

Commit

Permalink
Find user by drupal ID or name
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Jan 25, 2023
1 parent 0a98bd3 commit d2606b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
28 changes: 20 additions & 8 deletions ckanext/drupal_idp/logic/action.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
from __future__ import annotations

from sqlalchemy import or_

import ckan.plugins.toolkit as tk

from ckanext.toolbelt.decorators import Collector

import ckanext.drupal_idp.utils as utils

action, get_actions = Collector("drupal_idp").split()



@action
@tk.side_effect_free
def user_show(context, data_dict):
tk.check_access('drupal_idp_user_show', dict(context), data_dict)
id: utils.DrupalId = tk.get_or_bust(data_dict, 'id')
User = context['model'].User
tk.check_access("drupal_idp_user_show", dict(context), data_dict)
id: utils.DrupalId = tk.get_or_bust(data_dict, "id")

User = context["model"].User

user = (
context['session'].query(User.id)
.filter(User.plugin_extras["drupal_idp"]["id"].astext == str(id))
context["session"]
.query(User.id)
.filter(
or_(
User.plugin_extras["drupal_idp"]["id"].astext == str(id),
User.plugin_extras["drupal_idp"]["name"].astext == str(id),
)
)
.one_or_none()
)

if user is None:
raise tk.ObjectNotFound(tk._(f'DrupalId({id}) not found'))
data_dict['id'] = user.id
raise tk.ObjectNotFound(tk._(f"DrupalId({id}) not found"))

data_dict["id"] = user.id
return tk.get_action("user_show")(context, data_dict)


Expand Down
2 changes: 2 additions & 0 deletions ckanext/drupal_idp/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def details_data():
"email": "[email protected]",
"id": 123,
"roles": [],
"fields": {},
"avatar": None
}


Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-drupal-idp
version = 0.3.5
version = 0.4.5
description = Login to CKAN using Drupal session cookie
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -58,4 +58,4 @@ filterwarnings =
ignore::sqlalchemy.exc.SADeprecationWarning
ignore::sqlalchemy.exc.SAWarning
ignore::DeprecationWarning
addopts = --ckan-ini test.ini
addopts = --ckan-ini test.ini

0 comments on commit d2606b7

Please sign in to comment.