Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a6ace944
authored
Apr 04, 2021
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add group import from JSON to GroupProfile model
parent
71c1adc9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
11 deletions
+44
-11
circle/dashboard/models.py
+44
-11
No files found.
circle/dashboard/models.py
View file @
a6ace944
...
@@ -17,14 +17,15 @@
...
@@ -17,14 +17,15 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
datetime
import
timedelta
import
json
from
itertools
import
chain
from
hashlib
import
md5
from
hashlib
import
md5
from
logging
import
getLogger
from
logging
import
getLogger
from
datetime
import
timedelta
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
,
Permission
from
django.contrib.auth.signals
import
user_logged_in
from
django.contrib.auth.signals
import
user_logged_in
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
(
from
django.db.models
import
(
Model
,
ForeignKey
,
OneToOneField
,
CharField
,
IntegerField
,
TextField
,
Model
,
ForeignKey
,
OneToOneField
,
CharField
,
IntegerField
,
TextField
,
...
@@ -36,20 +37,16 @@ from django.utils import timezone
...
@@ -36,20 +37,16 @@ from django.utils import timezone
from
django.utils.html
import
escape
from
django.utils.html
import
escape
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django_sshkey.models
import
UserKey
from
django_sshkey.models
import
UserKey
from
django.core.exceptions
import
ObjectDoesNotExist
from
itertools
import
chain
from
sizefield.models
import
FileSizeField
from
jsonfield
import
JSONField
from
jsonfield
import
JSONField
from
model_utils.models
import
TimeFramedModel
,
TimeStampedModel
from
model_utils.fields
import
StatusField
from
model_utils
import
Choices
from
model_utils
import
Choices
from
model_utils.fields
import
StatusField
from
model_utils.models
import
TimeFramedModel
,
TimeStampedModel
from
sizefield.models
import
FileSizeField
from
acl.models
import
AclBase
from
acl.models
import
AclBase
from
common.models
import
HumanReadableObject
,
create_readable
,
Encoder
from
common.models
import
HumanReadableObject
,
create_readable
,
Encoder
from
vm.models.instance
import
ACCESS_METHODS
from
vm.models.instance
import
ACCESS_METHODS
from
.store_api
import
Store
,
NoStoreException
,
NotOkException
from
.store_api
import
Store
,
NoStoreException
,
NotOkException
from
.validators
import
connect_command_template_validator
from
.validators
import
connect_command_template_validator
...
@@ -323,6 +320,42 @@ class GroupProfile(AclBase):
...
@@ -323,6 +320,42 @@ class GroupProfile(AclBase):
return
reverse
(
'dashboard.views.group-detail'
,
return
reverse
(
'dashboard.views.group-detail'
,
kwargs
=
{
'pk'
:
self
.
group
.
pk
})
kwargs
=
{
'pk'
:
self
.
group
.
pk
})
@classmethod
def
create_from_json
(
cls
,
owner
,
json_data
):
group
=
Group
()
try
:
data
=
json
.
loads
(
json_data
)
group
.
name
=
data
[
"name"
]
group
.
save
()
profile
=
group
.
profile
profile
.
set_user_level
(
owner
,
"owner"
)
profile
.
description
=
data
[
"desc"
]
profile
.
org_id
=
data
[
"org_id"
]
profile
.
instance_limit
=
int
(
data
[
"instance_limit"
])
profile
.
template_instance_limit
=
int
(
data
[
"template_instance_limit"
])
profile
.
disk_quota
=
long
(
data
[
"disk_quota"
])
profile
.
save
()
for
org_id
in
data
[
"users"
]:
try
:
user
=
Profile
.
objects
.
get
(
org_id
=
org_id
)
.
user
user
.
groups
.
add
(
group
)
except
ObjectDoesNotExist
:
future_member
=
FutureMember
(
org_id
=
org_id
,
group
=
group
)
future_member
.
save
()
for
permission
in
data
[
"permissions"
]:
group
.
permissions
.
add
(
Permission
.
objects
.
get_by_natural_key
(
*
permission
)
)
return
group
.
profile
except
(
KeyError
,
ValueError
,
TypeError
):
if
group
.
id
is
not
None
:
group
.
delete
()
logger
.
error
(
"Invalid group JSON"
)
def
get_or_create_profile
(
self
):
def
get_or_create_profile
(
self
):
obj
,
created
=
GroupProfile
.
objects
.
get_or_create
(
group_id
=
self
.
pk
)
obj
,
created
=
GroupProfile
.
objects
.
get_or_create
(
group_id
=
self
.
pk
)
...
...
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