Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
guo xiaoyong
Jumpserver
Commits
f2a98dd6
Commit
f2a98dd6
authored
3 years ago
by
jiangweidong
Browse files
Options
Download
Email Patches
Plain Diff
feat: 完成会话分享可设置1、5分钟时限,且可分享给指定人
parent
b560f02e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/terminal/migrations/0050_sessionsharing_users.py
+3
-4
apps/terminal/migrations/0050_sessionsharing_users.py
apps/terminal/models/sharing.py
+2
-4
apps/terminal/models/sharing.py
apps/terminal/serializers/sharing.py
+8
-7
apps/terminal/serializers/sharing.py
with
13 additions
and
15 deletions
+13
-15
apps/terminal/migrations/0050_sessionsharing_
meta
.py
→
apps/terminal/migrations/0050_sessionsharing_
users
.py
+
3
-
4
View file @
f2a98dd6
# Generated by Django 3.1.14 on 2022-05-1
2
0
7:2
2
# Generated by Django 3.1.14 on 2022-05-1
7
0
0:5
2
import
common.db.encoder
from
django.db
import
migrations
,
models
...
...
@@ -13,7 +12,7 @@ class Migration(migrations.Migration):
operations
=
[
migrations
.
AddField
(
model_name
=
'sessionsharing'
,
name
=
'
meta
'
,
field
=
models
.
JSON
Field
(
default
=
dict
,
encoder
=
common
.
db
.
encoder
.
ModelJSONFieldEncoder
,
verbose_name
=
'
Meta
'
),
name
=
'
users
'
,
field
=
models
.
Char
Field
(
default
=
list
,
max_length
=
1024
,
verbose_name
=
'
User
'
),
),
]
This diff is collapsed.
Click to expand it.
apps/terminal/models/sharing.py
+
2
-
4
View file @
f2a98dd6
...
...
@@ -4,7 +4,6 @@ from django.db import models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils
import
timezone
from
common.db.encoder
import
ModelJSONFieldEncoder
from
common.mixins
import
CommonModelMixin
from
orgs.mixins.models
import
OrgModelMixin
from
.session
import
Session
...
...
@@ -29,7 +28,7 @@ class SessionSharing(CommonModelMixin, OrgModelMixin):
expired_time
=
models
.
IntegerField
(
default
=
0
,
verbose_name
=
_
(
'Expired time (min)'
),
db_index
=
True
)
meta
=
models
.
JSON
Field
(
encoder
=
ModelJSONFieldEncoder
,
default
=
dict
,
verbose_name
=
_
(
"Meta"
)
)
users
=
models
.
Char
Field
(
max_length
=
1024
,
verbose_name
=
_
(
"User"
),
default
=
list
)
class
Meta
:
ordering
=
(
'-date_created'
,
)
...
...
@@ -56,8 +55,7 @@ class SessionSharing(CommonModelMixin, OrgModelMixin):
return
False
,
_
(
'Link not active'
)
if
not
self
.
is_expired
:
return
False
,
_
(
'Link expired'
)
allow_users
=
self
.
meta
.
get
(
'users'
,
[])
if
allow_users
and
str
(
joiner
.
id
)
not
in
allow_users
:
if
self
.
users
and
str
(
joiner
.
id
)
not
in
self
.
users
.
split
(
','
):
return
False
,
_
(
'User not allowed to join'
)
return
True
,
''
...
...
This diff is collapsed.
Click to expand it.
apps/terminal/serializers/sharing.py
+
8
-
7
View file @
f2a98dd6
...
...
@@ -7,26 +7,27 @@ from ..models import SessionSharing, SessionJoinRecord
__all__
=
[
'SessionSharingSerializer'
,
'SessionJoinRecordSerializer'
]
class
SessionSharing
Meta
Serializer
(
serializers
.
Serializer
):
class
SessionSharingSerializer
(
OrgResourceModel
Serializer
Mixin
):
users
=
serializers
.
ListSerializer
(
child
=
serializers
.
CharField
(
max_length
=
36
),
write_only
=
True
,
default
=
dict
child
=
serializers
.
CharField
(
max_length
=
36
),
write_only
=
True
,
default
=
list
,
allow_null
=
True
)
class
SessionSharingSerializer
(
OrgResourceModelSerializerMixin
):
meta
=
SessionSharingMetaSerializer
()
class
Meta
:
model
=
SessionSharing
fields_mini
=
[
'id'
]
fields_small
=
fields_mini
+
[
'verify_code'
,
'is_active'
,
'expired_time'
,
'created_by'
,
'date_created'
,
'date_updated'
,
'
meta
'
'date_created'
,
'date_updated'
,
'
users
'
]
fields_fk
=
[
'session'
,
'creator'
]
fields
=
fields_small
+
fields_fk
read_only_fields
=
[
'verify_code'
]
def
save
(
self
,
**
kwargs
):
users
=
self
.
validated_data
.
get
(
'users'
,
[])
self
.
validated_data
[
'users'
]
=
','
.
join
(
users
)
return
super
().
save
(
**
kwargs
)
def
create
(
self
,
validated_data
):
validated_data
[
'verify_code'
]
=
random_string
(
4
)
session
=
validated_data
.
get
(
'session'
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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