Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hiboo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ACIDES
Hiboo
Commits
1e0a6720
Commit
1e0a6720
authored
4 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Implement basic profile transitions
parent
6268e4db
No related branches found
No related tags found
1 merge request
!20
Add 'remember me' button
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hiboo/application/base.py
+28
-1
28 additions, 1 deletion
hiboo/application/base.py
hiboo/profile/__init__.py
+30
-8
30 additions, 8 deletions
hiboo/profile/__init__.py
hiboo/profile/admin.py
+4
-3
4 additions, 3 deletions
hiboo/profile/admin.py
with
62 additions
and
12 deletions
hiboo/application/base.py
+
28
−
1
View file @
1e0a6720
from
hiboo
import
sso
from
hiboo.service.forms
import
ServiceForm
as
BaseForm
from
flask_babel
import
lazy_gettext
as
_
import
flask
...
...
@@ -15,6 +14,8 @@ class BaseApplication(object):
@classmethod
def
register
(
cls
,
application_id
):
"""
Class decorator for registering new applications
"""
def
register_function
(
application
):
application
.
application_id
=
application_id
cls
.
registry
[
application_id
]
=
application
()
...
...
@@ -22,14 +23,40 @@ class BaseApplication(object):
return
register_function
def
render_details
(
self
,
service
):
"""
Render application details in the service details page
"""
return
flask
.
render_template
(
"
application_{}.html
"
.
format
(
self
.
application_id
),
service
=
service
)
def
fill_service
(
self
,
service
):
"""
Updates the service options dictionary based on SSO
parameters
"""
return
self
.
sso_protocol
.
fill_service
(
service
)
def
activate
(
self
,
profile
):
"""
Default activation behavior is doing nothing
"""
return
True
def
block
(
self
,
profile
):
"""
Default blocking behavior is doing nothing
"""
return
True
def
welcome
(
self
,
profile
):
"""
Defaul welcome behavior is doing nothing
"""
return
True
def
delete
(
self
,
profile
):
"""
Deleting an account generally requires application
implementation, so this needs to be overridden
"""
return
False
class
OIDCApplication
(
BaseApplication
):
sso_protocol
=
sso
.
oidc
...
...
This diff is collapsed.
Click to expand it.
hiboo/profile/__init__.py
+
30
−
8
View file @
1e0a6720
...
...
@@ -4,14 +4,7 @@ import flask
blueprint
=
flask
.
Blueprint
(
"
profile
"
,
__name__
,
template_folder
=
"
templates
"
)
import
flask_login
from
hiboo
import
models
,
utils
from
hiboo.profile
import
format
formats
=
format
.
ProfileFormat
.
registry
from
hiboo.profile
import
login
,
admin
,
forms
,
cli
from
hiboo
import
models
,
utils
,
application
def
get_profile
(
service
,
**
redirect_args
):
...
...
@@ -26,3 +19,32 @@ def get_profile(service, **redirect_args):
utils
.
force_redirect
(
utils
.
url_for
(
"
profile.pick
"
,
**
redirect_args
))
else
:
utils
.
force_redirect
(
utils
.
url_for
(
"
profile.create_quick
"
,
**
redirect_args
))
def
transition
(
profile
):
"""
Handle profile transitions as single-step workflows
"""
# These are coded as (current, target), None being a wildcard.
# All matches apply, including wildcards.
TRANSITIONS
=
{
(
None
,
models
.
Profile
.
BLOCKED
):
[
"
block
"
],
(
None
,
models
.
Profile
.
DELETED
):
[
"
delete
"
],
(
None
,
models
.
Profile
.
ACTIVE
):
[
"
activate
"
],
(
models
.
Profile
.
REQUEST
,
models
.
Profile
.
ACTIVE
):
[
"
welcome
"
],
}
app
=
application
.
registry
.
get
(
profile
.
service
.
application_id
)
functions
=
(
TRANSITIONS
.
get
((
profile
.
status
,
profile
.
transition
),
[])
+
TRANSITIONS
.
get
((
None
,
profile
.
transition
),
[])
+
TRANSITIONS
.
get
((
profile
.
status
,
None
),
[])
)
valid
=
any
([
hasattr
(
app
,
function
)
and
getattr
(
app
,
function
)(
profile
)
for
function
in
functions
])
if
valid
:
profile
.
status
=
profile
.
transition
profile
.
transition
=
None
from
hiboo.profile
import
login
,
admin
,
cli
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hiboo/profile/admin.py
+
4
−
3
View file @
1e0a6720
from
hiboo.profile
import
blueprint
from
hiboo.profile
import
blueprint
,
transition
from
hiboo
import
security
,
models
from
hiboo
import
user
as
hiboo_user
from
flask_babel
import
lazy_gettext
as
_
...
...
@@ -45,7 +45,7 @@ def set_status(profile_uuid, status):
if
status
not
in
(
models
.
Profile
.
ACTIVE
,
models
.
Profile
.
BLOCKED
):
flask
.
abort
(
403
)
profile
=
models
.
Profile
.
query
.
get
(
profile_uuid
)
or
flask
.
abort
(
404
)
profile
.
status
=
status
profile
.
transition
=
status
models
.
log
(
category
=
models
.
History
.
STATUS
,
value
=
status
,
...
...
@@ -55,8 +55,9 @@ def set_status(profile_uuid, status):
actor
=
flask_login
.
current_user
,
public
=
True
)
transition
(
profile
)
models
.
db
.
session
.
commit
()
flask
.
flash
(
_
(
"
Profile status
was successfully chang
ed
"
),
"
success
"
)
flask
.
flash
(
_
(
"
Profile status
change was request
ed
"
),
"
success
"
)
return
flask
.
redirect
(
flask
.
url_for
(
"
.details
"
,
profile_uuid
=
profile_uuid
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment