🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add `EnableUserEditing`, to control whether a regular user can change their own details (default `true`)
Deluan7feda4bea42d
diff --git a/conf/configuration.go b/conf/configuration.goindex a1dcc9335..671ee02ec 100644--- a/conf/configuration.go+++ b/conf/configuration.go@@ -42,6 +42,7 @@ type configOptions struct {EnableGravatar boolEnableFavourites boolEnableStarRating bool+ EnableUserEditing boolDefaultTheme stringGATrackingID stringEnableLogRedacting bool@@ -148,6 +149,7 @@ func init() {viper.SetDefault("enablegravatar", false)viper.SetDefault("enablefavourites", true)viper.SetDefault("enablestarrating", true)+ viper.SetDefault("enableuserediting", true)viper.SetDefault("defaulttheme", "Dark")viper.SetDefault("gatrackingid", "")viper.SetDefault("enablelogredacting", true)diff --git a/persistence/user_repository.go b/persistence/user_repository.goindex bfcb42ee7..a816dc00f 100644--- a/persistence/user_repository.go+++ b/persistence/user_repository.go@@ -4,6 +4,8 @@ import ("context""time"+ "github.com/navidrome/navidrome/conf"+. "github.com/Masterminds/squirrel""github.com/astaxie/beego/orm""github.com/deluan/rest"@@ -145,6 +147,9 @@ func (r *userRepository) Update(entity interface{}, cols ...string) error {return rest.ErrPermissionDenied}if !usr.IsAdmin {+ if !conf.Server.EnableUserEditing {+ return rest.ErrPermissionDenied+ }u.IsAdmin = falseu.UserName = usr.UserName}diff --git a/server/app/serve_index.go b/server/app/serve_index.goindex 2f48f567e..02f54b4e4 100644--- a/server/app/serve_index.go+++ b/server/app/serve_index.go@@ -48,6 +48,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {"losslessFormats": strings.ToUpper(strings.Join(consts.LosslessFormats, ",")),"devActivityPanel": conf.Server.DevActivityPanel,"devFastAccessCoverArt": conf.Server.DevFastAccessCoverArt,+ "enableUserEditing": conf.Server.EnableUserEditing,}j, err := json.Marshal(appConfig)if err != nil {diff --git a/server/app/serve_index_test.go b/server/app/serve_index_test.goindex 180cc4cdd..04f4c80c9 100644--- a/server/app/serve_index_test.go+++ b/server/app/serve_index_test.go@@ -189,6 +189,16 @@ var _ = Describe("serveIndex", func() {expected := strings.ToUpper(strings.Join(consts.LosslessFormats, ","))Expect(config).To(HaveKeyWithValue("losslessFormats", expected))})++ It("sets the enableUserEditing", func() {+ r := httptest.NewRequest("GET", "/index.html", nil)+ w := httptest.NewRecorder()++ serveIndex(ds, fs)(w, r)++ config := extractAppConfig(w.Body.String())+ Expect(config).To(HaveKeyWithValue("enableUserEditing", true))+ })})var appConfigRegex = regexp.MustCompile(`(?m)window.__APP_CONFIG__="([^"]*)`)diff --git a/ui/src/config.js b/ui/src/config.jsindex 8f9a218a4..ec7a3c8b2 100644--- a/ui/src/config.js+++ b/ui/src/config.js@@ -17,6 +17,7 @@ const defaultConfig = {devFastAccessCoverArt: false,enableStarRating: true,defaultTheme: 'Dark',+ enableUserEditing: true,}let configdiff --git a/ui/src/layout/AppBar.js b/ui/src/layout/AppBar.jsindex 3ac1310bb..bc8a7c610 100644--- a/ui/src/layout/AppBar.js+++ b/ui/src/layout/AppBar.js@@ -80,6 +80,9 @@ const CustomUserMenu = ({ onClick, ...rest }) => {return null}if (permissions !== 'admin') {+ if (!config.enableUserEditing) {+ return null+ }userResource.icon = PersonIcon} else {userResource.icon = SupervisorAccountIcon