Skip to content

Commit

Permalink
feat: configurable drupal login endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 9, 2023
1 parent d2606b7 commit 05aed2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
13 changes: 10 additions & 3 deletions ckanext/drupal_idp/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging

from ckan import model
import ckan.plugins as plugins
import ckan.plugins.toolkit as tk

from ckanext.drupal_idp.logic import action
from ckanext.drupal_idp.logic import auth
from ckanext.drupal_idp import helpers, utils, drupal, cli
from ckanext.drupal_idp import helpers, utils, drupal, cli, views

CONFIG_FOCE_SYNC = "ckanext.drupal_idp.synchronization.force"
CONFIG_SKIP_STATIC = "ckanext.drupal_idp.skip_static"
Expand All @@ -24,6 +25,10 @@ class DrupalIdpPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IActions)
plugins.implements(plugins.IAuthFunctions)
plugins.implements(plugins.IClick)
plugins.implements(plugins.IBlueprint)

def get_blueprint(self):
return views.get_blueprints()

# IClick

Expand Down Expand Up @@ -52,7 +57,6 @@ def identify(self):
The drupal session contains the drupal id of the logged in user.
We need to convert this to represent the ckan user."""


static = {
("static", "index"),
("webassets", "index"),
Expand Down Expand Up @@ -90,7 +94,10 @@ def identify(self):
)
return

tk.c.user = user["name"]
if tk.check_ckan_version("2.10"):
tk.login_user(model.User.get(user["name"]))
else:
tk.c.user = user["name"]

# IConfigurer

Expand Down
2 changes: 1 addition & 1 deletion ckanext/drupal_idp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def synchronize(user: UserDict, details: Details, force: bool = False) -> UserDi
if (
force or
userobj.email != details.email
or details.make_userdict()["plugin_extras"] != userobj.plugin_extras
or details.make_userdict()["plugin_extras"]["drupal_idp"] != userobj.plugin_extras.get("drupal_idp")
):
log.info(f"Synchronizing user {details.name}")
user = _attach_details(user["id"], details)
Expand Down
14 changes: 14 additions & 0 deletions ckanext/drupal_idp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import annotations

from flask import Blueprint
import ckan.plugins.toolkit as tk
bp = Blueprint("drupal_idp", __name__)


def get_blueprints():
return [bp]

@bp.route("/user/login/drupal-idp-redirect")
def redirect_to_drupal_login():
login_url = tk.config.get("ckanext.drupal_idp.login_url", "/user/login")
return tk.redirect_to(login_url)

0 comments on commit 05aed2d

Please sign in to comment.