ability to add permissions on signup via social providers #7307
This commit is contained in:
parent
2bd8b67d02
commit
dc6555e31b
@ -568,6 +568,16 @@ system. See the corresponding
|
|||||||
|
|
||||||
Defaults to True
|
Defaults to True
|
||||||
|
|
||||||
|
#### [`SOCIALACCOUNT_DEFAULT_PERMISSIONS=<json>`](#SOCIALACCOUNT_DEFAULT_PERMISSIONS) {#SOCIALACCOUNT_DEFAULT_PERMISSIONS}
|
||||||
|
|
||||||
|
: By default, paperless doesn't add any permissions to users signed up via social account providers.
|
||||||
|
|
||||||
|
This can be adjusted by configuring a custom json array with
|
||||||
|
codenames of permissions being added to users on the signup via social account providers.
|
||||||
|
|
||||||
|
Defaults to `["view_uisettings"]`.
|
||||||
|
|
||||||
|
|
||||||
#### [`PAPERLESS_ACCOUNT_ALLOW_SIGNUPS=<bool>`](#PAPERLESS_ACCOUNT_ALLOW_SIGNUPS) {#PAPERLESS_ACCOUNT_ALLOW_SIGNUPS}
|
#### [`PAPERLESS_ACCOUNT_ALLOW_SIGNUPS=<bool>`](#PAPERLESS_ACCOUNT_ALLOW_SIGNUPS) {#PAPERLESS_ACCOUNT_ALLOW_SIGNUPS}
|
||||||
|
|
||||||
: Allow users to signup for a new Paperless-ngx account.
|
: Allow users to signup for a new Paperless-ngx account.
|
||||||
|
@ -7,6 +7,8 @@ from django.conf import settings
|
|||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
class CustomAccountAdapter(DefaultAccountAdapter):
|
class CustomAccountAdapter(DefaultAccountAdapter):
|
||||||
def is_open_for_signup(self, request):
|
def is_open_for_signup(self, request):
|
||||||
@ -87,3 +89,14 @@ class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
|
|||||||
"""
|
"""
|
||||||
# TODO: If default global permissions are implemented, should also be here
|
# TODO: If default global permissions are implemented, should also be here
|
||||||
return super().populate_user(request, sociallogin, data) # pragma: no cover
|
return super().populate_user(request, sociallogin, data) # pragma: no cover
|
||||||
|
|
||||||
|
def save_user(self, request, sociallogin, form=None):
|
||||||
|
"""
|
||||||
|
Add the default permissions to users on signup
|
||||||
|
"""
|
||||||
|
user = super().save_user(request, sociallogin, form)
|
||||||
|
default_permission_codenames = getattr(settings, "SOCIALACCOUNT_DEFAULT_PERMISSIONS", [])
|
||||||
|
permissions = apps.get_model("auth", "Permission").objects.filter( codename__in=default_permission_codenames )
|
||||||
|
for permission in permissions:
|
||||||
|
user.user_permissions.add(permission.id)
|
||||||
|
return user
|
||||||
|
@ -459,6 +459,14 @@ SOCIALACCOUNT_AUTO_SIGNUP = __get_boolean("PAPERLESS_SOCIAL_AUTO_SIGNUP")
|
|||||||
SOCIALACCOUNT_PROVIDERS = json.loads(
|
SOCIALACCOUNT_PROVIDERS = json.loads(
|
||||||
os.getenv("PAPERLESS_SOCIALACCOUNT_PROVIDERS", "{}"),
|
os.getenv("PAPERLESS_SOCIALACCOUNT_PROVIDERS", "{}"),
|
||||||
)
|
)
|
||||||
|
SOCIALACCOUNT_DEFAULT_PERMISSIONS = list(
|
||||||
|
json.loads(
|
||||||
|
os.getenv(
|
||||||
|
"PAPERLESS_SOCIALACCOUNT_DEFAULT_PERMISSIONS",
|
||||||
|
'["view_uisettings"]',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[Paperless-ngx] "
|
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[Paperless-ngx] "
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user