Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cbf4258f
authored
Feb 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-profile' into 'master'
Feature: Profile
parents
472b00ed
d2263896
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
2 deletions
+85
-2
circle/circle/settings/base.py
+4
-0
circle/dashboard/migrations/0002_auto__add_profile.py
+0
-0
circle/dashboard/migrations/0003_auto__add_field_profile_instance_limit.py
+0
-0
circle/dashboard/models.py
+65
-1
circle/dashboard/views.py
+16
-1
No files found.
circle/circle/settings/base.py
View file @
cbf4258f
...
@@ -382,3 +382,7 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
...
@@ -382,3 +382,7 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
'DJANGO_SAML_ATTRIBUTE_MAPPING'
,
'DJANGO_SAML_ATTRIBUTE_MAPPING'
,
'{"mail": ["email"], "sn": ["last_name"], '
'{"mail": ["email"], "sn": ["last_name"], '
'"uid": ["username"], "cn": ["first_name"]}'
))
'"uid": ["username"], "cn": ["first_name"]}'
))
SAML_CREATE_UNKNOWN_USER
=
True
if
get_env_variable
(
'DJANGO_SAML_ORG_ID_ATTRIBUTE'
,
False
)
!=
False
:
SAML_ORG_ID_ATTRIBUTE
=
get_env_variable
(
'DJANGO_SAML_ORG_ID_ATTRIBUTE'
)
circle/dashboard/migrations/0002_auto__add_profile.py
0 → 100644
View file @
cbf4258f
This diff is collapsed.
Click to expand it.
circle/dashboard/migrations/0003_auto__add_field_profile_instance_limit.py
0 → 100644
View file @
cbf4258f
This diff is collapsed.
Click to expand it.
circle/dashboard/models.py
View file @
cbf4258f
from
logging
import
getLogger
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.db.models
import
Model
,
ForeignKey
from
django.contrib.auth.signals
import
user_logged_in
from
django.db.models
import
(
Model
,
ForeignKey
,
OneToOneField
,
CharField
,
IntegerField
)
from
django.utils.translation
import
ugettext_lazy
as
_
from
vm.models
import
Instance
from
vm.models
import
Instance
logger
=
getLogger
(
__name__
)
class
Favourite
(
Model
):
class
Favourite
(
Model
):
instance
=
ForeignKey
(
Instance
)
instance
=
ForeignKey
(
Instance
)
user
=
ForeignKey
(
User
)
user
=
ForeignKey
(
User
)
class
Profile
(
Model
):
user
=
OneToOneField
(
User
)
preferred_language
=
CharField
(
verbose_name
=
_
(
'preferred language'
),
choices
=
settings
.
LANGUAGES
,
max_length
=
32
,
default
=
settings
.
LANGUAGE_CODE
,
blank
=
False
)
org_id
=
CharField
(
# may be populated from eduPersonOrgId field
unique
=
True
,
blank
=
True
,
null
=
True
,
max_length
=
64
,
help_text
=
_
(
'Unique identifier of the person, e.g. a student number.'
))
instance_limit
=
IntegerField
(
default
=
5
)
def
create_profile
(
sender
,
user
,
request
,
**
kwargs
):
if
not
user
.
pk
:
return
False
profile
,
created
=
Profile
.
objects
.
get_or_create
(
user
=
user
)
return
created
user_logged_in
.
connect
(
create_profile
)
if
hasattr
(
settings
,
'SAML_ORG_ID_ATTRIBUTE'
):
logger
.
debug
(
"Register save_org_id to djangosaml2 pre_user_save"
)
from
djangosaml2.signals
import
pre_user_save
def
save_org_id
(
sender
,
**
kwargs
):
logger
.
debug
(
"save_org_id called by
%
s"
,
sender
.
username
)
attributes
=
kwargs
.
pop
(
'attributes'
)
atr
=
settings
.
SAML_ORG_ID_ATTRIBUTE
try
:
value
=
attributes
[
atr
][
0
]
except
Exception
as
e
:
value
=
None
logger
.
info
(
"save_org_id couldn't find attribute.
%
s"
,
unicode
(
e
))
if
sender
.
pk
is
None
:
sender
.
save
()
logger
.
debug
(
"save_org_id saved user
%
s"
,
unicode
(
sender
))
profile
,
created
=
Profile
.
objects
.
get_or_create
(
user
=
sender
)
if
created
or
profile
.
org_id
!=
value
:
logger
.
info
(
"org_id of
%
s added to user
%
s's profile"
,
value
,
sender
.
username
)
profile
.
org_id
=
value
profile
.
save
()
else
:
logger
.
debug
(
"org_id of
%
s already added to user
%
s's profile"
,
value
,
sender
.
username
)
return
False
pre_user_save
.
connect
(
save_org_id
)
else
:
logger
.
debug
(
"Do not register save_org_id to djangosaml2 pre_user_save"
)
circle/dashboard/views.py
View file @
cbf4258f
...
@@ -683,7 +683,6 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -683,7 +683,6 @@ class VmCreate(LoginRequiredMixin, TemplateView):
})
})
return
self
.
render_to_response
(
context
)
return
self
.
render_to_response
(
context
)
# TODO handle not ajax posts
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
self
.
form_class
(
request
.
POST
)
form
=
self
.
form_class
(
request
.
POST
)
if
not
form
.
is_valid
():
if
not
form
.
is_valid
():
...
@@ -691,6 +690,22 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -691,6 +690,22 @@ class VmCreate(LoginRequiredMixin, TemplateView):
post
=
form
.
cleaned_data
post
=
form
.
cleaned_data
user
=
request
.
user
user
=
request
.
user
try
:
limit
=
user
.
profile
.
instance_limit
except
Exception
as
e
:
logger
.
debug
(
'No profile or instance limit:
%
s'
,
e
)
else
:
current
=
Instance
.
active
.
filter
(
owner
=
user
)
.
count
()
logger
.
debug
(
'current use:
%
d, limit:
%
d'
,
current
,
limit
)
if
limit
<
current
:
messages
.
error
(
request
,
_
(
'Instance limit (
%
d) exceeded.'
)
%
limit
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
'/'
}),
content_type
=
"application/json"
)
else
:
return
redirect
(
'/'
)
template
=
post
[
'template'
]
template
=
post
[
'template'
]
if
not
template
.
has_level
(
request
.
user
,
'user'
):
if
not
template
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
raise
PermissionDenied
()
...
...
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