Commit d168e2bc authored by zhanglu's avatar zhanglu

Merge branch 'feature/user_list' into 'test'

根据用户名或者用户列表

See merge request !24
parents 91040cf2 7f7cb6cc
from engine.cache import RedisWithoutprefixProxy
from django.conf import settings
ins_cache = RedisWithoutprefixProxy(settings.REDIS_GROUP['ins_cache'])
......@@ -18,5 +18,6 @@ urlpatterns = [
# user
url(r'^v1/user/shadow/list$', user.ShadowUserList.as_view(), name='create_tag_for_batch'),
url(r'^v1/validate_3party_or_account$', user.Validate3PartyOrAccount.as_view(), name='validate_3party_or_account'),
url(r'^v1/validate_3party_account$', user.Validate3PartyAccount.as_view(), name='validate_3party_account$'),
]
......@@ -2,14 +2,20 @@ import json
from api.views.base_view import BaseView
from api.utils.sensitive import Sensitive
from api.cache.cache import ins_cache
from libs.user import get_user_by_ids
from alpha_types.venus import ERROR as CODES
ins_account_cache = "ins_account_cache"
class CreateTopicForBatch(BaseView):
"""
内部使用,批量建帖
"""
def post(self, request):
user_id = request.POST.get("user_id", 0)
......@@ -58,6 +64,18 @@ class CreateTopicForBatch(BaseView):
item["tag_id"] = tag_id if tag_id else None
item["is_online"] = is_online
not_exists_ids = []
topic_list = []
for item in topics:
_id = item.get("id")
exists = ins_cache.sismember(ins_account_cache, _id)
if exists:
continue
topic_list.append(item)
not_exists_ids.append(_id)
# check_info = Sensitive.check(tag_names)
# tags = [tag_name for tag_name, succ in check_info.items() if not succ]
tags = tag_names
......@@ -72,7 +90,7 @@ class CreateTopicForBatch(BaseView):
# 更新发帖
# 处理标签,将文本中的标签处理成现有标签
for item in topics:
for item in topic_list:
tags = item.get("tags") or []
tags = [tag.replace("#", '').strip() for tag in tags]
content = item["content"]
......@@ -89,11 +107,15 @@ class CreateTopicForBatch(BaseView):
create_err, result = self.call_rpc(
"venus/community/topic/batch_create_for_inner",
topic_list=topics
topic_list=topic_list
)
if create_err:
return self.error(create_err)
# 将已经跑了的数据添加到缓存
if not_exists_ids:
ins_cache.sadd(ins_account_cache, *not_exists_ids)
return self.ok(data=result)
......
import json
import json
from api.views.base_view import BaseView, get_offset_count
from libs.user import get_user_by_names
from alpha_types.venus.error import ERROR as CODES
class UpdateGraspStatus(BaseView):
......@@ -59,3 +62,46 @@ class Validate3PartyAccount(BaseView):
return self.error(err)
data = {account_id: _data.get(account_id, False) for account_id in account_ids}
return self.ok(data=data)
class Validate3PartyOrAccount(BaseView):
"""判断用户是否在三方账号或者alpha账号体系中。"""
def post(self, request):
try:
names = json.loads(request.POST.get("names", "[]"))
except:
names = []
if not names:
return self.error(self.get_ErrorInfo(CODES.PARAMS_INCOMPLETE))
user_list = get_user_by_names(names=names)
account_users = {}
for name in names:
for _, user in user_list.items():
if user["nick_name"] != name:
continue
account_users[name] = True
break
users = {name: account_users.get(name, False) for name in names}
err, _3party_account = self.call_rpc(
"venus/community/user/validate_has_bind_3party_account",
bind_account_ids=names
)
if err:
return self.error(err)
data = {
name: _3party_account.get(name, False) or users.get(name, False)
for name in names
}
return self.ok(data={
"users": data,
})
......@@ -46,6 +46,19 @@ def get_user_by_ids(user_ids):
return users_info
def get_user_by_names(names):
"""获取用户信息"""
try:
rpc = get_current_rpc_invoker()
users_info = rpc["venus/account/user/userinfo_list_by_name"](names=names).unwrap()
except Exception as e:
raise Exception(e)
return []
return users_info
def auth(request):
user_info = get_user_by_request(request)
if not user_info:
......
......@@ -68,8 +68,7 @@ QINIU_FACE_BUCKET = 'alpha-s'
FACE_TOP_N_CNT = 3
REDIS_GROUP = {
'desc_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
'qq_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
'ins_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
}
OPERTATION_POSITION = 3 # 运营卡片位置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment