Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
4120a2c0
Verified
Commit
4120a2c0
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Link/Create persons if a matching one is found for a user
Closes
#332
parent
6563144f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!414
Resolve "Allow automatic linking of persons to account by e-mail address"
Pipeline
#5017
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/preferences.py
+19
-0
19 additions, 0 deletions
aleksis/core/preferences.py
aleksis/core/util/middlewares.py
+21
-2
21 additions, 2 deletions
aleksis/core/util/middlewares.py
with
40 additions
and
2 deletions
aleksis/core/preferences.py
+
19
−
0
View file @
4120a2c0
...
...
@@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _
from
dynamic_preferences.preferences
import
Section
from
dynamic_preferences.types
import
(
BooleanPreference
,
ChoicePreference
,
FilePreference
,
MultipleChoicePreference
,
...
...
@@ -170,6 +171,24 @@ class PrimaryGroupField(ChoicePreference):
return
Person
.
syncable_fields_choices
()
@site_preferences_registry.register
class
AutoCreatePerson
(
BooleanPreference
):
section
=
account
name
=
"
auto_create_person
"
default
=
False
required
=
False
verbose_name
=
_
(
"
Automatically create new persons for new users
"
)
@site_preferences_registry.register
class
AutoLinkPerson
(
BooleanPreference
):
section
=
account
name
=
"
auto_link_person
"
default
=
False
required
=
False
verbose_name
=
_
(
"
Automatically link existing persons to new users by their e-mail address
"
)
@site_preferences_registry.register
class
SchoolName
(
StringPreference
):
section
=
school
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/util/middlewares.py
+
21
−
2
View file @
4120a2c0
...
...
@@ -2,8 +2,8 @@ from typing import Callable
from
django.http
import
HttpRequest
,
HttpResponse
from
..models
import
DummyPerson
from
.core_helpers
import
has_person
from
..models
import
DummyPerson
,
Person
from
.core_helpers
import
get_site_preferences
,
has_person
class
EnsurePersonMiddleware
:
...
...
@@ -12,6 +12,9 @@ class EnsurePersonMiddleware:
It is needed to inject a dummy person to a superuser that would otherwise
not have an associated person, in order they can get their account set up
without external help.
In addition, if configured in preferences, it auto-creates or links persons
to regular users if they match.
"""
def
__init__
(
self
,
get_response
:
Callable
):
...
...
@@ -25,6 +28,22 @@ class EnsurePersonMiddleware:
first_name
=
request
.
user
.
first_name
,
last_name
=
request
.
user
.
last_name
)
request
.
user
.
person
=
dummy_person
else
:
prefs
=
get_site_preferences
()
if
prefs
.
get
(
"
account__auto_link_person
"
,
False
):
person
,
created
=
Person
.
objects
.
get_or_create
(
email
=
request
.
user
.
email
,
defaults
=
{
"
first_name
"
:
request
.
user
.
first_name
,
"
last_name
"
:
request
.
user
.
last_name
,
},
)
if
created
and
not
prefs
.
get
(
"
account__auto_create_person
"
):
return
person
.
user
=
request
.
user
person
.
save
()
response
=
self
.
get_response
(
request
)
return
response
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment