Skip to main content

WebCase User checks

Package to provide additional user check mechanics.

Installation

pip install wc-django-user-checks

In settings.py:

INSTALLED_APPS += [
  'wcd_uer_checks',
]

WCD_USER_CHECKS = {
  'REGISTRY' = 'wcd_user_checks.globals.registry', # default
  'DEFINITIONS' = None, # default
  'CACHE' = 'default', # default

  'DEFINITIONS' = [
    'wcd_user_checks.builtins.MANUAL_CHECK_DEFINITION', # Manual check reason
  ],
}

Usage

For all your interactions use client module. It has everything that you would need.

Simple check interaction

# Importing client
from wcd_user_checks import client
# Getting check definition
from wcd_user_checks.builtins import MANUAL_CHECK_DEFINITION

# Setting a check reason to an initial value(invalid).
client.set_check(user_id, MANUAL_CHECK_DEFINITION.reason)
# Getting a user state
state = client.get_state(user_id)
# It will be invalid
# > state.is_passed == False

# Setting a valid state value
client.set_check(user_id, MANUAL_CHECK_DEFINITION.reason, state=builtins.ManualCheckState.VALID)
# Will force user check state to become valid
state = client.get_state(user_id)
# > state.is_passed == True

Creating a custom checker

File: apps/another/checker.py

from wcd_user_checks import client
from wcd_user_checks.registry import CheckDefinition

# This state might be django's `models.TextChoices` or any other Enum.
class AnotherState(str, Enum):
  VALID = 'valid'
  PROCESS = 'process'
  INVALID = 'invalid'

# This is your checker definition object
ANOTHER = CheckDefinition(
  # Reason to check. Must be unique for the project.
  reason='ANOTHER',
  # States enum, that your check workflow could be resolved.
  states=AnotherState,
  # Initial state. Better to be invalid,
  initial_state=AnotherState.INVALID,
  # Inspector - function that checks whether the check is passed or not.
  inspector=lambda x: x.state == AnotherState.VALID
)

You may register this manually:

client.get_registry().register(ANOTHER)

Or by defining tha path to a definitions in settings.py:

WCD_USER_CHECKS_DEFINITIONS = [
  'wcd_user_checks.builtins.MANUAL_CHECK_DEFINITION', # Build in

  'apps.another.checker.ANOTHER', # Yours
]

Administrative panel

By default there will be a separate model to change user checks. But it might happen this to be not enough. An you'll need to add an inliner to a user model.

There is functionality for that:

admin.py

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as Base
from django.contrib.auth import get_user_model

# This inline here has a little bit more optimized user checks displaying.
from wcd_user_checks.admin import UserCheckInlineAdmin


UserModel = get_user_model()
admin.site.unregister(UserModel)


@admin.register(UserModel)
class UserAdmin(Base):
  inlines = Base.inlines + [UserCheckInlineAdmin]

TODO

  • [_] Middleware for user checks auto injection into request.
  • [_] Context manager for checks for templates injection.
  • [_] DRF permissions.
  • [_] DRF views maybe.
  • [_] Some simple view decorator to check user's ability to perform action.

Metadata

Release files for wc-django-user-checks 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wc-django-user-checks 0.1.8
File Size Uploaded Provenance
wc-django-user-checks-0.1.8.tar.gz 12.5 kB Without provenance Details

Release files / wc-django-user-checks-0.1.8.tar.gz

Download URL wc-django-user-checks-0.1.8.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dad9d02d0c06c1d61adb24339b48ec14e3f33299532e7b505b9f334c68e16453
BLAKE2b-256 checksum
How to use checksums
8ad0aca458ec8a1f639b863be97fa966ed902aebeee1b8aa6b8d06191d9407ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

Security for wc-django-user-checks 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page