Skip to content

Commit 85f2c4c

Browse files
authored
Disable PUT /profile/ modifying Points (HackIllinois#398)
* Can't edit points in UpdateProfile * emphasize in the docs * Revert the tests * Put logic in the controller * err != nil check
1 parent 8f7bde0 commit 85f2c4c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

documentation/docs/reference/services/Profile.md

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ PUT /profile/
128128

129129
Updates the profile for the user with the `id` in the JWT token provided in the Authorization header.
130130
This returns the updated profile information.
131+
Note you can not edit the ``points`` field through this.
131132

132133
Request format:
133134
```

services/profile/controller/controller.go

+11
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ func UpdateProfile(w http.ResponseWriter, r *http.Request) {
134134
var profile models.Profile
135135
json.NewDecoder(r.Body).Decode(&profile)
136136

137+
old_profile, err := service.GetProfile(profile_id)
138+
139+
if err != nil {
140+
errors.WriteError(w, r, errors.DatabaseError(err.Error(), "Could not get profile associated with this profile id."))
141+
return
142+
}
143+
144+
if profile.Points != old_profile.Points {
145+
profile.Points = old_profile.Points
146+
}
147+
137148
err = service.UpdateProfile(profile_id, profile)
138149

139150
if err != nil {

0 commit comments

Comments
 (0)