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
577b5255
Commit
577b5255
authored
Apr 26, 2021
by
cbartondock
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/janeczku/calibre-web
parents
541dd6b5
97e4707f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
276 additions
and
149 deletions
+276
-149
admin.py
cps/admin.py
+76
-46
gmail.py
cps/services/gmail.py
+2
-0
main.css
cps/static/css/main.css
+4
-0
table.js
cps/static/js/table.js
+162
-83
mail.py
cps/tasks/mail.py
+1
-5
user_table.html
cps/templates/user_table.html
+31
-15
No files found.
cps/admin.py
View file @
577b5255
...
...
@@ -225,11 +225,23 @@ def edit_user_table():
languages
=
calibre_db
.
speaking_language
()
translations
=
babel
.
list_translations
()
+
[
LC
(
'en'
)]
allUser
=
ub
.
session
.
query
(
ub
.
User
)
tags
=
calibre_db
.
session
.
query
(
db
.
Tags
)
\
.
join
(
db
.
books_tags_link
)
\
.
join
(
db
.
Books
)
\
.
filter
(
calibre_db
.
common_filters
())
\
.
group_by
(
text
(
'books_tags_link.tag'
))
\
.
order_by
(
db
.
Tags
.
name
)
.
all
()
if
config
.
config_restricted_column
:
custom_values
=
calibre_db
.
session
.
query
(
db
.
cc_classes
[
config
.
config_restricted_column
])
.
all
()
else
:
custom_values
=
[]
if
not
config
.
config_anonbrowse
:
allUser
=
allUser
.
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ANONYMOUS
)
!=
constants
.
ROLE_ANONYMOUS
)
return
render_title_template
(
"user_table.html"
,
users
=
allUser
.
all
(),
tags
=
tags
,
custom_values
=
custom_values
,
translations
=
translations
,
languages
=
languages
,
visiblility
=
visibility
,
...
...
@@ -238,6 +250,7 @@ def edit_user_table():
title
=
_
(
u"Edit Users"
),
page
=
"usertable"
)
@
admi
.
route
(
"/ajax/listusers"
)
@
login_required
@
admin_required
...
...
@@ -332,7 +345,7 @@ def table_get_locale():
def
table_get_default_lang
():
languages
=
calibre_db
.
speaking_language
()
ret
=
list
()
ret
.
append
({
'value'
:
'all'
,
'text'
:
_
(
'Show All'
)})
ret
.
append
({
'value'
:
'all'
,
'text'
:
_
(
'Show All'
)})
for
lang
in
languages
:
ret
.
append
({
'value'
:
lang
.
lang_code
,
'text'
:
lang
.
name
})
return
json
.
dumps
(
ret
)
...
...
@@ -358,56 +371,55 @@ def edit_list_user(param):
vals
[
'field_index'
]
=
vals
[
'field_index'
][
0
]
if
'value'
in
vals
:
vals
[
'value'
]
=
vals
[
'value'
][
0
]
el
se
:
el
if
not
(
'value[]'
in
vals
)
:
return
""
for
user
in
users
:
try
:
vals
[
'value'
]
=
vals
[
'value'
]
.
strip
()
if
param
==
'name'
:
if
user
.
name
==
"Guest"
:
raise
Exception
(
_
(
"Guest Name can't be changed"
))
user
.
name
=
check_username
(
vals
[
'value'
])
elif
param
==
'email'
:
user
.
email
=
check_email
(
vals
[
'value'
])
elif
param
==
'kindle_mail'
:
user
.
kindle_mail
=
valid_email
(
vals
[
'value'
])
if
vals
[
'value'
]
else
""
elif
param
.
endswith
(
'role'
):
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
in
\
[
constants
.
ROLE_ADMIN
,
constants
.
ROLE_PASSWD
,
constants
.
ROLE_EDIT_SHELFS
]:
raise
Exception
(
_
(
"Guest can't have this role"
))
if
vals
[
'value'
]
==
'true'
:
user
.
role
|=
int
(
vals
[
'field_index'
])
else
:
if
int
(
vals
[
'field_index'
])
==
constants
.
ROLE_ADMIN
:
if
not
ub
.
session
.
query
(
ub
.
User
)
.
\
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ADMIN
)
==
constants
.
ROLE_ADMIN
,
ub
.
User
.
id
!=
user
.
id
)
.
count
():
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'
])
elif
param
.
startswith
(
'sidebar'
):
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
==
constants
.
SIDEBAR_READ_AND_UNREAD
:
raise
Exception
(
_
(
"Guest can't have this view"
))
if
vals
[
'value'
]
==
'true'
:
user
.
sidebar_view
|=
int
(
vals
[
'field_index'
])
if
param
in
[
'denied_tags'
,
'allowed_tags'
,
'allowed_column_value'
,
'denied_column_value'
]:
if
'value[]'
in
vals
:
setattr
(
user
,
param
,
prepare_tags
(
user
,
vals
[
'action'
][
0
],
param
,
vals
[
'value[]'
]))
else
:
user
.
sidebar_view
&=
~
int
(
vals
[
'field_index'
])
elif
param
==
'denied_tags'
:
user
.
denied_tags
=
vals
[
'value'
]
elif
param
==
'allowed_tags'
:
user
.
allowed_tags
=
vals
[
'value'
]
elif
param
==
'allowed_column_value'
:
user
.
allowed_column_value
=
vals
[
'value'
]
elif
param
==
'denied_column_value'
:
user
.
denied_column_value
=
vals
[
'value'
]
elif
param
==
'locale'
:
if
user
.
name
==
"Guest"
:
raise
Exception
(
_
(
"Guest's Locale is determined automatically and can't be set"
))
user
.
locale
=
vals
[
'value'
]
elif
param
==
'default_language'
:
user
.
default_language
=
vals
[
'value'
]
setattr
(
user
,
param
,
vals
[
'value'
]
.
strip
())
else
:
vals
[
'value'
]
=
vals
[
'value'
]
.
strip
()
if
param
==
'name'
:
if
user
.
name
==
"Guest"
:
raise
Exception
(
_
(
"Guest Name can't be changed"
))
user
.
name
=
check_username
(
vals
[
'value'
])
elif
param
==
'email'
:
user
.
email
=
check_email
(
vals
[
'value'
])
elif
param
==
'kindle_mail'
:
user
.
kindle_mail
=
valid_email
(
vals
[
'value'
])
if
vals
[
'value'
]
else
""
elif
param
.
endswith
(
'role'
):
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
in
\
[
constants
.
ROLE_ADMIN
,
constants
.
ROLE_PASSWD
,
constants
.
ROLE_EDIT_SHELFS
]:
raise
Exception
(
_
(
"Guest can't have this role"
))
if
vals
[
'value'
]
==
'true'
:
user
.
role
|=
int
(
vals
[
'field_index'
])
else
:
if
int
(
vals
[
'field_index'
])
==
constants
.
ROLE_ADMIN
:
if
not
ub
.
session
.
query
(
ub
.
User
)
.
\
filter
(
ub
.
User
.
role
.
op
(
'&'
)(
constants
.
ROLE_ADMIN
)
==
constants
.
ROLE_ADMIN
,
ub
.
User
.
id
!=
user
.
id
)
.
count
():
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'
])
elif
param
.
startswith
(
'sidebar'
):
if
user
.
name
==
"Guest"
and
int
(
vals
[
'field_index'
])
==
constants
.
SIDEBAR_READ_AND_UNREAD
:
raise
Exception
(
_
(
"Guest can't have this view"
))
if
vals
[
'value'
]
==
'true'
:
user
.
sidebar_view
|=
int
(
vals
[
'field_index'
])
else
:
user
.
sidebar_view
&=
~
int
(
vals
[
'field_index'
])
elif
param
==
'locale'
:
if
user
.
name
==
"Guest"
:
raise
Exception
(
_
(
"Guest's Locale is determined automatically and can't be set"
))
user
.
locale
=
vals
[
'value'
]
elif
param
==
'default_language'
:
user
.
default_language
=
vals
[
'value'
]
except
Exception
as
ex
:
log
.
debug_or_exception
(
ex
)
return
str
(
ex
),
400
ub
.
session_commit
()
return
""
...
...
@@ -483,6 +495,8 @@ def load_dialogtexts(element_id):
texts
[
"main"
]
=
_
(
'Are you sure you want to change visible book languages for selected user(s)?'
)
elif
element_id
==
"role"
:
texts
[
"main"
]
=
_
(
'Are you sure you want to change the selected role for the selected user(s)?'
)
elif
element_id
==
"restrictions"
:
texts
[
"main"
]
=
_
(
'Are you sure you want to change the selected restrictions for the selected user(s)?'
)
elif
element_id
==
"sidebar_view"
:
texts
[
"main"
]
=
_
(
'Are you sure you want to change the selected visibility restrictions for the selected user(s)?'
)
return
json
.
dumps
(
texts
)
...
...
@@ -629,6 +643,22 @@ def restriction_deletion(element, list_func):
return
','
.
join
(
elementlist
)
def
prepare_tags
(
user
,
action
,
tags_name
,
id_list
):
if
"tags"
in
tags_name
:
tags
=
calibre_db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
id
.
in_
(
id_list
))
.
all
()
new_tags_list
=
[
x
.
name
for
x
in
tags
]
else
:
tags
=
calibre_db
.
session
.
query
(
db
.
cc_classes
[
config
.
config_restricted_column
])
\
.
filter
(
db
.
cc_classes
[
config
.
config_restricted_column
]
.
id
.
in_
(
id_list
))
.
all
()
new_tags_list
=
[
x
.
value
for
x
in
tags
]
saved_tags_list
=
user
.
__dict__
[
tags_name
]
.
split
(
","
)
if
len
(
user
.
__dict__
[
tags_name
])
else
[]
if
action
==
"remove"
:
saved_tags_list
=
[
x
for
x
in
saved_tags_list
if
x
not
in
new_tags_list
]
else
:
saved_tags_list
.
extend
(
x
for
x
in
new_tags_list
if
x
not
in
saved_tags_list
)
return
","
.
join
(
saved_tags_list
)
@
admi
.
route
(
"/ajax/addrestriction/<int:res_type>"
,
defaults
=
{
"user_id"
:
0
},
methods
=
[
'POST'
])
@
admi
.
route
(
"/ajax/addrestriction/<int:res_type>/<int:user_id>"
,
methods
=
[
'POST'
])
@
login_required
...
...
cps/services/gmail.py
View file @
577b5255
...
...
@@ -61,6 +61,7 @@ def get_user_info(credentials):
return
user_info
.
get
(
'email'
,
""
)
def
send_messsage
(
token
,
msg
):
log
.
debug
(
"Start sending email via Gmail"
)
creds
=
Credentials
(
token
=
token
[
'token'
],
refresh_token
=
token
[
'refresh_token'
],
...
...
@@ -79,3 +80,4 @@ def send_messsage(token, msg):
body
=
{
'raw'
:
raw
}
(
service
.
users
()
.
messages
()
.
send
(
userId
=
'me'
,
body
=
body
)
.
execute
())
log
.
debug
(
"Email send successfully via Gmail"
)
cps/static/css/main.css
View file @
577b5255
...
...
@@ -15,6 +15,10 @@ body {
overflow
:
hidden
;
}
.myselect
{
overflow
:
visible
!important
;
}
#main
{
position
:
absolute
;
width
:
100%
;
...
...
cps/static/js/table.js
View file @
577b5255
This diff is collapsed.
Click to expand it.
cps/tasks/mail.py
View file @
577b5255
...
...
@@ -115,7 +115,6 @@ class TaskEmail(CalibreTask):
self
.
results
=
dict
()
def
prepare_message
(
self
):
log
.
debug
(
"prepare email message for sending"
)
message
=
MIMEMultipart
()
message
[
'to'
]
=
self
.
recipent
message
[
'from'
]
=
self
.
settings
[
"mail_from"
]
...
...
@@ -171,11 +170,10 @@ class TaskEmail(CalibreTask):
# redirect output to logfile on python2 on python3 debugoutput is caught with overwritten
# _print_debug function
if
sys
.
version_info
<
(
3
,
0
):
log
.
debug
(
"Redirect output on python2 for email"
)
org_smtpstderr
=
smtplib
.
stderr
smtplib
.
stderr
=
logger
.
StderrLogger
(
'worker.smtp'
)
log
.
debug
(
"Start send email"
)
log
.
debug
(
"Start send
ing
email"
)
if
use_ssl
==
2
:
self
.
asyncSMTP
=
EmailSSL
(
self
.
settings
[
"mail_server"
],
self
.
settings
[
"mail_port"
],
timeout
=
timeout
)
...
...
@@ -188,7 +186,6 @@ class TaskEmail(CalibreTask):
if
use_ssl
==
1
:
self
.
asyncSMTP
.
starttls
()
if
self
.
settings
[
"mail_password"
]:
log
.
debug
(
"Login to email server"
)
self
.
asyncSMTP
.
login
(
str
(
self
.
settings
[
"mail_login"
]),
str
(
self
.
settings
[
"mail_password"
]))
# Convert message to something to send
...
...
@@ -196,7 +193,6 @@ class TaskEmail(CalibreTask):
gen
=
Generator
(
fp
,
mangle_from_
=
False
)
gen
.
flatten
(
msg
)
log
.
debug
(
"Sending email"
)
self
.
asyncSMTP
.
sendmail
(
self
.
settings
[
"mail_from"
],
self
.
recipent
,
fp
.
getvalue
())
self
.
asyncSMTP
.
quit
()
self
.
_handleSuccess
()
...
...
cps/templates/user_table.html
View file @
577b5255
{% extends "layout.html" %}
{% macro user_table_row(parameter, edit_text, show_text, validate,
button=False, id=0
) -%}
{% macro user_table_row(parameter, edit_text, show_text, validate,
elements=False
) -%}
<th
data-field=
"{{ parameter }}"
id=
"{{ parameter }}"
data-name=
"{{ parameter }}"
data-visible=
"{{visiblility.get(parameter)}}"
...
...
@@ -11,8 +11,22 @@
data-sortable=
"true"
{%
endif
%}
{%
if
validate
%}
data-edit-validate=
"{{ _('This Field is Required') }}"
{%
endif
%}
>
{% if button %}
<!--div><button data-id="{{id}}" data-toggle="modal" data-target="#restrictModal" class="btn btn-default button_head disabled" aria-disabled="true">{{edit_text}}</button></div-->
<br>
{% if elements %}
<div
class=
"multi_select"
>
<select
class=
"multi_selector"
id=
"{{ parameter }}"
data-live-search=
"true"
data-style=
"btn-default"
data-dropup-auto=
"false"
aria-disabled=
"true"
multiple
disabled
>
{% for tag in elements %}
<option
class=
"tags_click"
value=
"{{tag.id}}"
>
{% if tag.name %}{{tag.name}}{% else %}{{tag.value}}{% endif %}
</option>
{% endfor %}
</select>
<div
class=
"btn-group btn-group-justified"
role=
"group"
>
<div
class=
"btn-group"
role=
"group"
>
<div
class=
"multi_head btn btn-default hidden"
data-set=
"remove"
data-name=
"{{parameter}}"
aria-disabled=
"true"
>
{{_('Remove')}}
</div>
</div>
<div
class=
"btn-group"
role=
"group"
>
<div
class=
"multi_head btn btn-default hidden"
data-set=
"add"
data-name=
"{{parameter}}"
aria-disabled=
"true"
>
{{_('Add')}}
</div>
</div>
</div>
</div>
{% endif %}
{{ show_text }}
</th>
...
...
@@ -25,14 +39,14 @@
data-formatter=
"checkboxFormatter"
>
<div
class=
"form-check"
>
<div>
<label>
<input
type=
"radio"
class=
"check_head"
data-val=
{{value.get(array_field)}}
name=
"options_{{array_field}}"
data-name=
"{{parameter}}"
disabled
>
{{_('Deny')}}
</label>
<input
type=
"radio"
class=
"check_head"
data-
set=
"false"
data-
val=
{{value.get(array_field)}}
name=
"options_{{array_field}}"
data-name=
"{{parameter}}"
disabled
>
{{_('Deny')}}
</div>
<div>
<label>
<input
type=
"radio"
class=
"check_head"
data-val=
{{value.get(array_field)}}
name=
"options_{{array_field}}"
data-name=
"{{parameter}}"
disabled
>
{{_('Allow')}}
</label>
<input
type=
"radio"
class=
"check_head"
data-
set=
"true"
data-
val=
{{value.get(array_field)}}
name=
"options_{{array_field}}"
data-name=
"{{parameter}}"
disabled
>
{{_('Allow')}}
</div>
</div>
{{show_text}}
...
...
@@ -51,6 +65,7 @@
{%
if
validate
%}
data-edit-validate=
"{{ _('This Field is Required') }}"
{%
endif
%}
>
<div>
<select
id=
"select_{{ parameter }}"
class=
"header_select"
disabled=
""
>
<option
value=
"none"
>
{{ _('Select...') }}
</option>
<option
value=
"all"
>
{{ _('Show All') }}
</option>
{% for language in languages %}
<option
value=
"{{language.lang_code}}"
>
{{language.name}}
</option>
...
...
@@ -87,6 +102,7 @@
{% block header %}
<link
href=
"{{ url_for('static', filename='css/libs/bootstrap-table.min.css') }}"
rel=
"stylesheet"
>
<link
href=
"{{ url_for('static', filename='css/libs/bootstrap-editable.css') }}"
rel=
"stylesheet"
>
<link
href=
"{{ url_for('static', filename='css/libs/bootstrap-select.min.css') }}"
rel=
"stylesheet"
>
{% endblock %}
{% block body %}
<h2
class=
"{{page}}"
>
{{_(title)}}
</h2>
...
...
@@ -107,10 +123,10 @@
{{ user_table_row('kindle_mail', _('Enter Kindle E-mail Address'), _('Kindle E-mail'), false) }}
{{ user_select_translations('locale', url_for('admin.table_get_locale'), _('Locale'), true) }}
{{ user_select_languages('default_language', url_for('admin.table_get_default_lang'), _('Visible Book Languages'), true) }}
{{ user_table_row('denied_tags', _("Edit Denied Tags"), _("Denied Tags"), false, t
rue, 0
) }}
{{ user_table_row('allowed_tags', _("Edit Allowed Tags"), _("Allowed Tags"), false, t
rue, 1
) }}
{{ user_table_row('allowed_column_value', _("Edit Allowed Column Values"), _("Allowed Column Values"), false,
true, 2
) }}
{{ user_table_row('denied_column_value', _("Edit Denied Column Values"), _("Denied Columns Values"), false,
true, 3
) }}
{{ user_table_row('denied_tags', _("Edit Denied Tags"), _("Denied Tags"), false, t
ags
) }}
{{ user_table_row('allowed_tags', _("Edit Allowed Tags"), _("Allowed Tags"), false, t
ags
) }}
{{ user_table_row('allowed_column_value', _("Edit Allowed Column Values"), _("Allowed Column Values"), false,
custom_values
) }}
{{ user_table_row('denied_column_value', _("Edit Denied Column Values"), _("Denied Columns Values"), false,
custom_values
) }}
{{ user_checkbox_row("role", "admin_role", _('Admin'), visiblility, all_roles)}}
{{ user_checkbox_row("role", "passwd_role", _('Change Password'), visiblility, all_roles)}}
{{ user_checkbox_row("role", "upload_role",_('Upload'), visiblility, all_roles)}}
...
...
@@ -151,7 +167,7 @@
<script
src=
"{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/libs/bootstrap-select.min.js')}}"
></script>
<script
src=
"{{ url_for('static', filename='js/table.js') }}"
></script>
<script>
</script>
{% endblock %}
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