Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add team tag to kb #2890

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/apps/tenant_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create(tenant_id):
role=UserTenantRole.INVITE,
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"]}

return get_json_result(data=usr)
Expand Down Expand Up @@ -88,7 +88,7 @@ def tenant_list():
return server_error_response(e)


@manager.route("/agree/<tenant_id>", methods=["GET"])
@manager.route("/agree/<tenant_id>", methods=["PUT"])
@login_required
def agree(tenant_id):
try:
Expand Down
3 changes: 2 additions & 1 deletion api/apps/user_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def setting_user():
update_dict["password"] = generate_password_hash(decrypt(new_password))

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
update_dict[k] = request_data[k]

Expand Down
32 changes: 24 additions & 8 deletions api/db/services/knowledgebase_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
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


Expand All @@ -25,10 +25,26 @@ class KnowledgebaseService(CommonService):
@DB.connection_context()
def get_by_tenant_ids(cls, joined_tenant_ids, user_id,
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 ==
TenantPermission.TEAM.value)) | (
cls.model.tenant_id == user_id))
cls.model.tenant_id == user_id))
& (cls.model.status == StatusEnum.VALID.value)
)
if desc:
Expand Down Expand Up @@ -63,14 +79,14 @@ def get_by_tenant_ids_by_offset(cls, joined_tenant_ids, user_id, offset, count,
if count == -1:
return kbs[offset:]

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

@classmethod
@DB.connection_context()
def get_detail(cls, kb_id):
fields = [
cls.model.id,
#Tenant.embd_id,
# Tenant.embd_id,
cls.model.embd_id,
cls.model.avatar,
cls.model.name,
Expand All @@ -83,14 +99,14 @@ def get_detail(cls, kb_id):
cls.model.parser_id,
cls.model.parser_config]
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.status == StatusEnum.VALID.value)
)
if not kbs:
return
d = kbs[0].to_dict()
#d["embd_id"] = kbs[0].tenant.embd_id
# d["embd_id"] = kbs[0].tenant.embd_id
return d

@classmethod
Expand Down Expand Up @@ -146,7 +162,7 @@ def get_all_ids(cls):
@classmethod
@DB.connection_context()
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()
if id:
kbs = kbs.where(cls.model.id == id)
Expand Down