Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
670c8a6d
Commit
670c8a6d
authored
Aug 16, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复唯一认证
parent
2ac5786b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
9 deletions
+30
-9
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+0
-0
mixins.py
apps/orgs/mixins.py
+27
-6
forms.py
apps/users/forms.py
+2
-2
group.py
apps/users/models/group.py
+1
-1
No files found.
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
670c8a6d
No preview for this file type
apps/i18n/zh/LC_MESSAGES/django.po
View file @
670c8a6d
This diff is collapsed.
Click to expand it.
apps/orgs/mixins.py
View file @
670c8a6d
...
...
@@ -3,12 +3,15 @@
from
werkzeug.local
import
Local
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db.models
import
Q
from
django.shortcuts
import
redirect
from
django.forms
import
ModelForm
from
django.http.response
import
HttpResponseForbidden
from
django.core.exceptions
import
ValidationError
from
common.utils
import
get_logger
,
is_uuid
from
common.utils
import
get_logger
from
.utils
import
current_org
,
set_current_org
,
set_to_root_org
from
.models
import
Organization
...
...
@@ -26,15 +29,15 @@ class OrgManager(models.Manager):
def
get_queryset
(
self
):
queryset
=
super
(
OrgManager
,
self
)
.
get_queryset
()
kwargs
=
{}
if
not
hasattr
(
tl
,
'times'
):
tl
.
times
=
0
#
if not hasattr(tl, 'times'):
#
tl.times = 0
# logger.debug("[{}]>>>>>>>>>> Get query set".format(tl.times))
if
not
current_org
:
kwargs
[
'id'
]
=
None
elif
current_org
.
is_real
():
kwargs
[
'org_id'
]
=
current_org
.
id
elif
current_org
.
is_default
():
queryset
=
queryset
.
filter
(
Q
(
org_id
=
""
)
|
Q
(
org_id__isnull
=
True
)
)
queryset
=
queryset
.
filter
(
org_id
=
""
)
queryset
=
queryset
.
filter
(
**
kwargs
)
tl
.
times
+=
1
return
queryset
...
...
@@ -73,7 +76,7 @@ class OrgManager(models.Manager):
class
OrgModelMixin
(
models
.
Model
):
org_id
=
models
.
CharField
(
max_length
=
36
,
null
=
True
,
blank
=
True
,
default
=
None
)
org_id
=
models
.
CharField
(
max_length
=
36
,
blank
=
True
,
default
=
''
,
verbose_name
=
_
(
"Organization"
)
)
objects
=
OrgManager
()
sep
=
'@'
...
...
@@ -120,6 +123,25 @@ class OrgModelMixin(models.Model):
else
:
return
name
def
validate_unique
(
self
,
exclude
=
None
):
"""
Check unique constraints on the model and raise ValidationError if any
failed.
"""
self
.
org_id
=
current_org
.
id
if
current_org
.
is_real
()
else
''
if
exclude
and
'org_id'
in
exclude
:
exclude
.
remove
(
'org_id'
)
unique_checks
,
date_checks
=
self
.
_get_unique_checks
(
exclude
=
exclude
)
errors
=
self
.
_perform_unique_checks
(
unique_checks
)
date_errors
=
self
.
_perform_date_checks
(
date_checks
)
for
k
,
v
in
date_errors
.
items
():
errors
.
setdefault
(
k
,
[])
.
extend
(
v
)
if
errors
:
raise
ValidationError
(
errors
)
class
Meta
:
abstract
=
True
...
...
@@ -157,4 +179,3 @@ class OrgModelForm(ModelForm):
continue
model
=
field
.
queryset
.
model
field
.
queryset
=
model
.
objects
.
all
()
apps/users/forms.py
View file @
670c8a6d
...
...
@@ -306,7 +306,7 @@ def user_limit_to():
return
{
"orgs"
:
current_org
}
class
UserGroupForm
(
forms
.
ModelForm
):
class
UserGroupForm
(
Org
ModelForm
):
users
=
forms
.
ModelMultipleChoiceField
(
queryset
=
User
.
objects
.
exclude
(
role
=
User
.
ROLE_APP
),
label
=
_
(
"User"
),
...
...
@@ -342,7 +342,7 @@ class UserGroupForm(forms.ModelForm):
class
Meta
:
model
=
UserGroup
fields
=
[
'name'
,
'users'
,
'comment'
'name'
,
'users'
,
'comment'
,
]
help_texts
=
{
'name'
:
'* required'
...
...
apps/users/models/group.py
View file @
670c8a6d
...
...
@@ -22,7 +22,7 @@ class UserGroup(OrgModelMixin):
class
Meta
:
ordering
=
[
'name'
]
unique_together
=
[(
'org_id'
,
'name'
)]
unique_together
=
[(
'org_id'
,
'name'
)
,
]
verbose_name
=
_
(
"User group"
)
@classmethod
...
...
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