Kevin Hu commited on
Commit
124ecb2
·
1 Parent(s): 17d873a

add team tag to kb (#2890)

Browse files

### What problem does this PR solve?
#2834

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

api/apps/tenant_app.py CHANGED
@@ -60,7 +60,7 @@ def create(tenant_id):
60
  role=UserTenantRole.INVITE,
61
  status=StatusEnum.VALID.value)
62
 
63
- usr = list(usrs.dicts())[0]
64
  usr = {k: v for k, v in usr.items() if k in ["id", "avatar", "email", "nickname"]}
65
 
66
  return get_json_result(data=usr)
@@ -88,7 +88,7 @@ def tenant_list():
88
  return server_error_response(e)
89
 
90
 
91
- @manager.route("/agree/<tenant_id>", methods=["GET"])
92
  @login_required
93
  def agree(tenant_id):
94
  try:
 
60
  role=UserTenantRole.INVITE,
61
  status=StatusEnum.VALID.value)
62
 
63
+ usr = usrs[0].to_dict()
64
  usr = {k: v for k, v in usr.items() if k in ["id", "avatar", "email", "nickname"]}
65
 
66
  return get_json_result(data=usr)
 
88
  return server_error_response(e)
89
 
90
 
91
+ @manager.route("/agree/<tenant_id>", methods=["PUT"])
92
  @login_required
93
  def agree(tenant_id):
94
  try:
api/apps/user_app.py CHANGED
@@ -260,7 +260,8 @@ def setting_user():
260
  update_dict["password"] = generate_password_hash(decrypt(new_password))
261
 
262
  for k in request_data.keys():
263
- if k in ["password", "new_password"]:
 
264
  continue
265
  update_dict[k] = request_data[k]
266
 
 
260
  update_dict["password"] = generate_password_hash(decrypt(new_password))
261
 
262
  for k in request_data.keys():
263
+ if k in ["password", "new_password", "email", "status", "is_superuser", "login_channel", "is_anonymous",
264
+ "is_active", "is_authenticated", "last_login_time"]:
265
  continue
266
  update_dict[k] = request_data[k]
267
 
api/db/services/knowledgebase_service.py CHANGED
@@ -14,7 +14,7 @@
14
  # limitations under the License.
15
  #
16
  from api.db import StatusEnum, TenantPermission
17
- from api.db.db_models import Knowledgebase, DB, Tenant
18
  from api.db.services.common_service import CommonService
19
 
20
 
@@ -25,10 +25,26 @@ class KnowledgebaseService(CommonService):
25
  @DB.connection_context()
26
  def get_by_tenant_ids(cls, joined_tenant_ids, user_id,
27
  page_number, items_per_page, orderby, desc):
28
- kbs = cls.model.select().where(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  ((cls.model.tenant_id.in_(joined_tenant_ids) & (cls.model.permission ==
30
  TenantPermission.TEAM.value)) | (
31
- cls.model.tenant_id == user_id))
32
  & (cls.model.status == StatusEnum.VALID.value)
33
  )
34
  if desc:
@@ -63,14 +79,14 @@ class KnowledgebaseService(CommonService):
63
  if count == -1:
64
  return kbs[offset:]
65
 
66
- return kbs[offset:offset+count]
67
 
68
  @classmethod
69
  @DB.connection_context()
70
  def get_detail(cls, kb_id):
71
  fields = [
72
  cls.model.id,
73
- #Tenant.embd_id,
74
  cls.model.embd_id,
75
  cls.model.avatar,
76
  cls.model.name,
@@ -83,14 +99,14 @@ class KnowledgebaseService(CommonService):
83
  cls.model.parser_id,
84
  cls.model.parser_config]
85
  kbs = cls.model.select(*fields).join(Tenant, on=(
86
- (Tenant.id == cls.model.tenant_id) & (Tenant.status == StatusEnum.VALID.value))).where(
87
  (cls.model.id == kb_id),
88
  (cls.model.status == StatusEnum.VALID.value)
89
  )
90
  if not kbs:
91
  return
92
  d = kbs[0].to_dict()
93
- #d["embd_id"] = kbs[0].tenant.embd_id
94
  return d
95
 
96
  @classmethod
@@ -146,7 +162,7 @@ class KnowledgebaseService(CommonService):
146
  @classmethod
147
  @DB.connection_context()
148
  def get_list(cls, joined_tenant_ids, user_id,
149
- page_number, items_per_page, orderby, desc, id , name):
150
  kbs = cls.model.select()
151
  if id:
152
  kbs = kbs.where(cls.model.id == id)
 
14
  # limitations under the License.
15
  #
16
  from api.db import StatusEnum, TenantPermission
17
+ from api.db.db_models import Knowledgebase, DB, Tenant, User
18
  from api.db.services.common_service import CommonService
19
 
20
 
 
25
  @DB.connection_context()
26
  def get_by_tenant_ids(cls, joined_tenant_ids, user_id,
27
  page_number, items_per_page, orderby, desc):
28
+ fields = [
29
+ cls.model.id,
30
+ cls.model.avatar,
31
+ cls.model.name,
32
+ cls.model.language,
33
+ cls.model.description,
34
+ cls.model.permission,
35
+ cls.model.doc_num,
36
+ cls.model.token_num,
37
+ cls.model.chunk_num,
38
+ cls.model.parser_id,
39
+ cls.model.embd_id,
40
+ User.nickname,
41
+ User.avatar.alias('tenant_avatar'),
42
+ cls.model.update_time
43
+ ]
44
+ kbs = cls.model.select(*fields).join(User, on=(cls.model.tenant_id == User.id)).where(
45
  ((cls.model.tenant_id.in_(joined_tenant_ids) & (cls.model.permission ==
46
  TenantPermission.TEAM.value)) | (
47
+ cls.model.tenant_id == user_id))
48
  & (cls.model.status == StatusEnum.VALID.value)
49
  )
50
  if desc:
 
79
  if count == -1:
80
  return kbs[offset:]
81
 
82
+ return kbs[offset:offset + count]
83
 
84
  @classmethod
85
  @DB.connection_context()
86
  def get_detail(cls, kb_id):
87
  fields = [
88
  cls.model.id,
89
+ # Tenant.embd_id,
90
  cls.model.embd_id,
91
  cls.model.avatar,
92
  cls.model.name,
 
99
  cls.model.parser_id,
100
  cls.model.parser_config]
101
  kbs = cls.model.select(*fields).join(Tenant, on=(
102
+ (Tenant.id == cls.model.tenant_id) & (Tenant.status == StatusEnum.VALID.value))).where(
103
  (cls.model.id == kb_id),
104
  (cls.model.status == StatusEnum.VALID.value)
105
  )
106
  if not kbs:
107
  return
108
  d = kbs[0].to_dict()
109
+ # d["embd_id"] = kbs[0].tenant.embd_id
110
  return d
111
 
112
  @classmethod
 
162
  @classmethod
163
  @DB.connection_context()
164
  def get_list(cls, joined_tenant_ids, user_id,
165
+ page_number, items_per_page, orderby, desc, id, name):
166
  kbs = cls.model.select()
167
  if id:
168
  kbs = kbs.where(cls.model.id == id)