瀏覽代碼

Removed global vol limit on mobile for Music module

Toby Chui 3 年之前
父節點
當前提交
643672c359
共有 7 個文件被更改,包括 50 次插入7 次删除
  1. 6 0
      mod/permission/request.go
  2. 25 0
      mod/user/user.go
  3. 1 1
      network.forward.go
  4. 1 1
      permission.go
  5. 2 4
      system.go
  6. 14 0
      user.go
  7. 1 1
      web/Music/index.html

+ 6 - 0
mod/permission/request.go

@@ -73,6 +73,12 @@ func (h *PermissionHandler) HandleGroupEdit(w http.ResponseWriter, r *http.Reque
 			return
 		}
 
+		//Do not allow removal of admin permission from administrator group
+		if isAdmin == "false" && groupname == "administrator" {
+			sendErrorResponse(w, "You cannot unset admin permission from administrator group")
+			return
+		}
+
 		quota, err := mv(r, "defaultQuota", true)
 		if err != nil {
 			sendErrorResponse(w, "Default Quota not defined")

+ 25 - 0
mod/user/user.go

@@ -157,3 +157,28 @@ func (u *UserHandler) GetUserInfoFromRequest(w http.ResponseWriter, r *http.Requ
 	}
 	return userObject, nil
 }
+
+//Get all the users given the permission group name, super IO heavy operation
+func (u *UserHandler) GetUsersInPermissionGroup(permissionGroupName string) ([]*User, error) {
+	results := []*User{}
+	//Check if the given group exists
+	if u.phandler.GetPermissionGroupByName(permissionGroupName) == nil {
+		//Permission group with given name not exists
+		return results, errors.New("Permission group not exists")
+	}
+
+	AllRegisteredUsers := u.authAgent.ListUsers()
+	for _, thisUser := range AllRegisteredUsers {
+		thisUserInfo, err := u.GetUserInfoFromUsername(thisUser)
+		if err != nil {
+			continue
+		}
+
+		//Check if the user is in the given permission group
+		if thisUserInfo.UserIsInOneOfTheGroupOf([]string{permissionGroupName}) {
+			results = append(results, thisUserInfo)
+		}
+	}
+
+	return results, nil
+}

+ 1 - 1
network.forward.go

@@ -24,7 +24,7 @@ func portForwardInit() {
 	sysdb.NewTable("portforward")
 
 	//Register modules
-	if *allow_upnp == true {
+	if *allow_upnp {
 		//Forward the previous registered paths
 		entries, _ := sysdb.ListTable("portforward")
 		for _, keypairs := range entries {

+ 1 - 1
permission.go

@@ -42,7 +42,7 @@ func permissionInit() {
 			//There are already users in the system. Only allow authorized users
 			if authAgent.CheckAuth(r) {
 				requestingUser, _ := userHandler.GetUserInfoFromRequest(w, r)
-				if requestingUser != nil && requestingUser.IsAdmin() == true {
+				if requestingUser != nil && requestingUser.IsAdmin() {
 					permissionHandler.HandleListGroup(w, r)
 				} else {
 					errorHandlePermissionDenied(w, r)

+ 2 - 4
system.go

@@ -85,13 +85,11 @@ func systemIdHandlePing(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Access-Control-Allow-Origin", "*")
 	w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
 	w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
-	status := struct {
+	js, _ := json.Marshal(struct {
 		Status string
 	}{
 		"OK",
-	}
-
-	js, _ := json.Marshal(status)
+	})
 	sendJSONResponse(w, string(js))
 }
 

+ 14 - 0
user.go

@@ -230,6 +230,20 @@ func user_handleUserEdit(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 
+		//Check if the current user is the only one admin in the administrator group and he is leaving the group
+		allAdministratorGroupUsers, err := userHandler.GetUsersInPermissionGroup("administrator")
+		if err == nil {
+			//Skip checking if error
+			if len(allAdministratorGroupUsers) == 1 && userinfo.UserIsInOneOfTheGroupOf([]string{"administrator"}) && !stringInSlice("administrator", newGroupKeys) {
+				//Current administrator group only contain 1 user
+				//This user is in the administrator group
+				//The user want to unset himself from administrator group
+				//Reject the operation as this will cause system lockdown
+				sendErrorResponse(w, "You are the only administrator. You cannot remove yourself from the administrator group.")
+				return
+			}
+		}
+
 		//Get the permission groups by their ids
 		newPermissioGroups := userHandler.GetPermissionHandler().GetPermissionGroupByNameList(newGroupKeys)
 

+ 1 - 1
web/Music/index.html

@@ -1079,7 +1079,7 @@
 		//Check if it is mobile. If yes, always 100% and leave volume to system
 		if (isMobile()){
 			globalvol = 1;
-			$(".desktopOnly").addClass("disabled");
+			//$(".desktopOnly").addClass("disabled");
 		}
 
 		audioElement[0].volume = parseFloat(globalvol);