Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
SFB 1288 - INF
nopaque
Commits
2efc9533
Commit
2efc9533
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add breadcrumbs to admin package
parent
b8e63d23
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/__init__.py
+1
-0
1 addition, 0 deletions
app/__init__.py
app/admin/__init__.py
+16
-1
16 additions, 1 deletion
app/admin/__init__.py
app/admin/json_routes.py
+22
-0
22 additions, 0 deletions
app/admin/json_routes.py
app/admin/routes.py
+11
-35
11 additions, 35 deletions
app/admin/routes.py
with
50 additions
and
36 deletions
app/__init__.py
+
1
−
0
View file @
2efc9533
...
...
@@ -61,6 +61,7 @@ def create_app(config: Config = Config) -> Flask:
init_error_handlers
(
app
)
from
.admin
import
bp
as
admin_blueprint
default_breadcrumb_root
(
admin_blueprint
,
'
.admin
'
)
app
.
register_blueprint
(
admin_blueprint
,
url_prefix
=
'
/admin
'
)
from
.api
import
bp
as
api_blueprint
...
...
This diff is collapsed.
Click to expand it.
app/admin/__init__.py
+
16
−
1
View file @
2efc9533
from
flask
import
Blueprint
from
flask_login
import
login_required
from
app.decorators
import
admin_required
bp
=
Blueprint
(
'
admin
'
,
__name__
)
from
.
import
routes
@bp.before_request
@login_required
@admin_required
def
before_request
():
'''
Ensures that the routes in this package can be visited only by users with
administrator privileges (login_required and admin_required).
'''
pass
from
.
import
json_routes
,
routes
This diff is collapsed.
Click to expand it.
app/admin/json_routes.py
0 → 100644
+
22
−
0
View file @
2efc9533
from
flask
import
current_app
from
threading
import
Thread
from
app
import
db
from
app.models
import
User
from
.
import
bp
@bp.route
(
'
/users/<hashid:user_id>/delete
'
,
methods
=
[
'
DELETE
'
])
def
delete_user
(
user_id
):
def
_delete_user
(
app
,
user_id
):
with
app
.
app_context
():
user
=
User
.
query
.
get
(
user_id
)
user
.
delete
()
db
.
session
.
commit
()
User
.
query
.
get_or_404
(
user_id
)
thread
=
Thread
(
target
=
_delete_user
,
args
=
(
current_app
.
_get_current_object
(),
user_id
)
)
thread
.
start
()
return
{},
202
This diff is collapsed.
Click to expand it.
app/admin/routes.py
+
11
−
35
View file @
2efc9533
from
flask
import
current_app
,
flash
,
redirect
,
render_template
,
url_for
from
flask_login
import
login_required
from
threading
import
Thread
from
flask
import
flash
,
redirect
,
render_template
,
url_for
from
flask_breadcrumbs
import
register_breadcrumb
from
app
import
db
,
hashids
from
app.decorators
import
admin_required
from
app.models
import
Role
,
User
,
UserSettingJobStatusMailNotificationLevel
from
app.users.forms
import
(
EditNotificationSettingsForm
)
from
app.users.forms
import
EditNotificationSettingsForm
from
app.users.forms
import
EditProfileSettingsForm
from
.
import
bp
from
.forms
import
AdminEditUserForm
@bp.before_request
@login_required
@admin_required
def
before_request
():
'''
Ensures that the routes in this package can be visited only by users with
administrator privileges (login_required and admin_required).
'''
pass
from
app.users.utils
import
(
user_endpoint_arguments_constructor
as
user_eac
,
user_dynamic_list_constructor
as
user_dlc
)
@bp.route
(
''
)
@register_breadcrumb
(
bp
,
'
.
'
,
'
<i class=
"
material-icons left
"
>admin_panel_settings</i>Administration
'
)
def
index
():
return
redirect
(
url_for
(
'
.users
'
))
@bp.route
(
'
/users
'
)
@register_breadcrumb
(
bp
,
'
.users
'
,
'
<i class=
"
material-icons left
"
>group</i>Users
'
)
def
users
():
users
=
[
x
.
to_json_serializeable
(
backrefs
=
True
)
for
x
in
User
.
query
.
all
()]
return
render_template
(
...
...
@@ -39,12 +30,14 @@ def users():
@bp.route
(
'
/users/<hashid:user_id>
'
)
@register_breadcrumb
(
bp
,
'
.users.entity
'
,
''
,
dynamic_list_constructor
=
user_dlc
)
def
user
(
user_id
):
user
=
User
.
query
.
get_or_404
(
user_id
)
return
render_template
(
'
admin/user.html.j2
'
,
title
=
'
User
'
,
user
=
user
)
@bp.route
(
'
/users/<hashid:user_id>/edit
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@register_breadcrumb
(
bp
,
'
.users.entity.edit
'
,
'
Edit
'
,
endpoint_arguments_constructor
=
user_eac
)
def
edit_user
(
user_id
):
user
=
User
.
query
.
get_or_404
(
user_id
)
admin_edit_user_form
=
AdminEditUserForm
(
...
...
@@ -92,20 +85,3 @@ def edit_user(user_id):
title
=
'
Edit user
'
,
user
=
user
)
@bp.route
(
'
/users/<hashid:user_id>/delete
'
,
methods
=
[
'
DELETE
'
])
def
delete_user
(
user_id
):
def
_delete_user
(
app
,
user_id
):
with
app
.
app_context
():
user
=
User
.
query
.
get
(
user_id
)
user
.
delete
()
db
.
session
.
commit
()
User
.
query
.
get_or_404
(
user_id
)
thread
=
Thread
(
target
=
_delete_user
,
args
=
(
current_app
.
_get_current_object
(),
user_id
)
)
thread
.
start
()
return
{},
202
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