mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-20 13:36:05 -05:00
feat: approve users, edit users through manage users page (#1383)
This commit is contained in:
10
cms/auth_backends.py
Normal file
10
cms/auth_backends.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
|
||||
class ApprovalBackend(ModelBackend):
|
||||
def user_can_authenticate(self, user):
|
||||
can_authenticate = super().user_can_authenticate(user)
|
||||
if can_authenticate and settings.USERS_NEEDS_TO_BE_APPROVED and not user.is_superuser:
|
||||
return getattr(user, 'is_approved', False)
|
||||
return can_authenticate
|
||||
23
cms/middleware.py
Normal file
23
cms/middleware.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.conf import settings
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class ApprovalMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
if settings.USERS_NEEDS_TO_BE_APPROVED and request.user.is_authenticated and not request.user.is_superuser and not getattr(request.user, 'is_approved', False):
|
||||
allowed_paths = [
|
||||
reverse('approval_required'),
|
||||
reverse('account_logout'),
|
||||
]
|
||||
if request.path not in allowed_paths:
|
||||
if request.path.startswith('/api/'):
|
||||
return JsonResponse({'detail': 'User account not approved.'}, status=403)
|
||||
return redirect('approval_required')
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
@@ -128,6 +128,10 @@ USERS_CAN_SELF_REGISTER = True
|
||||
|
||||
RESTRICTED_DOMAINS_FOR_USER_REGISTRATION = ["xxx.com", "emaildomainwhatever.com"]
|
||||
|
||||
# by default users do not need to be approved. If this is set to True, then new users
|
||||
# will have to be approved before they can login successfully
|
||||
USERS_NEEDS_TO_BE_APPROVED = False
|
||||
|
||||
# Comma separated list of domains: ["organization.com", "private.organization.com", "org2.com"]
|
||||
# Empty list disables.
|
||||
ALLOWED_DOMAINS_FOR_USER_REGISTRATION = []
|
||||
@@ -501,6 +505,10 @@ ALLOW_CUSTOM_MEDIA_URLS = False
|
||||
# Whether to allow anonymous users to list all users
|
||||
ALLOW_ANONYMOUS_USER_LISTING = True
|
||||
|
||||
# Who can see the members page
|
||||
# valid choices are all, editors, admins
|
||||
CAN_SEE_MEMBERS_PAGE = "all"
|
||||
|
||||
# Maximum number of media a user can upload
|
||||
NUMBER_OF_MEDIA_USER_CAN_UPLOAD = 100
|
||||
|
||||
@@ -517,6 +525,9 @@ USER_CAN_TRANSCRIBE_VIDEO = True
|
||||
# Whisper transcribe options - https://github.com/openai/whisper
|
||||
WHISPER_MODEL = "base"
|
||||
|
||||
# show a custom text in the sidebar footer, otherwise the default will be shown if this is empty
|
||||
SIDEBAR_FOOTER_TEXT = ""
|
||||
|
||||
try:
|
||||
# keep a local_settings.py file for local overrides
|
||||
from .local_settings import * # noqa
|
||||
@@ -558,3 +569,12 @@ except ImportError:
|
||||
if GLOBAL_LOGIN_REQUIRED:
|
||||
auth_index = MIDDLEWARE.index("django.contrib.auth.middleware.AuthenticationMiddleware")
|
||||
MIDDLEWARE.insert(auth_index + 1, "django.contrib.auth.middleware.LoginRequiredMiddleware")
|
||||
|
||||
|
||||
if USERS_NEEDS_TO_BE_APPROVED:
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'cms.auth_backends.ApprovalBackend',
|
||||
'allauth.account.auth_backends.AuthenticationBackend',
|
||||
)
|
||||
auth_index = MIDDLEWARE.index("django.contrib.auth.middleware.AuthenticationMiddleware")
|
||||
MIDDLEWARE.insert(auth_index + 1, "cms.middleware.ApprovalMiddleware")
|
||||
|
||||
@@ -1 +1 @@
|
||||
VERSION = "6.5.2"
|
||||
VERSION = "6.6.0"
|
||||
|
||||
Reference in New Issue
Block a user