allow to edit profile to users logged in via OIDC

Fixes #942

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-08-01 19:41:18 +02:00
parent 9d2b5dc07d
commit 2a827544ef
4 changed files with 40 additions and 45 deletions

View File

@@ -484,7 +484,7 @@ func TestOIDCLoginLogout(t *testing.T) {
r.RequestURI = webClientProfilePath r.RequestURI = webClientProfilePath
r.Header.Set("Cookie", fmt.Sprintf("%v=%v", oidcCookieKey, tokenCookie)) r.Header.Set("Cookie", fmt.Sprintf("%v=%v", oidcCookieKey, tokenCookie))
server.router.ServeHTTP(rr, r) 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 // the user can access the allowed pages
rr = httptest.NewRecorder() rr = httptest.NewRecorder()
r, err = http.NewRequest(http.MethodGet, webClientFilesPath, nil) r, err = http.NewRequest(http.MethodGet, webClientFilesPath, nil)

View File

@@ -1454,10 +1454,9 @@ func (s *httpdServer) setupWebClientRoutes() {
Delete(webClientDirsPath, deleteUserDir) Delete(webClientDirsPath, deleteUserDir)
router.With(s.checkSecondFactorRequirement, s.refreshCookie). router.With(s.checkSecondFactorRequirement, s.refreshCookie).
Get(webClientDownloadZipPath, s.handleWebClientDownloadZip) Get(webClientDownloadZipPath, s.handleWebClientDownloadZip)
router.With(s.checkSecondFactorRequirement, s.refreshCookie, s.requireBuiltinLogin). router.With(s.checkSecondFactorRequirement, s.refreshCookie).Get(webClientProfilePath,
Get(webClientProfilePath, s.handleClientGetProfile) s.handleClientGetProfile)
router.With(s.checkSecondFactorRequirement, s.requireBuiltinLogin). router.With(s.checkSecondFactorRequirement).Post(webClientProfilePath, s.handleWebClientProfilePost)
Post(webClientProfilePath, s.handleWebClientProfilePost)
router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)). router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)).
Get(webChangeClientPwdPath, s.handleWebClientChangePwd) Get(webChangeClientPwdPath, s.handleWebClientChangePwd)
router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)). router.With(s.checkSecondFactorRequirement, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)).

View File

@@ -94,25 +94,24 @@ func isZeroTime(t time.Time) bool {
} }
type baseClientPage struct { type baseClientPage struct {
Title string Title string
CurrentURL string CurrentURL string
FilesURL string FilesURL string
SharesURL string SharesURL string
ShareURL string ShareURL string
ProfileURL string ProfileURL string
ChangePwdURL string ChangePwdURL string
StaticURL string StaticURL string
LogoutURL string LogoutURL string
MFAURL string MFAURL string
MFATitle string MFATitle string
FilesTitle string FilesTitle string
SharesTitle string SharesTitle string
ProfileTitle string ProfileTitle string
Version string Version string
CSRFToken string CSRFToken string
HasExternalLogin bool LoggedUser *dataprovider.User
LoggedUser *dataprovider.User Branding UIBranding
Branding UIBranding
} }
type dirMapping struct { type dirMapping struct {
@@ -351,25 +350,24 @@ func (s *httpdServer) getBaseClientPageData(title, currentURL string, r *http.Re
v := version.Get() v := version.Get()
return baseClientPage{ return baseClientPage{
Title: title, Title: title,
CurrentURL: currentURL, CurrentURL: currentURL,
FilesURL: webClientFilesPath, FilesURL: webClientFilesPath,
SharesURL: webClientSharesPath, SharesURL: webClientSharesPath,
ShareURL: webClientSharePath, ShareURL: webClientSharePath,
ProfileURL: webClientProfilePath, ProfileURL: webClientProfilePath,
ChangePwdURL: webChangeClientPwdPath, ChangePwdURL: webChangeClientPwdPath,
StaticURL: webStaticFilesPath, StaticURL: webStaticFilesPath,
LogoutURL: webClientLogoutPath, LogoutURL: webClientLogoutPath,
MFAURL: webClientMFAPath, MFAURL: webClientMFAPath,
MFATitle: pageClient2FATitle, MFATitle: pageClient2FATitle,
FilesTitle: pageClientFilesTitle, FilesTitle: pageClientFilesTitle,
SharesTitle: pageClientSharesTitle, SharesTitle: pageClientSharesTitle,
ProfileTitle: pageClientProfileTitle, ProfileTitle: pageClientProfileTitle,
Version: fmt.Sprintf("%v-%v", v.Version, v.CommitHash), Version: fmt.Sprintf("%v-%v", v.Version, v.CommitHash),
CSRFToken: csrfToken, CSRFToken: csrfToken,
HasExternalLogin: isLoggedInWithOIDC(r), LoggedUser: getUserFromToken(r),
LoggedUser: getUserFromToken(r), Branding: s.binding.Branding.WebClient,
Branding: s.binding.Branding.WebClient,
} }
} }

View File

@@ -80,13 +80,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<span>{{.SharesTitle}}</span></a> <span>{{.SharesTitle}}</span></a>
</li> </li>
{{end}} {{end}}
{{if not .HasExternalLogin}}
<li class="nav-item {{if eq .CurrentURL .ProfileURL}}active{{end}}"> <li class="nav-item {{if eq .CurrentURL .ProfileURL}}active{{end}}">
<a class="nav-link" href="{{.ProfileURL}}"> <a class="nav-link" href="{{.ProfileURL}}">
<i class="fas fa-user"></i> <i class="fas fa-user"></i>
<span>{{.ProfileTitle}}</span></a> <span>{{.ProfileTitle}}</span></a>
</li> </li>
{{end}}
{{if .LoggedUser.CanManageMFA}} {{if .LoggedUser.CanManageMFA}}
<li class="nav-item {{if eq .CurrentURL .MFAURL}}active{{end}}"> <li class="nav-item {{if eq .CurrentURL .MFAURL}}active{{end}}">
<a class="nav-link" href="{{.MFAURL}}"> <a class="nav-link" href="{{.MFAURL}}">