Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
168ecda9
Commit
168ecda9
authored
Apr 30, 2018
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for fetching Launchpad teams
parent
1f79737b
Pipeline
#74
passed with stage
in 0 seconds
Changes
5
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
454 additions
and
3 deletions
+454
-3
setup.py
setup.py
+1
-0
uitwww/auth.py
uitwww/auth.py
+33
-3
uitwww/data/permissions.yml
uitwww/data/permissions.yml
+7
-0
uitwww/third_party/__init__.py
uitwww/third_party/__init__.py
+0
-0
uitwww/third_party/openid_teams.py
uitwww/third_party/openid_teams.py
+413
-0
No files found.
setup.py
View file @
168ecda9
...
...
@@ -43,6 +43,7 @@ setuptools.setup(
packages
=
[
"uitwww"
,
"uitwww.third_party"
],
entry_points
=
{
...
...
uitwww/auth.py
View file @
168ecda9
...
...
@@ -18,6 +18,10 @@ import uuid
import
flask
import
flask_openid
import
pkg_resources
import
yaml
from
uitwww.third_party
import
openid_teams
class
SessionError
(
BaseException
):
...
...
@@ -63,12 +67,27 @@ class Sessions:
self
.
db
.
update
(
"DELETE FROM auth_sessions WHERE id = ?;"
,
id
)
class
Permissions
:
def
__init__
(
self
):
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
"data/permissions.yml"
)
self
.
config
=
yaml
.
load
(
raw
.
decode
(
"utf-8"
))
def
allowed_teams
(
self
):
return
list
(
self
.
config
[
"teams"
].
keys
())
def
prepare_blueprint
(
app
):
"""Prepare the auth blueprint"""
bp
=
flask
.
Blueprint
(
"auth"
,
__name__
)
oid
=
flask_openid
.
OpenID
(
app
,
safe_roots
=
[])
oid
=
flask_openid
.
OpenID
(
app
,
safe_roots
=
[],
extension_responses
=
[
openid_teams
.
TeamsResponse
],
)
sessions
=
Sessions
(
app
.
db
)
permissions
=
Permissions
()
@
app
.
before_request
def
check_auth
():
...
...
@@ -85,7 +104,12 @@ def prepare_blueprint(app):
@
oid
.
after_login
def
receive_openid
(
resp
):
flask
.
session
[
"auth"
]
=
sessions
.
create
(
resp
.
nickname
,
[])
teams
=
resp
.
extensions
[
"lp"
].
is_member
if
not
teams
or
teams
==
[
""
]:
flask
.
flash
(
"Non hai i permessi per accedere al sito."
,
"error"
)
return
flask
.
redirect
(
flask
.
url_for
(
"pages.index"
))
flask
.
session
[
"auth"
]
=
sessions
.
create
(
resp
.
nickname
,
teams
)
flask
.
flash
(
"Benvenuto %s!"
%
resp
.
nickname
,
"success"
)
return
flask
.
redirect
(
flask
.
url_for
(
"pages.index"
))
...
...
@@ -93,7 +117,13 @@ def prepare_blueprint(app):
@
oid
.
loginhandler
def
login
():
if
"auth_name"
not
in
flask
.
g
:
return
oid
.
try_login
(
"https://login.ubuntu.com/+openid"
,
ask_for
=
[
"nickname"
])
return
oid
.
try_login
(
"https://login.ubuntu.com/+openid"
,
ask_for
=
[
"nickname"
],
extensions
=
[
openid_teams
.
TeamsRequest
(
permissions
.
allowed_teams
())
],
)
else
:
flask
.
flash
(
"Hai già effettuato l'accesso!"
,
"info"
)
return
flask
.
redirect
(
flask
.
url_for
(
"pages.index"
))
...
...
uitwww/data/permissions.yml
0 → 100644
View file @
168ecda9
permissions
:
[]
teams
:
ubuntu-it-www
:
"
*"
ubuntu-it-council
:
"
*"
ubuntu-it-members
:
[]
ubuntu-it-newsletter
:
[]
uitwww/third_party/__init__.py
0 → 100644
View file @
168ecda9
uitwww/third_party/openid_teams.py
0 → 100644
View file @
168ecda9
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