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
e80badbd
Commit
e80badbd
authored
4 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Reafactor the profile creation code
parent
81413106
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!20
Add 'remember me' button
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hiboo/profile/login.py
+26
-33
26 additions, 33 deletions
hiboo/profile/login.py
hiboo/service/forms.py
+1
-1
1 addition, 1 deletion
hiboo/service/forms.py
with
27 additions
and
34 deletions
hiboo/profile/login.py
+
26
−
33
View file @
e80badbd
...
...
@@ -24,55 +24,48 @@ def pick(service_uuid):
def
create
(
service_uuid
,
create_for
=
False
,
quick
=
False
):
service
=
models
.
Service
.
query
.
get
(
service_uuid
)
or
flask
.
abort
(
404
)
status
=
models
.
Profile
.
ACTIVE
is_admin
=
flask_login
.
current_user
.
is_admin
format
=
formats
[
service
.
profile_format
]
# If the admin passed a user uuid, use that one, otherwise ignore it
if
create_for
and
flask_login
.
current_user
.
is_admin
:
user
=
hiboo_user
.
get_user
(
intent
=
"
profile.create_for
"
,
create_for
=
None
)
else
:
user
=
flask_login
.
current_user
# Do not create profile for locked services
if
service
.
policy
==
models
.
Service
.
LOCKED
:
flask
.
flash
(
_
(
"
You cannot request a profile for this service
"
),
"
danger
"
)
user
=
hiboo_user
.
get_user
(
intent
=
"
profile.create_for
"
,
create_for
=
None
)
if
(
create_for
and
is_admin
)
else
flask_login
.
current_user
# Check that profile creation is allowed
profiles
=
models
.
Profile
.
filter
(
service
,
user
).
all
()
errors
=
[
error
for
check
,
error
in
(
(
service
.
policy
==
models
.
Service
.
LOCKED
,
_
(
"
You cannot request a profile for this service
"
)),
(
len
(
profiles
)
>
0
and
service
.
single_profile
,
_
(
"
You already own a profile for this service
"
)),
(
not
is_admin
and
service
.
policy
==
models
.
Service
.
RESERVED
,
_
(
"
You cannot request a profile for this service
"
)),
(
not
is_admin
and
len
(
profiles
)
>=
service
.
max_profiles
and
service
.
policy
!=
models
.
Service
.
BURST
,
_
(
"
Your reached the maximum number of profiles
"
))
)
if
check
]
if
errors
:
flask
.
flash
(
errors
[
0
],
"
danger
"
)
return
flask
.
redirect
(
flask
.
url_for
(
"
account.home
"
))
# Other restrictions do not apply to admins or managers
if
not
flask_login
.
current_user
.
is_admin
:
profiles
=
models
.
Profile
.
filter
(
service
,
user
).
all
()
# Do not create profile for locked services
if
service
.
policy
==
models
.
Service
.
RESERVED
:
flask
.
flash
(
_
(
"
You cannot request a profile for this service
"
),
"
danger
"
)
return
flask
.
redirect
(
flask
.
url_for
(
"
account.home
"
))
# Only burst services are allowed to exceed profile count
elif
len
(
profiles
)
>=
service
.
max_profiles
and
service
.
policy
!=
models
.
Service
.
BURST
:
flask
.
flash
(
_
(
"
Your reached the maximum number of profiles
"
),
"
danger
"
)
return
flask
.
redirect
(
flask
.
url_for
(
"
account.home
"
))
# Managed services and bursting accounts require approval
elif
len
(
profiles
)
>=
service
.
max_profiles
or
service
.
policy
==
models
.
Service
.
MANAGED
:
flask
.
flash
(
_
(
"
Your profile creation requires approval
"
),
"
warning
"
)
status
=
models
.
Profile
.
REQUEST
# Managed services and bursting accounts require approval
if
len
(
profiles
)
>=
service
.
max_profiles
or
service
.
policy
==
models
.
Service
.
MANAGED
:
flask
.
flash
(
_
(
"
Your profile creation requires approval
"
),
"
warning
"
)
status
=
models
.
Profile
.
REQUEST
# Initialize and validate the form before applying overrides
form
=
forms
.
ProfileForm
()
form
.
username
.
validators
=
format
.
validators
()
submit
=
form
.
validate_on_submit
()
# If this is a quick creation
, prefill
the
u
ser
name with a generated on
e
if
quick
:
# If this is a quick creation
or
the ser
vice prevents custom profile creation, force the usernam
e
if
quick
or
service
.
single_profile
:
for
username
in
format
.
alternatives
(
format
.
coalesce
(
user
.
username
)):
if
not
service
.
check_username
(
username
):
form
.
force_username
(
username
)
break
if
quick
:
form
.
hide_fields
()
# If same_username is enabled, enforce the username
if
service
.
same_username
:
form
.
force_username
(
user
.
username
)
# Handle the creation form
if
submit
:
if
service
.
check_username
(
form
.
username
.
data
):
flask
.
flash
(
_
(
"
A profile with that username exists already
"
),
"
danger
"
)
else
:
profile
=
models
.
Profile
(
)
profile
.
user
=
user
profile
.
service
=
service
profile
.
username
=
form
.
username
.
data
profile
.
comment
=
form
.
comment
.
data
profile
.
status
=
status
profile
=
models
.
Profile
(
user_uuid
=
user
.
uuid
,
service_uuid
=
service
.
uuid
,
username
=
form
.
username
.
data
,
comment
=
form
.
comment
.
data
,
status
=
status
)
models
.
db
.
session
.
add
(
profile
)
models
.
log
(
models
.
History
.
CREATE
,
profile
.
username
,
profile
.
comment
,
user
=
user
,
service
=
service
,
profile
=
profile
)
...
...
This diff is collapsed.
Click to expand it.
hiboo/service/forms.py
+
1
−
1
View file @
e80badbd
...
...
@@ -20,5 +20,5 @@ class ServiceForm(flask_wtf.FlaskForm):
[(
name
,
format
.
message
.
capitalize
())
for
name
,
format
in
profile
.
formats
.
items
()
if
name
]
)
)
s
ame_usernam
e
=
fields
.
BooleanField
(
_
(
'
Dis
able
per
-profile
username
'
))
s
ingle_profil
e
=
fields
.
BooleanField
(
_
(
'
En
able
single
-profile
behavior (no custom username, no additional profile)
'
))
submit
=
fields
.
SubmitField
(
_
(
'
Submit
'
))
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