Skip to content

Commit

Permalink
fix: deleted user remains deleted during initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Dec 14, 2023
1 parent 6b88342 commit b2b69f2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
21 changes: 10 additions & 11 deletions ckanext/drupal_idp/cli.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import click

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

import ckanext.drupal_idp.utils as utils

def get_commands():
return [drupal_idp]


@click.group(short_help='ckanext-drupal-idp CLI')
@click.group(short_help="ckanext-drupal-idp CLI")
def drupal_idp():
"""
"""
""" """
pass


@drupal_idp.group()
def user():
"""User management
"""
"""User management"""
pass


@user.command()
def list():
"""List all users with DrupalID
"""
users = model.Session.query(model.User).filter(model.User.plugin_extras.has_key('drupal_idp'))
"""List all users with DrupalID"""
users = model.Session.query(model.User).filter(
model.User.plugin_extras.has_key("drupal_idp")
)
for user in users:
click.echo(f"{user.name}:")
extras = user.plugin_extras['drupal_idp']
extras = user.plugin_extras["drupal_idp"]
click.echo(f"\tID: {extras['id']}")
click.echo(f"\tRoles: {', '.join(extras['roles'])}")
click.echo(f"\tEmail: {extras['email']}")
Expand Down
7 changes: 3 additions & 4 deletions ckanext/drupal_idp/drupal.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from __future__ import annotations

import logging
import abc
import logging
import os
from typing import Any, Dict, Iterable, List, Optional
from typing import Any, Iterable, List, Optional

import sqlalchemy as sa
from sqlalchemy.engine import Row
from sqlalchemy.exc import OperationalError, ProgrammingError

import ckan.plugins.toolkit as tk
from ckan.exceptions import CkanConfigurationException

from ckanext.drupal_idp import utils, config
from ckanext.drupal_idp import config, utils

log = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion ckanext/drupal_idp/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_some_endpoint(app):
def test_some_action():
pass
"""
import ckanext.drupal_idp.plugin as plugin


def test_plugin():
Expand Down
23 changes: 18 additions & 5 deletions ckanext/drupal_idp/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from __future__ import annotations
import dataclasses

import base64
import dataclasses
import hashlib
import logging
import six
import secrets
from urllib.parse import unquote
from typing import Any, Dict, List, Optional, TypedDict
from urllib.parse import unquote

import six
from typing_extensions import NotRequired

import ckan.lib.munge as munge
import ckan.model as model
import ckan.plugins.toolkit as tk
import ckan.lib.munge as munge
from . import signals, config

from . import config, signals

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -222,6 +225,8 @@ def get_or_create_from_details(details: Details) -> UserDict:
Raises:
ValidationError if email or username is not unique
"""

user: dict[str, Any] | None
try:
user = tk.get_action("drupal_idp_user_show")(
{"ignore_auth": True}, {"id": details.id}
Expand All @@ -230,6 +235,14 @@ def get_or_create_from_details(details: Details) -> UserDict:
user = _get_by_email(details.email)
if user:
user = synchronize(user, details)

if user and user["state"] == "deleted":
userobj = model.User.get(user["id"])
if userobj:
userobj.activate()
model.Session.commit()
user["state"] = userobj.state

return user or _create_from_details(details)


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-drupal-idp
version = 0.4.6a3
version = 0.4.6a4
description = Login to CKAN using Drupal session cookie
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit b2b69f2

Please sign in to comment.