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
554bc6aa
Commit
554bc6aa
authored
Apr 29, 2016
by
Jan B
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from cervinko/feature-rights-management
add user-permission management
parents
f7e86804
38330799
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
294 additions
and
133 deletions
+294
-133
config.py
cps/config.py
+4
-0
detail.html
cps/templates/detail.html
+1
-1
layout.html
cps/templates/layout.html
+2
-2
user_edit.html
cps/templates/user_edit.html
+23
-5
user_list.html
cps/templates/user_list.html
+11
-1
ub.py
cps/ub.py
+134
-105
web.py
cps/web.py
+119
-19
No files found.
cps/config.py
View file @
554bc6aa
...
...
@@ -60,6 +60,7 @@ TITLE_REGEX = check_setting_str(CFG, 'Advanced', 'TITLE_REGEX', '^(A|The|An|Der|
DEVELOPMENT
=
bool
(
check_setting_int
(
CFG
,
'Advanced'
,
'DEVELOPMENT'
,
0
))
PUBLIC_REG
=
bool
(
check_setting_int
(
CFG
,
'Advanced'
,
'PUBLIC_REG'
,
0
))
UPLOADING
=
bool
(
check_setting_int
(
CFG
,
'Advanced'
,
'UPLOADING'
,
0
))
ANO_SHOW_BOOKS
=
bool
(
check_setting_int
(
CFG
,
'Advanced'
,
'ANO_SHOW_BOOKS'
,
0
))
SYS_ENCODING
=
"UTF-8"
...
...
@@ -78,6 +79,8 @@ configval["DEVELOPMENT"] = DEVELOPMENT
configval
[
"TITLE_REGEX"
]
=
TITLE_REGEX
configval
[
"PUBLIC_REG"
]
=
PUBLIC_REG
configval
[
"UPLOADING"
]
=
UPLOADING
configval
[
"ANO_SHOW_BOOKS"
]
=
ANO_SHOW_BOOKS
def
save_config
(
configval
):
new_config
=
ConfigObj
()
...
...
@@ -94,6 +97,7 @@ def save_config(configval):
new_config
[
'Advanced'
][
'DEVELOPMENT'
]
=
int
(
configval
[
"DEVELOPMENT"
])
new_config
[
'Advanced'
][
'PUBLIC_REG'
]
=
int
(
configval
[
"PUBLIC_REG"
])
new_config
[
'Advanced'
][
'UPLOADING'
]
=
int
(
configval
[
"UPLOADING"
])
new_config
[
'Advanced'
][
'ANO_SHOW_BOOKS'
]
=
int
(
configval
[
"ANO_SHOW_BOOKS"
])
new_config
.
write
()
return
"Saved"
...
...
cps/templates/detail.html
View file @
554bc6aa
...
...
@@ -154,7 +154,7 @@
</div>
{% endif %}
{% if g.user.role %}
{% if g.user.role
_edit()
%}
<div
class=
"btn-toolbar"
role=
"toolbar"
>
<div
class=
"btn-group"
role=
"group"
aria-label=
"Edit/Delete book"
>
<a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
class=
"btn btn-sm btn-warning"
role=
"button"
><span
class=
"glyphicon glyphicon-edit"
></span>
Edit metadata
</a>
...
...
cps/templates/layout.html
View file @
554bc6aa
...
...
@@ -63,7 +63,7 @@
</ul>
<ul
class=
"nav navbar-nav navbar-right"
id=
"main-nav"
>
{% if g.user.is_authenticated() %}
{% if g.user.role
%}
{% if g.user.role
_upload() or g.user.role_admin()
%}
{% if g.allow_upload %}
<li>
<form
id=
"form-upload"
class=
"navbar-form"
action=
"{{ url_for('upload') }}"
method=
"post"
enctype=
"multipart/form-data"
>
...
...
@@ -74,7 +74,7 @@
</li>
{% endif %}
{% endif %}
{% if g.user.role %}
{% if g.user.role
_admin()
%}
<li><a
href=
"{{url_for('user_list')}}"
><span
class=
"glyphicon glyphicon-dashboard"
></span>
Admin
</a></li>
{% endif %}
<li><a
href=
"{{url_for('profile')}}"
><span
class=
"glyphicon glyphicon-user"
></span>
{{g.user.nickname}}
</a></li>
...
...
cps/templates/user_edit.html
View file @
554bc6aa
...
...
@@ -3,7 +3,7 @@
<div
class=
"discover"
>
<h1>
{{title}}
</h1>
<form
role=
"form"
method=
"POST"
>
{% if g.user and g.user.role and new_user %}
{% if g.user and g.user.role
_admin()
and new_user %}
<div
class=
"form-group required"
>
<label
for=
"nickname"
>
Username
</label>
<input
type=
"text"
class=
"form-control"
name=
"nickname"
id=
"nickname"
value=
"{{ content.nickname if content.nickname != None }}"
>
...
...
@@ -13,21 +13,39 @@
<label
for=
"email"
>
Email address
</label>
<input
type=
"email"
class=
"form-control"
name=
"email"
id=
"email"
value=
"{{ content.email if content.email != None }}"
required
>
</div>
{% if g.user and g.user.role_passwd() or g.user.role_admin()%}
<div
class=
"form-group"
>
<label
for=
"password"
>
Password
</label>
<input
type=
"password"
class=
"form-control"
name=
"password"
id=
"password"
value=
""
>
</div>
{% endif %}
<div
class=
"form-group"
>
<label
for=
"kindle_mail"
>
Kindle E-Mail
</label>
<input
type=
"text"
class=
"form-control"
name=
"kindle_mail"
id=
"kindle_mail"
value=
"{{ content.kindle_mail if content.kindle_mail != None }}"
>
</div>
{% if g.user and g.user.role and not profile %}
{% if g.user and g.user.role_admin() and not profile %}
<div
class=
"form-group"
>
<label
for=
"admin_role"
>
Admin user
</label>
<input
type=
"checkbox"
name=
"admin_role"
id=
"admin_role"
{%
if
content
.
role_admin
()
%}
checked
{%
endif
%}
>
</div>
<div
class=
"form-group"
>
<label
for=
"download_role"
>
Allow Downloads
</label>
<input
type=
"checkbox"
name=
"download_role"
id=
"download_role"
{%
if
content
.
role_download
()
%}
checked
{%
endif
%}
>
</div>
<div
class=
"form-group"
>
<label
for=
"upload_role"
>
Allow Uploads
</label>
<input
type=
"checkbox"
name=
"upload_role"
id=
"upload_role"
{%
if
content
.
role_upload
()
%}
checked
{%
endif
%}
>
</div>
<div
class=
"form-group"
>
<label
for=
"edit_role"
>
Allow Edit
</label>
<input
type=
"checkbox"
name=
"edit_role"
id=
"edit_role"
{%
if
content
.
role_edit
()
%}
checked
{%
endif
%}
>
</div>
<div
class=
"form-group"
>
<label
for=
"
user_role"
>
Admin user
</label>
<input
type=
"checkbox"
name=
"
admin_user"
id=
"admin_user"
{%
if
content
.
role
%}
checked
{%
endif
%}
>
<label
for=
"
passwd_role"
>
Allow Changing Password
</label>
<input
type=
"checkbox"
name=
"
passwd_role"
id=
"passwd_role"
{%
if
content
.
role_passwd
()
%}
checked
{%
endif
%}
>
</div>
{% endif %}
{% if g.user and g.user.role and not profile and not new_user %}
{% if g.user and g.user.role
_admin()
and not profile and not new_user %}
<div
class=
"checkbox"
>
<label>
<input
type=
"checkbox"
name=
"delete"
>
Delete this user
...
...
cps/templates/user_list.html
View file @
554bc6aa
...
...
@@ -9,6 +9,11 @@
<th>
Kindle
</th>
<th>
DLS
</th>
<th>
Admin
</th>
<th>
Download
</th>
<th>
Upload
</th>
<th>
Edit
</th>
<th>
Passwd
</th>
</tr>
{% for user in content %}
<tr>
...
...
@@ -16,7 +21,12 @@
<td>
{{user.email}}
</td>
<td>
{{user.kindle_mail}}
</td>
<td>
{{user.downloads.count()}}
</td>
<td>
{% if user.role %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
<td>
{% if user.role_admin() %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
<td>
{% if user.role_download() %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
<td>
{% if user.role_upload() %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
<td>
{% if user.role_edit() %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
<td>
{% if user.role_passwd() %}
<span
class=
"glyphicon glyphicon-ok"
></span>
{% else %}
<span
class=
"glyphicon glyphicon-remove"
></span>
{% endif %}
</td>
{% endfor %}
</table>
<div
class=
"btn btn-default"
><a
href=
"{{url_for('new_user')}}"
>
Add new user
</a></div>
...
...
cps/ub.py
View file @
554bc6aa
...
...
@@ -14,6 +14,10 @@ Base = declarative_base()
ROLE_USER
=
0
ROLE_ADMIN
=
1
ROLE_DOWNLOAD
=
2
ROLE_UPLOAD
=
4
ROLE_EDIT
=
8
ROLE_PASSWD
=
16
DEFAULT_PASS
=
"admin123"
class
User
(
Base
):
...
...
@@ -31,6 +35,31 @@ class User(Base):
def
is_authenticated
(
self
):
return
True
def
role_admin
(
self
):
if
self
.
role
is
not
None
:
return
True
if
self
.
role
&
ROLE_ADMIN
==
ROLE_ADMIN
else
False
else
:
return
False
def
role_download
(
self
):
if
self
.
role
is
not
None
:
return
True
if
self
.
role
&
ROLE_DOWNLOAD
==
ROLE_DOWNLOAD
else
False
else
:
return
False
def
role_upload
(
self
):
if
self
.
role
is
not
None
:
return
True
if
self
.
role
&
ROLE_UPLOAD
==
ROLE_UPLOAD
else
False
else
:
return
False
def
role_edit
(
self
):
if
self
.
role
is
not
None
:
return
True
if
self
.
role
&
ROLE_EDIT
==
ROLE_EDIT
else
False
else
:
return
False
def
role_passwd
(
self
):
if
self
.
role
is
not
None
:
return
True
if
self
.
role
&
ROLE_PASSWD
==
ROLE_PASSWD
else
False
else
:
return
False
def
is_active
(
self
):
return
True
...
...
@@ -150,7 +179,7 @@ def get_mail_settings():
def
create_admin_user
():
user
=
User
()
user
.
nickname
=
"admin"
user
.
role
=
1
user
.
role
=
ROLE_USER
+
ROLE_ADMIN
+
ROLE_DOWNLOAD
+
ROLE_UPLOAD
+
ROLE_EDIT
+
ROLE_PASSWD
user
.
password
=
generate_password_hash
(
DEFAULT_PASS
)
session
.
add
(
user
)
...
...
cps/web.py
View file @
554bc6aa
This diff is collapsed.
Click to expand it.
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