From 3d287da5cea12e043bcf83f8b8610a97896770a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Fri, 16 Aug 2024 11:01:51 +0200 Subject: [PATCH] refactor: simplify getting the app url for collabora --- .../pkg/service/grpc/v0/service.go | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index 41a50df81a..1458a4e27e 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -157,20 +157,28 @@ func (s *Service) getAppUrlFor(action, fileExt string) string { // "edit" urls will be prioritized. Note that "view" url might be returned for // "read/write" view mode if no "edit" url is found. func (s *Service) getAppUrl(fileExt string, viewMode appproviderv1beta1.ViewMode) string { - // check view_comment action first (for collabora) - appURL := s.getAppUrlFor("view_comment", fileExt) - // prioritize view action if possible - if viewAppURL := s.getAppUrlFor("view", fileExt); viewAppURL != "" { - appURL = viewAppURL - } + appURL := s.getAppUrlFor("view", fileExt) - // If read/write mode has been requested, prioritize edit action. - // Special case for collabora because it only provides one action per - // extension, - if viewMode == appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE || strings.ToLower(s.config.App.Name) == "collabora" { - if editAppURL := s.getAppUrlFor("edit", fileExt); editAppURL != "" { - appURL = editAppURL + if strings.ToLower(s.config.App.Name) == "collabora" { + // collabora provides only one action per extension. usual options + // are "view" (checked above), "edit" or "view_comment" (this last one + // is exclusive of collabora) + if appURL == "" { + if editURL := s.getAppUrlFor("edit", fileExt); editURL != "" { + return editURL + } + if commentURL := s.getAppUrlFor("view_comment", fileExt); commentURL != "" { + return commentURL + } + } + } else { + // If not collabora, there might be an edit action for the extension. + // If read/write mode has been requested, prioritize edit action. + if viewMode == appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE { + if editAppURL := s.getAppUrlFor("edit", fileExt); editAppURL != "" { + appURL = editAppURL + } } }