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
d32b2ca5
Commit
d32b2ca5
authored
Apr 12, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent traceback after delete user
flash message in case last admin role is removed #1938
parent
d0a89562
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
19 deletions
+26
-19
admin.py
cps/admin.py
+5
-3
table.js
cps/static/js/table.js
+20
-15
web.py
cps/web.py
+1
-1
No files found.
cps/admin.py
View file @
d32b2ca5
...
@@ -249,7 +249,7 @@ def list_users():
...
@@ -249,7 +249,7 @@ def list_users():
order
=
request
.
args
.
get
(
"order"
,
""
)
.
lower
()
order
=
request
.
args
.
get
(
"order"
,
""
)
.
lower
()
state
=
None
state
=
None
if
sort
==
"state"
:
if
sort
==
"state"
:
state
=
json
.
loads
(
request
.
args
.
get
(
"state"
))
state
=
json
.
loads
(
request
.
args
.
get
(
"state"
,
"[]"
))
if
sort
!=
"state"
and
order
:
if
sort
!=
"state"
and
order
:
order
=
text
(
sort
+
" "
+
order
)
order
=
text
(
sort
+
" "
+
order
)
...
@@ -356,7 +356,7 @@ def edit_list_user(param):
...
@@ -356,7 +356,7 @@ def edit_list_user(param):
user
.
email
=
check_email
(
vals
[
'value'
])
user
.
email
=
check_email
(
vals
[
'value'
])
elif
param
==
'kindle_mail'
:
elif
param
==
'kindle_mail'
:
user
.
kindle_mail
=
valid_email
(
vals
[
'value'
])
if
vals
[
'value'
]
else
""
user
.
kindle_mail
=
valid_email
(
vals
[
'value'
])
if
vals
[
'value'
]
else
""
elif
param
==
'role'
:
elif
param
.
endswith
(
'role'
)
:
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
in
\
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
in
\
[
constants
.
ROLE_ADMIN
,
constants
.
ROLE_PASSWD
,
constants
.
ROLE_EDIT_SHELFS
]:
[
constants
.
ROLE_ADMIN
,
constants
.
ROLE_PASSWD
,
constants
.
ROLE_EDIT_SHELFS
]:
raise
Exception
(
_
(
"Guest can't have this role"
))
raise
Exception
(
_
(
"Guest can't have this role"
))
...
@@ -367,7 +367,9 @@ def edit_list_user(param):
...
@@ -367,7 +367,9 @@ def edit_list_user(param):
if
not
ub
.
session
.
query
(
ub
.
User
)
.
\
if
not
ub
.
session
.
query
(
ub
.
User
)
.
\
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ADMIN
)
==
constants
.
ROLE_ADMIN
,
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ADMIN
)
==
constants
.
ROLE_ADMIN
,
ub
.
User
.
id
!=
user
.
id
)
.
count
():
ub
.
User
.
id
!=
user
.
id
)
.
count
():
return
_
(
u"No admin user remaining, can't remove admin role"
,
nick
=
user
.
name
),
400
return
Response
(
json
.
dumps
({
'type'
:
"danger"
,
'message'
:
_
(
u"No admin user remaining, can't remove admin role"
,
nick
=
user
.
name
)}),
mimetype
=
'application/json'
)
user
.
role
&=
~
int
(
vals
[
'field_index'
])
user
.
role
&=
~
int
(
vals
[
'field_index'
])
elif
param
==
'sidebar_view'
:
elif
param
==
'sidebar_view'
:
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
==
constants
.
SIDEBAR_READ_AND_UNREAD
:
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
==
constants
.
SIDEBAR_READ_AND_UNREAD
:
...
...
cps/static/js/table.js
View file @
d32b2ca5
...
@@ -612,25 +612,30 @@ function checkboxFormatter(value, row, index){
...
@@ -612,25 +612,30 @@ function checkboxFormatter(value, row, index){
function
checkboxChange
(
checkbox
,
userId
,
field
,
field_index
)
{
function
checkboxChange
(
checkbox
,
userId
,
field
,
field_index
)
{
$
.
ajax
({
$
.
ajax
({
method
:
"post"
,
method
:
"post"
,
url
:
window
.
location
.
pathname
+
"/../../ajax/editlistusers/"
+
field
,
url
:
window
.
location
.
pathname
+
"/../../ajax/editlistusers/"
+
field
,
data
:
{
"pk"
:
userId
,
"field_index"
:
field_index
,
"value"
:
checkbox
.
checked
}
data
:
{
"pk"
:
userId
,
"field_index"
:
field_index
,
"value"
:
checkbox
.
checked
},
/*<div className="editable-buttons">
success
:
function
(
data
)
{
<button type="button" className="btn btn-default btn-sm editable-cancel"><i
if
(
!
jQuery
.
isEmptyObject
(
data
))
{
className="glyphicon glyphicon-remove"></i></button>
$
(
"#flash_success"
).
remove
();
</div>*/
$
(
"#flash_danger"
).
remove
();
/*<div className="editable-error-block help-block" style="">Text to show</div>*/
$
(
".navbar"
).
after
(
'<div class="row-fluid text-center" style="margin-top: -20px;">'
+
});
'<div id="flash_'
+
data
.
type
+
'" class="alert alert-'
+
data
.
type
+
'">'
+
data
.
message
+
'</div>'
+
$
.
ajax
({
'</div>'
);
method
:
"get"
,
}
url
:
window
.
location
.
pathname
+
"/../../ajax/listusers"
,
$
.
ajax
({
async
:
true
,
method
:
"get"
,
timeout
:
900
,
url
:
window
.
location
.
pathname
+
"/../../ajax/listusers"
,
success
:
function
(
data
)
{
async
:
true
,
$
(
"#user-table"
).
bootstrapTable
(
"load"
,
data
);
timeout
:
900
,
success
:
function
(
data
)
{
$
(
"#user-table"
).
bootstrapTable
(
"load"
,
data
);
}
});
}
}
});
});
}
}
function
deactivateHeaderButtons
(
e
)
{
function
deactivateHeaderButtons
(
e
)
{
$
(
"#user_delete_selection"
).
addClass
(
"disabled"
);
$
(
"#user_delete_selection"
).
addClass
(
"disabled"
);
$
(
"#user_delete_selection"
).
attr
(
"aria-disabled"
,
true
);
$
(
"#user_delete_selection"
).
attr
(
"aria-disabled"
,
true
);
...
...
cps/web.py
View file @
d32b2ca5
...
@@ -761,7 +761,7 @@ def list_books():
...
@@ -761,7 +761,7 @@ def list_books():
state
=
None
state
=
None
if
sort
==
"state"
:
if
sort
==
"state"
:
state
=
json
.
loads
(
request
.
args
.
get
(
"state"
))
state
=
json
.
loads
(
request
.
args
.
get
(
"state"
,
"[]"
))
if
sort
!=
"state"
and
order
:
if
sort
!=
"state"
and
order
:
order
=
[
text
(
sort
+
" "
+
order
)]
order
=
[
text
(
sort
+
" "
+
order
)]
...
...
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