Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
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
thies
uffd
Commits
93b09342
Commit
93b09342
authored
3 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Added api endpoint for mail aliases
parent
73a74ad7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
uffd/api/views.py
+24
-0
24 additions, 0 deletions
uffd/api/views.py
with
24 additions
and
0 deletions
uffd/api/views.py
+
24
−
0
View file @
93b09342
...
...
@@ -3,6 +3,7 @@ import functools
from
flask
import
Blueprint
,
jsonify
,
current_app
,
request
,
abort
from
uffd.user.models
import
User
,
Group
from
uffd.mail.models
import
Mail
from
uffd.session.views
import
login_get_user
,
login_ratelimit
bp
=
Blueprint
(
'
api
'
,
__name__
,
template_folder
=
'
templates
'
,
url_prefix
=
'
/api/v1/
'
)
...
...
@@ -93,3 +94,26 @@ def checkpassword():
login_ratelimit
.
log
(
username
)
return
jsonify
(
None
)
return
jsonify
(
generate_user_dict
(
user
))
def
generate_mail_dict
(
mail
):
return
{
'
name
'
:
mail
.
uid
,
'
receive_addresses
'
:
list
(
mail
.
receivers
),
'
destination_addresses
'
:
list
(
mail
.
destinations
)}
@bp.route
(
'
/getmails
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@apikey_required
(
'
getmails
'
)
def
getmails
():
if
len
(
request
.
values
)
>
1
:
abort
(
400
)
key
=
(
list
(
request
.
values
.
keys
())
or
[
None
])[
0
]
values
=
request
.
values
.
getlist
(
key
)
if
key
is
None
:
mails
=
Mail
.
query
.
all
()
elif
key
==
'
name
'
and
len
(
values
)
==
1
:
mails
=
Mail
.
query
.
filter_by
(
uid
=
values
[
0
]).
all
()
elif
key
==
'
receive_address
'
and
len
(
values
)
==
1
:
mails
=
Mail
.
query
.
filter_by
(
receivers
=
values
[
0
]).
all
()
elif
key
==
'
destination_address
'
and
len
(
values
)
==
1
:
mails
=
Mail
.
query
.
filter_by
(
destinations
=
values
[
0
]).
all
()
else
:
abort
(
400
)
return
jsonify
([
generate_mail_dict
(
mail
)
for
mail
in
mails
])
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