User control patch
Changed available actions done by an admin to itself: admin can no longer remove itself from users list, admin can no longer change its user type to manager.
This commit is contained in:
		
							parent
							
								
									4cc79da4cf
								
							
						
					
					
						commit
						93731c3f3e
					
				|  | @ -215,7 +215,10 @@ func UpdateUser(db store.IStore) echo.HandlerFunc { | ||||||
| 			} | 			} | ||||||
| 			user.PasswordHash = hash | 			user.PasswordHash = hash | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  | 		if previousUsername != currentUser(c) { | ||||||
| 			user.Admin = admin | 			user.Admin = admin | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		if err := db.DeleteUser(previousUsername); err != nil { | 		if err := db.DeleteUser(previousUsername); err != nil { | ||||||
| 			return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, err.Error()}) | 			return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, err.Error()}) | ||||||
|  | @ -289,6 +292,10 @@ func RemoveUser(db store.IStore) echo.HandlerFunc { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		username := data["username"].(string) | 		username := data["username"].(string) | ||||||
|  | 
 | ||||||
|  | 		if username == currentUser(c) { | ||||||
|  | 			return c.JSON(http.StatusForbidden, jsonHTTPResponse{false, "User cannot delete itself"}) | ||||||
|  | 		} | ||||||
| 		// delete user from database
 | 		// delete user from database
 | ||||||
| 
 | 
 | ||||||
| 		if err := db.DeleteUser(username); err != nil { | 		if err := db.DeleteUser(username); err != nil { | ||||||
|  | @ -297,10 +304,7 @@ func RemoveUser(db store.IStore) echo.HandlerFunc { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		log.Infof("Removed user: %s", username) | 		log.Infof("Removed user: %s", username) | ||||||
| 		if username == currentUser(c) { | 
 | ||||||
| 			log.Infof("You removed yourself, killing session") |  | ||||||
| 			clearSession(c) |  | ||||||
| 		} |  | ||||||
| 		return c.JSON(http.StatusOK, jsonHTTPResponse{true, "User removed"}) | 		return c.JSON(http.StatusOK, jsonHTTPResponse{true, "User removed"}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue