From 2a827544ef9d997915e4c930b0c8cd6ed2a53683 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Mon, 1 Aug 2022 19:41:18 +0200 Subject: [PATCH] allow to edit profile to users logged in via OIDC Fixes #942 Signed-off-by: Nicola Murino --- internal/httpd/oidc_test.go | 2 +- internal/httpd/server.go | 7 ++-- internal/httpd/webclient.go | 74 +++++++++++++++++------------------ templates/webclient/base.html | 2 - 4 files changed, 40 insertions(+), 45 deletions(-) diff --git a/internal/httpd/oidc_test.go b/internal/httpd/oidc_test.go index ae28cd30..71df439f 100644 --- a/internal/httpd/oidc_test.go +++ b/internal/httpd/oidc_test.go @@ -484,7 +484,7 @@ func TestOIDCLoginLogout(t *testing.T) { r.RequestURI = webClientProfilePath r.Header.Set("Cookie", fmt.Sprintf("%v=%v", oidcCookieKey, tokenCookie)) server.router.ServeHTTP(rr, r) - assert.Equal(t, http.StatusForbidden, rr.Code) + assert.Equal(t, http.StatusOK, rr.Code) // the user can access the allowed pages rr = httptest.NewRecorder() r, err = http.NewRequest(http.MethodGet, webClientFilesPath, nil) diff --git a/internal/httpd/server.go b/internal/httpd/server.go index f1345e23..3e6a941a 100644 --- a/internal/httpd/server.go +++ b/internal/httpd/server.go @@ -1454,10 +1454,9 @@ func (s *httpdServer) setupWebClientRoutes() { Delete(webClientDirsPath, deleteUserDir) router.With(s.checkSecondFactorRequirement, s.refreshCookie). Get(webClientDownloadZipPath, s.handleWebClientDownloadZip) - router.With(s.checkSecondFactorRequirement, s.refreshCookie, s.requireBuiltinLogin). - Get(webClientProfilePath, s.handleClientGetProfile) - router.With(s.checkSecondFactorRequirement, s.requireBuiltinLogin). - Post(webClientProfilePath, s.handleWebClientProfilePost) + router.With(s.checkSecondFactorRequirement, s.refreshCookie).Get(webClientProfilePath, + s.handleClientGetProfile) + router.With(s.checkSecondFactorRequirement).Post(webClientProfilePath, s.handleWebClientProfilePost) router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)). Get(webChangeClientPwdPath, s.handleWebClientChangePwd) router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)). diff --git a/internal/httpd/webclient.go b/internal/httpd/webclient.go index 8e90a00b..a4d8cbda 100644 --- a/internal/httpd/webclient.go +++ b/internal/httpd/webclient.go @@ -94,25 +94,24 @@ func isZeroTime(t time.Time) bool { } type baseClientPage struct { - Title string - CurrentURL string - FilesURL string - SharesURL string - ShareURL string - ProfileURL string - ChangePwdURL string - StaticURL string - LogoutURL string - MFAURL string - MFATitle string - FilesTitle string - SharesTitle string - ProfileTitle string - Version string - CSRFToken string - HasExternalLogin bool - LoggedUser *dataprovider.User - Branding UIBranding + Title string + CurrentURL string + FilesURL string + SharesURL string + ShareURL string + ProfileURL string + ChangePwdURL string + StaticURL string + LogoutURL string + MFAURL string + MFATitle string + FilesTitle string + SharesTitle string + ProfileTitle string + Version string + CSRFToken string + LoggedUser *dataprovider.User + Branding UIBranding } type dirMapping struct { @@ -351,25 +350,24 @@ func (s *httpdServer) getBaseClientPageData(title, currentURL string, r *http.Re v := version.Get() return baseClientPage{ - Title: title, - CurrentURL: currentURL, - FilesURL: webClientFilesPath, - SharesURL: webClientSharesPath, - ShareURL: webClientSharePath, - ProfileURL: webClientProfilePath, - ChangePwdURL: webChangeClientPwdPath, - StaticURL: webStaticFilesPath, - LogoutURL: webClientLogoutPath, - MFAURL: webClientMFAPath, - MFATitle: pageClient2FATitle, - FilesTitle: pageClientFilesTitle, - SharesTitle: pageClientSharesTitle, - ProfileTitle: pageClientProfileTitle, - Version: fmt.Sprintf("%v-%v", v.Version, v.CommitHash), - CSRFToken: csrfToken, - HasExternalLogin: isLoggedInWithOIDC(r), - LoggedUser: getUserFromToken(r), - Branding: s.binding.Branding.WebClient, + Title: title, + CurrentURL: currentURL, + FilesURL: webClientFilesPath, + SharesURL: webClientSharesPath, + ShareURL: webClientSharePath, + ProfileURL: webClientProfilePath, + ChangePwdURL: webChangeClientPwdPath, + StaticURL: webStaticFilesPath, + LogoutURL: webClientLogoutPath, + MFAURL: webClientMFAPath, + MFATitle: pageClient2FATitle, + FilesTitle: pageClientFilesTitle, + SharesTitle: pageClientSharesTitle, + ProfileTitle: pageClientProfileTitle, + Version: fmt.Sprintf("%v-%v", v.Version, v.CommitHash), + CSRFToken: csrfToken, + LoggedUser: getUserFromToken(r), + Branding: s.binding.Branding.WebClient, } } diff --git a/templates/webclient/base.html b/templates/webclient/base.html index e4cc6301..79be2cb7 100644 --- a/templates/webclient/base.html +++ b/templates/webclient/base.html @@ -80,13 +80,11 @@ along with this program. If not, see . {{.SharesTitle}} {{end}} - {{if not .HasExternalLogin}} - {{end}} {{if .LoggedUser.CanManageMFA}}