From 4f888be82c4544fa512f5655a7617850ca3bca43 Mon Sep 17 00:00:00 2001 From: Ranjiwei <32759763+r350178982@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:20:54 +0800 Subject: [PATCH] Wiki set repo type (#6264) * update * update * update --- seahub/api2/endpoints/group_libraries.py | 5 +++-- seahub/api2/endpoints/groups.py | 5 ++++- seahub/api2/endpoints/repos.py | 18 +++++++++++++++++- seahub/api2/endpoints/wiki2.py | 3 +++ seahub/api2/utils.py | 5 +++++ seahub/constants.py | 2 ++ seahub/utils/db_api.py | 10 ++++++++++ 7 files changed, 44 insertions(+), 4 deletions(-) diff --git a/seahub/api2/endpoints/group_libraries.py b/seahub/api2/endpoints/group_libraries.py index 44e725bcf5..18f8a72748 100644 --- a/seahub/api2/endpoints/group_libraries.py +++ b/seahub/api2/endpoints/group_libraries.py @@ -12,7 +12,7 @@ from seaserv import seafile_api, ccnet_api from constance import config from seahub import settings -from seahub.api2.utils import api_error +from seahub.api2.utils import api_error, is_wiki_repo from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication from seahub.api2.endpoints.utils import api_check_group @@ -85,7 +85,8 @@ class GroupLibraries(APIView): group_repos = seafile_api.get_repos_by_group(group_id) group_repos.sort(key=lambda x: x.last_modified, reverse=True) - + group_repos = [gr for gr in group_repos if not is_wiki_repo(gr)] + try: current_page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '100')) diff --git a/seahub/api2/endpoints/groups.py b/seahub/api2/endpoints/groups.py index 9844f7c923..7842f67e53 100644 --- a/seahub/api2/endpoints/groups.py +++ b/seahub/api2/endpoints/groups.py @@ -13,7 +13,7 @@ from rest_framework import status from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError -from seahub.api2.utils import api_error +from seahub.api2.utils import api_error, is_wiki_repo from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle from seahub.api2.endpoints.group_owned_libraries import get_group_id_by_repo_owner @@ -181,6 +181,9 @@ class Groups(APIView): repos = [] for r in group_repos: + if is_wiki_repo(r): + continue + repo_owner = repo_id_owner_dict.get(r.id, r.user) repo = { "id": r.id, diff --git a/seahub/api2/endpoints/repos.py b/seahub/api2/endpoints/repos.py index 5a7606a4fd..53fadeff67 100644 --- a/seahub/api2/endpoints/repos.py +++ b/seahub/api2/endpoints/repos.py @@ -10,7 +10,7 @@ from rest_framework import status from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication -from seahub.api2.utils import api_error +from seahub.api2.utils import api_error, is_wiki_repo from seahub.api2.endpoints.group_owned_libraries import get_group_id_by_repo_owner @@ -113,6 +113,10 @@ class ReposView(APIView): # do not return virtual repos if r.is_virtual: continue + + if is_wiki_repo(r): + continue + repo_info = { "type": "mine", @@ -170,6 +174,9 @@ class ReposView(APIView): shared_repos.sort(key=lambda x: x.last_modify, reverse=True) for r in shared_repos: + + if is_wiki_repo(r): + continue owner_email = r.user @@ -238,6 +245,11 @@ class ReposView(APIView): monitored_repo_id_list = [] for r in group_repos: + + if is_wiki_repo(r): + continue + + repo_info = { "type": "group", "group_id": r.group_id, @@ -282,6 +294,10 @@ class ReposView(APIView): nickname_dict[e] = email2nickname(e) for r in public_repos: + + if is_wiki_repo(r): + continue + repo_owner = repo_id_owner_dict[r.repo_id] repo_info = { "type": "public", diff --git a/seahub/api2/endpoints/wiki2.py b/seahub/api2/endpoints/wiki2.py index cbac54dd9b..25a339200e 100644 --- a/seahub/api2/endpoints/wiki2.py +++ b/seahub/api2/endpoints/wiki2.py @@ -21,6 +21,7 @@ from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle from seahub.api2.utils import api_error, to_python_boolean +from seahub.utils.db_api import SeafileDB from seahub.wiki2.models import Wiki2 as Wiki from seahub.wiki2.utils import is_valid_wiki_name, can_edit_wiki, get_wiki_dirs_by_path, \ get_wiki_config, WIKI_PAGES_DIR, WIKI_CONFIG_PATH, WIKI_CONFIG_FILE_NAME, is_group_wiki, \ @@ -183,6 +184,8 @@ class Wikis2View(APIView): try: wiki = Wiki.objects.add(wiki_name=wiki_name, owner=wiki_owner, repo_id=repo_id) + seafile_db_api = SeafileDB() + seafile_db_api.set_repo_type(repo_id, 'wiki') except Exception as e: logger.error(e) msg = 'Internal Server Error' diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index 9bea136070..c69d33d4ca 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -21,6 +21,7 @@ from pysearpc import SearpcError from seahub.base.templatetags.seahub_tags import email2nickname, \ translate_seahub_time, file_icon_filter, email2contact_email +from seahub.constants import REPO_TYPE_WIKI from seahub.group.views import is_group_staff from seahub.group.utils import is_group_member from seahub.api2.models import Token, TokenV2, DESKTOP_PLATFORMS @@ -278,3 +279,7 @@ def is_web_request(request): return True else: return False + +def is_wiki_repo(repo): + return repo.repo_type == REPO_TYPE_WIKI + diff --git a/seahub/constants.py b/seahub/constants.py index a76c2f0f05..b9840638cc 100644 --- a/seahub/constants.py +++ b/seahub/constants.py @@ -33,3 +33,5 @@ HASH_URLS = { } REPO_SHARE_LINK_COUNT_LIMIT = 500000 + +REPO_TYPE_WIKI = 'wiki' diff --git a/seahub/utils/db_api.py b/seahub/utils/db_api.py index d373b93a84..86f6a5eae9 100644 --- a/seahub/utils/db_api.py +++ b/seahub/utils/db_api.py @@ -357,3 +357,13 @@ class SeafileDB: """ with connection.cursor() as cursor: cursor.execute(sql) + + def set_repo_type(self, repo_id, repo_type): + sql = f""" + UPDATE `{self.db_name}`. `RepoInfo` + SET `type`= '%s' + WHERE `repo_id`='%s' + """ % (repo_type, repo_id) + + with connection.cursor() as cursor: + cursor.execute(sql)