Переглянути джерело

add team tag to kb (#2890)

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

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
tags/v0.13.0
Kevin Hu 1 рік тому
джерело
коміт
e0c0bdeb0a
Аккаунт користувача з таким Email не знайдено

+ 2
- 2
api/apps/tenant_app.py Переглянути файл

role=UserTenantRole.INVITE, role=UserTenantRole.INVITE,
status=StatusEnum.VALID.value) status=StatusEnum.VALID.value)


usr = list(usrs.dicts())[0]
usr = usrs[0].to_dict()
usr = {k: v for k, v in usr.items() if k in ["id", "avatar", "email", "nickname"]} usr = {k: v for k, v in usr.items() if k in ["id", "avatar", "email", "nickname"]}


return get_json_result(data=usr) return get_json_result(data=usr)
return server_error_response(e) return server_error_response(e)




@manager.route("/agree/<tenant_id>", methods=["GET"])
@manager.route("/agree/<tenant_id>", methods=["PUT"])
@login_required @login_required
def agree(tenant_id): def agree(tenant_id):
try: try:

+ 2
- 1
api/apps/user_app.py Переглянути файл

update_dict["password"] = generate_password_hash(decrypt(new_password)) update_dict["password"] = generate_password_hash(decrypt(new_password))


for k in request_data.keys(): for k in request_data.keys():
if k in ["password", "new_password"]:
if k in ["password", "new_password", "email", "status", "is_superuser", "login_channel", "is_anonymous",
"is_active", "is_authenticated", "last_login_time"]:
continue continue
update_dict[k] = request_data[k] update_dict[k] = request_data[k]



+ 24
- 8
api/db/services/knowledgebase_service.py Переглянути файл

# limitations under the License. # limitations under the License.
# #
from api.db import StatusEnum, TenantPermission from api.db import StatusEnum, TenantPermission
from api.db.db_models import Knowledgebase, DB, Tenant
from api.db.db_models import Knowledgebase, DB, Tenant, User
from api.db.services.common_service import CommonService from api.db.services.common_service import CommonService




@DB.connection_context() @DB.connection_context()
def get_by_tenant_ids(cls, joined_tenant_ids, user_id, def get_by_tenant_ids(cls, joined_tenant_ids, user_id,
page_number, items_per_page, orderby, desc): page_number, items_per_page, orderby, desc):
kbs = cls.model.select().where(
fields = [
cls.model.id,
cls.model.avatar,
cls.model.name,
cls.model.language,
cls.model.description,
cls.model.permission,
cls.model.doc_num,
cls.model.token_num,
cls.model.chunk_num,
cls.model.parser_id,
cls.model.embd_id,
User.nickname,
User.avatar.alias('tenant_avatar'),
cls.model.update_time
]
kbs = cls.model.select(*fields).join(User, on=(cls.model.tenant_id == User.id)).where(
((cls.model.tenant_id.in_(joined_tenant_ids) & (cls.model.permission == ((cls.model.tenant_id.in_(joined_tenant_ids) & (cls.model.permission ==
TenantPermission.TEAM.value)) | ( TenantPermission.TEAM.value)) | (
cls.model.tenant_id == user_id))
cls.model.tenant_id == user_id))
& (cls.model.status == StatusEnum.VALID.value) & (cls.model.status == StatusEnum.VALID.value)
) )
if desc: if desc:
if count == -1: if count == -1:
return kbs[offset:] return kbs[offset:]


return kbs[offset:offset+count]
return kbs[offset:offset + count]


@classmethod @classmethod
@DB.connection_context() @DB.connection_context()
def get_detail(cls, kb_id): def get_detail(cls, kb_id):
fields = [ fields = [
cls.model.id, cls.model.id,
#Tenant.embd_id,
# Tenant.embd_id,
cls.model.embd_id, cls.model.embd_id,
cls.model.avatar, cls.model.avatar,
cls.model.name, cls.model.name,
cls.model.parser_id, cls.model.parser_id,
cls.model.parser_config] cls.model.parser_config]
kbs = cls.model.select(*fields).join(Tenant, on=( kbs = cls.model.select(*fields).join(Tenant, on=(
(Tenant.id == cls.model.tenant_id) & (Tenant.status == StatusEnum.VALID.value))).where(
(Tenant.id == cls.model.tenant_id) & (Tenant.status == StatusEnum.VALID.value))).where(
(cls.model.id == kb_id), (cls.model.id == kb_id),
(cls.model.status == StatusEnum.VALID.value) (cls.model.status == StatusEnum.VALID.value)
) )
if not kbs: if not kbs:
return return
d = kbs[0].to_dict() d = kbs[0].to_dict()
#d["embd_id"] = kbs[0].tenant.embd_id
# d["embd_id"] = kbs[0].tenant.embd_id
return d return d


@classmethod @classmethod
@classmethod @classmethod
@DB.connection_context() @DB.connection_context()
def get_list(cls, joined_tenant_ids, user_id, def get_list(cls, joined_tenant_ids, user_id,
page_number, items_per_page, orderby, desc, id , name):
page_number, items_per_page, orderby, desc, id, name):
kbs = cls.model.select() kbs = cls.model.select()
if id: if id:
kbs = kbs.where(cls.model.id == id) kbs = kbs.where(cls.model.id == id)

Завантаження…
Відмінити
Зберегти