Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Postbuero
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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®
Onboarding
AlekSIS-App-Postbuero
Commits
7afd06a1
Verified
Commit
7afd06a1
authored
2 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement alias models
parent
63ad3e48
No related branches found
No related tags found
1 merge request
!12
Implement Webmilter alias resolution
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/postbuero/migrations/0005_group_address.py
+70
-0
70 additions, 0 deletions
aleksis/apps/postbuero/migrations/0005_group_address.py
aleksis/apps/postbuero/models.py
+75
-2
75 additions, 2 deletions
aleksis/apps/postbuero/models.py
with
145 additions
and
2 deletions
aleksis/apps/postbuero/migrations/0005_group_address.py
0 → 100644
+
70
−
0
View file @
7afd06a1
# Generated by Django 3.2.15 on 2022-08-10 16:29
import
aleksis.core.managers
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
contenttypes
'
,
'
0002_remove_content_type_name
'
),
(
'
sites
'
,
'
0002_alter_domain_unique
'
),
(
'
core
'
,
'
0041_update_gender_choices
'
),
(
'
postbuero
'
,
'
0004_domain_is_public
'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
MailAlias
'
,
fields
=
[
(
'
id
'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
extended_data
'
,
models
.
JSONField
(
default
=
dict
,
editable
=
False
)),
(
'
local_part
'
,
models
.
CharField
(
max_length
=
64
,
verbose_name
=
'
Local part
'
)),
(
'
domain
'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'
postbuero.maildomain
'
,
verbose_name
=
'
Domain
'
)),
(
'
polymorphic_ctype
'
,
models
.
ForeignKey
(
editable
=
False
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'
polymorphic_postbuero.mailalias_set+
'
,
to
=
'
contenttypes.contenttype
'
)),
(
'
site
'
,
models
.
ForeignKey
(
default
=
1
,
editable
=
False
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'
sites.site
'
)),
],
options
=
{
'
verbose_name
'
:
'
Mail alias
'
,
'
verbose_name_plural
'
:
'
Mail alias
'
,
},
managers
=
[
(
'
objects
'
,
aleksis
.
core
.
managers
.
PolymorphicCurrentSiteManager
()),
],
),
migrations
.
CreateModel
(
name
=
'
MailAliasForPerson
'
,
fields
=
[
(
'
mailalias_ptr
'
,
models
.
OneToOneField
(
auto_created
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
parent_link
=
True
,
primary_key
=
True
,
serialize
=
False
,
to
=
'
postbuero.mailalias
'
)),
(
'
person
'
,
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
SET_NULL
,
related_name
=
'
local_mail_aliases
'
,
to
=
'
core.person
'
,
verbose_name
=
'
Person
'
)),
],
options
=
{
'
verbose_name
'
:
'
Mail alias for a person
'
,
'
verbose_name_plural
'
:
'
Mail aliases for persons
'
,
},
bases
=
(
'
postbuero.mailalias
'
,),
managers
=
[
(
'
objects
'
,
aleksis
.
core
.
managers
.
PolymorphicCurrentSiteManager
()),
],
),
migrations
.
CreateModel
(
name
=
'
MailAliasForGroup
'
,
fields
=
[
(
'
mailalias_ptr
'
,
models
.
OneToOneField
(
auto_created
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
parent_link
=
True
,
primary_key
=
True
,
serialize
=
False
,
to
=
'
postbuero.mailalias
'
)),
(
'
group
'
,
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
SET_NULL
,
related_name
=
'
local_mail_aliases
'
,
to
=
'
core.group
'
,
verbose_name
=
'
Group
'
)),
],
options
=
{
'
verbose_name
'
:
'
Mail alias for a group
'
,
'
verbose_name_plural
'
:
'
Mail aliases for groups
'
,
},
bases
=
(
'
postbuero.mailalias
'
,),
managers
=
[
(
'
objects
'
,
aleksis
.
core
.
managers
.
PolymorphicCurrentSiteManager
()),
],
),
migrations
.
AddConstraint
(
model_name
=
'
mailalias
'
,
constraint
=
models
.
UniqueConstraint
(
fields
=
(
'
local_part
'
,
'
domain
'
),
name
=
'
unique_alias_per_domain
'
),
),
]
This diff is collapsed.
Click to expand it.
aleksis/apps/postbuero/models.py
+
75
−
2
View file @
7afd06a1
from
django.db
import
models
from
django.db
import
models
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.mixins
import
ExtensibleModel
,
ExtensiblePolymorphicModel
from
aleksis.core.models
import
Person
from
aleksis.core.models
import
Group
,
Person
class
MailDomain
(
ExtensibleModel
):
class
MailDomain
(
ExtensibleModel
):
...
@@ -40,3 +40,76 @@ class MailAddress(ExtensibleModel):
...
@@ -40,3 +40,76 @@ class MailAddress(ExtensibleModel):
fields
=
[
"
local_part
"
,
"
domain
"
],
name
=
"
unique_local_part_per_domain
"
fields
=
[
"
local_part
"
,
"
domain
"
],
name
=
"
unique_local_part_per_domain
"
)
)
]
]
class
MailAlias
(
ExtensiblePolymorphicModel
):
domain
=
models
.
ForeignKey
(
MailDomain
,
verbose_name
=
_
(
"
Domain
"
),
on_delete
=
models
.
CASCADE
)
local_part
=
models
.
CharField
(
verbose_name
=
_
(
"
Local part
"
),
max_length
=
64
)
def
__str__
(
self
)
->
str
:
return
f
"
{
self
.
local_part
}
@
{
self
.
domain
}
"
def
resolve
(
self
,
**
kwargs
):
raise
NotImplementedError
(
"
You must use the concrete model to resovle the alias.
"
)
class
Meta
:
verbose_name
=
_
(
"
Mail alias
"
)
verbose_name_plural
=
_
(
"
Mail alias
"
)
constraints
=
[
models
.
UniqueConstraint
(
fields
=
[
"
local_part
"
,
"
domain
"
],
name
=
"
unique_alias_per_domain
"
)
]
class
MailAliasForPerson
(
MailAlias
):
person
=
models
.
ForeignKey
(
Person
,
verbose_name
=
_
(
"
Person
"
),
null
=
True
,
on_delete
=
models
.
SET_NULL
,
related_name
=
"
local_mail_aliases
"
,
)
def
resolve
(
self
,
guardians
:
bool
=
False
):
"""
Resolve alias to the e-mail address of this person or its guardians.
"""
if
not
self
.
person
:
return
[]
if
guardians
:
return
list
(
self
.
person
.
guardians
.
all
().
values_list
(
"
email
"
,
flat
=
True
))
return
[
self
.
person
.
email
]
class
Meta
:
verbose_name
=
_
(
"
Mail alias for a person
"
)
verbose_name_plural
=
_
(
"
Mail aliases for persons
"
)
class
MailAliasForGroup
(
MailAlias
):
group
=
models
.
ForeignKey
(
Group
,
verbose_name
=
_
(
"
Group
"
),
null
=
True
,
on_delete
=
models
.
SET_NULL
,
related_name
=
"
local_mail_aliases
"
,
)
def
resolve
(
self
,
guardians
:
bool
=
False
,
owners
:
bool
=
False
):
"""
Resolve alias to the e-mail addresses of this group
'
s members, owners, or their guardians.
"""
if
not
self
.
group
:
return
[]
if
owners
:
pq
=
self
.
group
.
owners
.
all
()
else
:
pq
=
self
.
group
.
members
.
all
()
if
guardians
:
pq
=
Person
.
objects
.
filter
(
children__in
=
pq
)
return
list
(
pq
.
values_list
(
"
email
"
,
flat
=
True
))
class
Meta
:
verbose_name
=
_
(
"
Mail alias for a group
"
)
verbose_name_plural
=
_
(
"
Mail aliases for groups
"
)
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