Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
067fb1b0
Commit
067fb1b0
authored
Apr 07, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent delete Guest user and redirect to admin page after user delete
parent
78071841
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
admin.py
cps/admin.py
+12
-5
No files found.
cps/admin.py
View file @
067fb1b0
...
...
@@ -1185,10 +1185,14 @@ def _handle_edit_user(to_save, content, languages, translations, kobo_support):
if
to_save
.
get
(
"delete"
):
if
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ADMIN
)
==
constants
.
ROLE_ADMIN
,
ub
.
User
.
id
!=
content
.
id
)
.
count
():
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
id
==
content
.
id
)
.
delete
()
ub
.
session_commit
()
flash
(
_
(
u"User '
%(nick)
s' deleted"
,
nick
=
content
.
name
),
category
=
"success"
)
return
redirect
(
url_for
(
'admin.admin'
))
if
content
.
name
!=
"Guest"
:
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
id
==
content
.
id
)
.
delete
()
ub
.
session_commit
()
flash
(
_
(
u"User '
%(nick)
s' deleted"
,
nick
=
content
.
name
),
category
=
"success"
)
return
redirect
(
url_for
(
'admin.admin'
))
else
:
flash
(
_
(
u"Can't delete Guest User"
),
category
=
"error"
)
return
redirect
(
url_for
(
'admin.admin'
))
else
:
flash
(
_
(
u"No admin user remaining, can't delete user"
,
nick
=
content
.
name
),
category
=
"error"
)
return
redirect
(
url_for
(
'admin.admin'
))
...
...
@@ -1255,6 +1259,7 @@ def _handle_edit_user(to_save, content, languages, translations, kobo_support):
except
OperationalError
:
ub
.
session
.
rollback
()
flash
(
_
(
u"Settings DB is not Writeable"
),
category
=
"error"
)
return
""
@
admi
.
route
(
"/admin/user/new"
,
methods
=
[
"GET"
,
"POST"
])
...
...
@@ -1350,7 +1355,9 @@ def edit_user(user_id):
kobo_support
=
feature_support
[
'kobo'
]
and
config
.
config_kobo_sync
if
request
.
method
==
"POST"
:
to_save
=
request
.
form
.
to_dict
()
_handle_edit_user
(
to_save
,
content
,
languages
,
translations
,
kobo_support
)
resp
=
_handle_edit_user
(
to_save
,
content
,
languages
,
translations
,
kobo_support
)
if
resp
:
return
resp
return
render_title_template
(
"user_edit.html"
,
translations
=
translations
,
languages
=
languages
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment