Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
courier
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
张宇
courier
Commits
98b7e35e
Commit
98b7e35e
authored
Feb 07, 2020
by
张宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
can_send
parent
bad15ffe
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
25 deletions
+51
-25
views.py
message/views.py
+17
-20
gaia_client.py
rpc/gaia_client.py
+29
-3
exceptions.py
rpc_framework/exceptions.py
+1
-1
views.py
rpc_framework/views.py
+4
-1
No files found.
message/views.py
View file @
98b7e35e
...
@@ -12,7 +12,9 @@ from adapter.old_system import bind_prefix
...
@@ -12,7 +12,9 @@ from adapter.old_system import bind_prefix
from
adapter.rpcd.exceptions
import
RPCPermanentError
from
adapter.rpcd.exceptions
import
RPCPermanentError
from
api.models.message
import
ConversationUserStatus
from
api.models.message
import
ConversationUserStatus
from
rpc
import
gaia_client
from
rpc
import
gaia_client
from
rpc.gaia_client
import
get_doctor_basic_info
,
get_single_doctor_basic_info
from
rpc.gaia_client
import
get_doctor_basic_info
,
\
get_single_doctor_basic_info
,
get_user_info_by_user_id
,
\
get_fans_relationship
,
is_kefu_user
from
rpc_framework
import
exceptions
from
rpc_framework
import
exceptions
from
rpc_framework.context
import
RPCViewContext
from
rpc_framework.context
import
RPCViewContext
from
rpc_framework.decorators
import
rpc_view
,
interceptor_classes
from
rpc_framework.decorators
import
rpc_view
,
interceptor_classes
...
@@ -243,26 +245,21 @@ def message_conversation_list_v3(user_ids: List[int],
...
@@ -243,26 +245,21 @@ def message_conversation_list_v3(user_ids: List[int],
@interceptor_classes
([
CalleeParametersInterceptor
,
SessionUserInterceptor
])
@interceptor_classes
([
CalleeParametersInterceptor
,
SessionUserInterceptor
])
def
check_can_send_message
(
context
:
RPCViewContext
,
target_uid
:
str
)
->
Dict
:
def
check_can_send_message
(
context
:
RPCViewContext
,
target_uid
:
str
)
->
Dict
:
user
=
context
.
user
user
=
context
.
user
# doctor_info = get_single_doctor_basic_info(user.id)
doctor_info
=
get_single_doctor_basic_info
(
user
.
id
)
#
# target_user_id = doctor_info.get('user_id')
# print('target_user_id:', target_user_id)
# raise exceptions.NotFoundException
target_user_info
=
get_user_info_by_user_id
(
target_uid
)
if
not
target_user_info
:
raise
exceptions
.
NotFoundException
# if not target_user_id:
target_doctor_info
=
get_single_doctor_basic_info
(
target_uid
)
# raise 26872687
if
doctor_info
or
target_doctor_info
:
# target_doctor = get_doctor_by_user_id(target_user.id)
return
{
'can_send'
:
True
}
#
# if doctor or target_doctor:
user_follow
,
target_follow
=
get_fans_relationship
(
user
.
id
,
target_uid
)
# return {'can_send': True}
target_user_id
=
(
doctor_info
or
{})
.
get
(
'user_id'
)
#
if
user_follow
and
target_follow
:
# user_follow = user.fans.filter(follow=target_user, bond=True).exists()
return
{
'can_send'
:
True
}
# target_follow = target_user.fans.filter(follow=user, bond=True).exists()
if
is_kefu_user
(
target_user_id
):
#
return
{
'can_send'
:
True
}
# if user_follow and target_follow:
# return {'can_send': True}
# if target_user.person.id.hex == settings.KEFU_PERSION_ID:
# return {'can_send': True}
return
{
'can_send'
:
False
}
return
{
'can_send'
:
False
}
rpc/gaia_client.py
View file @
98b7e35e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
typing
import
List
,
Dict
,
Optional
,
Set
from
typing
import
List
,
Dict
,
Optional
,
Set
,
Tuple
from
rpc
import
rpc_invoke_error_handle_decorator
from
rpc
import
rpc_invoke_error_handle_decorator
from
rpc.context
import
get_rpc_remote_invoker
from
rpc.context
import
get_rpc_remote_invoker
...
@@ -45,9 +45,23 @@ def get_doctor_basic_info(doctor_ids: List[str]) -> List[Dict]:
...
@@ -45,9 +45,23 @@ def get_doctor_basic_info(doctor_ids: List[str]) -> List[Dict]:
def
get_single_doctor_basic_info
(
doctor_id
:
str
)
->
Dict
:
def
get_single_doctor_basic_info
(
doctor_id
:
str
)
->
Dict
:
re
turn
get_rpc_remote_invoker
()[
'api/doctor/basic_info'
](
re
s
=
get_rpc_remote_invoker
()[
'api/doctor/basic_info'
](
doctor_ids
=
[
doctor_id
]
doctor_ids
=
[
doctor_id
]
)
.
unwrap
()[
0
]
)
.
unwrap
()
if
res
:
return
res
[
0
]
def
get_fans_relationship
(
user_id1
:
str
,
user_id2
:
str
)
->
Tuple
[
bool
,
bool
]:
# response:
# value1: user2 是否 user1 的粉丝
# value2: user1 是否 user2 的粉丝
try
:
return
get_rpc_remote_invoker
()[
'api/get_fans_relationship'
](
user_id1
=
user_id1
,
user_id2
=
user_id2
)
.
unwrap
()
except
:
return
[
False
,
False
]
def
batch_get_doctor_info_by_user_ids
(
user_ids
:
List
[
int
])
->
Dict
:
def
batch_get_doctor_info_by_user_ids
(
user_ids
:
List
[
int
])
->
Dict
:
...
@@ -55,3 +69,15 @@ def batch_get_doctor_info_by_user_ids(user_ids: List[int]) -> Dict:
...
@@ -55,3 +69,15 @@ def batch_get_doctor_info_by_user_ids(user_ids: List[int]) -> Dict:
user_ids
=
user_ids
,
user_ids
=
user_ids
,
with_fields
=
[
'meta'
]
with_fields
=
[
'meta'
]
)
.
unwrap
()
)
.
unwrap
()
def
get_user_info_by_user_id
(
user_id
):
return
get_rpc_remote_invoker
()[
'hera/user/getinfoby_userid'
](
user_id
=
user_id
)
.
unwrap
()
def
is_kefu_user
(
user_id
):
try
:
get_rpc_remote_invoker
()[
'api/is_kefu_user'
](
user_id
=
user_id
)
.
unwrap
()
except
:
return
False
rpc_framework/exceptions.py
View file @
98b7e35e
...
@@ -55,7 +55,7 @@ class AuthenticationFailed(RPCViewBaseException):
...
@@ -55,7 +55,7 @@ class AuthenticationFailed(RPCViewBaseException):
message
=
Error
.
getDesc
(
Error
.
AUTH_FAILED
)
message
=
Error
.
getDesc
(
Error
.
AUTH_FAILED
)
class
NotFoundException
(
RPCViewBaseException
):
class
NotFoundException
(
RPCViewBaseException
):
code
=
1404
code
=
1404
# gaia RPCNotFoundException
message
=
"Not Found"
message
=
"Not Found"
# default_message = "Not Found"
# default_message = "Not Found"
...
...
rpc_framework/views.py
View file @
98b7e35e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
traceback
from
django.db
import
connection
,
transaction
from
django.db
import
connection
,
transaction
from
rpc_framework
import
exceptions
from
rpc_framework
import
exceptions
...
@@ -19,7 +21,8 @@ def exception_handler(exc, wrapped_context) -> None:
...
@@ -19,7 +21,8 @@ def exception_handler(exc, wrapped_context) -> None:
raise
exc
raise
exc
elif
issubclass
(
exc
.
__class__
,
exceptions
.
RPCViewBaseException
):
elif
issubclass
(
exc
.
__class__
,
exceptions
.
RPCViewBaseException
):
raise
exc
.
as_rpc_view_exception
()
raise
exc
.
as_rpc_view_exception
()
return
None
elif
isinstance
(
exc
,
Exception
):
print
(
exc
,
exc
.
args
[
0
]
if
exc
.
args
else
''
,
traceback
.
format_exc
())
class
RPCView
(
RPCAbstractView
):
class
RPCView
(
RPCAbstractView
):
...
...
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