From 7cf0aa56a47538f3b786a960a4968f34638d19d3 Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 11 Oct 2024 15:24:40 +0800 Subject: [PATCH 1/2] show org logo on share link page --- seahub/utils/__init__.py | 30 ++++++++++++++++++++++++ seahub/views/file.py | 10 +++++++- seahub/views/repo.py | 50 ++++++++++++++++++++++------------------ 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 5dc3e30982..1ab5e5d99e 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1457,3 +1457,33 @@ ASCII_RE = re.compile(r'[^\x00-\x7f]') def is_valid_password(password): return False if ASCII_RE.search(password) else True + + +def get_logo_path_by_user(username): + + logo_path = LOGO_PATH + + # custom logo + custom_logo_file = os.path.join(MEDIA_ROOT, CUSTOM_LOGO_PATH) + if os.path.exists(custom_logo_file): + logo_path = CUSTOM_LOGO_PATH + + # org custom logo + orgs = ccnet_api.get_orgs_by_user(username) + if orgs: + + from seahub.organizations.settings import ORG_ENABLE_ADMIN_CUSTOM_LOGO + if ORG_ENABLE_ADMIN_CUSTOM_LOGO: + + org = orgs[0] + from seahub.organizations.models import OrgAdminSettings + org_logo_url = OrgAdminSettings.objects.get_org_logo_url(org.org_id) + + if org_logo_url: + logo_path = org_logo_url + + from seahub.avatar.settings import AVATAR_FILE_STORAGE + if AVATAR_FILE_STORAGE == 'seahub.base.database_storage.DatabaseStorage': + logo_path = "/image-view/" + logo_path + + return logo_path diff --git a/seahub/views/file.py b/seahub/views/file.py index 8dfb520234..7e0003fffc 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -1326,7 +1326,6 @@ def view_shared_file(request, fileshare): permissions = fileshare.get_permissions() - #template = 'shared_file_view.html' template = 'shared_file_view_react.html' file_share_link = request.path @@ -1367,8 +1366,13 @@ def view_shared_file(request, fileshare): data['can_edit_file'] = ret_dict['can_edit_file'] data['file_perm'] = ret_dict['file_perm'] + if not request.user.is_authenticated: + from seahub.utils import get_logo_path_by_user + data['logo_path'] = get_logo_path_by_user(shared_by) + return render(request, template, data) + @share_link_audit @share_link_login_required def view_file_via_shared_dir(request, fileshare): @@ -1626,6 +1630,10 @@ def view_file_via_shared_dir(request, fileshare): data['can_edit_file'] = ret_dict['can_edit_file'] data['file_perm'] = ret_dict['file_perm'] + if not request.user.is_authenticated: + from seahub.utils import get_logo_path_by_user + data['logo_path'] = get_logo_path_by_user(shared_by) + return render(request, template, data) @login_required diff --git a/seahub/views/repo.py b/seahub/views/repo.py index 27972ba96e..9fca203a2e 100644 --- a/seahub/views/repo.py +++ b/seahub/views/repo.py @@ -349,28 +349,34 @@ def view_shared_dir(request, fileshare): dir_share_link = request.path desc_for_ogp = _('Share link for %s.') % dir_name - return render(request, template, { - 'repo': repo, - 'token': token, - 'path': req_path, - 'username': username, - 'dir_name': dir_name, - 'dir_path': real_path, - 'file_list': file_list, - 'dir_list': dir_list, - 'zipped': zipped, - 'traffic_over_limit': False, - 'max_upload_file_size': max_upload_file_size, - 'no_quota': no_quota, - 'permissions': permissions, - 'mode': mode, - 'thumbnail_size': thumbnail_size, - 'dir_share_link': dir_share_link, - 'desc_for_ogp': desc_for_ogp, - 'enable_share_link_report_abuse': ENABLE_SHARE_LINK_REPORT_ABUSE, - 'enable_video_thumbnail': ENABLE_VIDEO_THUMBNAIL, - 'enable_pdf_thumbnail': ENABLE_PDF_THUMBNAIL, - }) + data = { + 'repo': repo, + 'token': token, + 'path': req_path, + 'username': username, + 'dir_name': dir_name, + 'dir_path': real_path, + 'file_list': file_list, + 'dir_list': dir_list, + 'zipped': zipped, + 'traffic_over_limit': False, + 'max_upload_file_size': max_upload_file_size, + 'no_quota': no_quota, + 'permissions': permissions, + 'mode': mode, + 'thumbnail_size': thumbnail_size, + 'dir_share_link': dir_share_link, + 'desc_for_ogp': desc_for_ogp, + 'enable_share_link_report_abuse': ENABLE_SHARE_LINK_REPORT_ABUSE, + 'enable_video_thumbnail': ENABLE_VIDEO_THUMBNAIL, + 'enable_pdf_thumbnail': ENABLE_PDF_THUMBNAIL, + } + + if not request.user.is_authenticated: + from seahub.utils import get_logo_path_by_user + data['logo_path'] = get_logo_path_by_user(fileshare.username) + + return render(request, template, data) @share_link_audit From 8ad875a7887beeea9f07641cf7ae14b0782de4b9 Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 11 Oct 2024 15:33:07 +0800 Subject: [PATCH 2/2] update --- seahub/views/repo.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/seahub/views/repo.py b/seahub/views/repo.py index 9fca203a2e..e11c28fb9d 100644 --- a/seahub/views/repo.py +++ b/seahub/views/repo.py @@ -422,15 +422,21 @@ def view_shared_upload_link(request, uploadlink): logger.error(e) max_upload_file_size = -1 - return render(request, 'view_shared_upload_link_react.html', { - 'repo': repo, - 'path': path, - 'username': username, - 'dir_name': dir_name, - 'max_upload_file_size': max_upload_file_size, - 'no_quota': no_quota, - 'uploadlink': uploadlink, - 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, - 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, - 'max_number_of_files_for_fileupload': MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD, - }) + data = { + 'repo': repo, + 'path': path, + 'username': username, + 'dir_name': dir_name, + 'max_upload_file_size': max_upload_file_size, + 'no_quota': no_quota, + 'uploadlink': uploadlink, + 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, + 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, + 'max_number_of_files_for_fileupload': MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD, + } + + if not request.user.is_authenticated: + from seahub.utils import get_logo_path_by_user + data['logo_path'] = get_logo_path_by_user(uploadlink.username) + + return render(request, 'view_shared_upload_link_react.html', data)