auth
auth/profile.go
Stop soft-deleting Profiles and actually delete them. The information we're storing in Profiles isn't unique enough that we should go through the hassle we're going through to soft-delete it. Add a deleteProfile method to our profileStore, and implement it for our postgres and memstore implementations. Add a DeleteProfile wrapper for our Context. Remove the Deleted property from the Profile type and the ProfileChange type, and update references to it. Stop cleaning up after our Profile in the UpdateProfileHandler, because there's no longer any way to delete the Profile from the UpdateProfileHandler. Update our get/list* methods so they don't filter on the non-existent Deleted property anymore. Update our SQL schema definition to not include the deleted column. Update our profile tests to use the DeleteProfile method and stop comparing the no-longer-existing Deleted property.
1.1 --- a/profile.go Sat Apr 11 17:23:15 2015 -0400 1.2 +++ b/profile.go Sat Apr 11 17:58:15 2015 -0400 1.3 @@ -79,7 +79,6 @@ 1.4 PassphraseResetCreated time.Time `json:"-"` 1.5 Created time.Time `json:"created,omitempty"` 1.6 LastSeen time.Time `json:"last_seen,omitempty"` 1.7 - Deleted bool `json:"deleted,omitempty"` 1.8 } 1.9 1.10 // ApplyChange applies the properties of the passed ProfileChange 1.11 @@ -115,9 +114,6 @@ 1.12 if change.LastSeen != nil { 1.13 p.LastSeen = *change.LastSeen 1.14 } 1.15 - if change.Deleted != nil { 1.16 - p.Deleted = *change.Deleted 1.17 - } 1.18 } 1.19 1.20 // ApplyBulkChange applies the properties of the passed BulkProfileChange 1.21 @@ -140,11 +136,10 @@ 1.22 PassphraseReset *string 1.23 PassphraseResetCreated *time.Time 1.24 LastSeen *time.Time 1.25 - Deleted *bool 1.26 } 1.27 1.28 func (c ProfileChange) Empty() bool { 1.29 - return (c.Name == nil && c.Passphrase == nil && c.Iterations == nil && c.Salt == nil && c.PassphraseScheme == nil && c.Compromised == nil && c.LockedUntil == nil && c.PassphraseReset == nil && c.PassphraseResetCreated == nil && c.LastSeen == nil && c.Deleted == nil) 1.30 + return (c.Name == nil && c.Passphrase == nil && c.Iterations == nil && c.Salt == nil && c.PassphraseScheme == nil && c.Compromised == nil && c.LockedUntil == nil && c.PassphraseReset == nil && c.PassphraseResetCreated == nil && c.LastSeen == nil) 1.31 } 1.32 1.33 // Validate checks the ProfileChange it is called on 1.34 @@ -262,6 +257,7 @@ 1.35 saveProfile(profile Profile) error 1.36 updateProfile(id uuid.ID, change ProfileChange) error 1.37 updateProfiles(ids []uuid.ID, change BulkProfileChange) error 1.38 + deleteProfile(id uuid.ID) error 1.39 1.40 addLogin(login Login) error 1.41 removeLogin(value string, profile uuid.ID) error 1.42 @@ -277,9 +273,6 @@ 1.43 if !ok { 1.44 return Profile{}, ErrProfileNotFound 1.45 } 1.46 - if p.Deleted { 1.47 - return Profile{}, ErrProfileNotFound 1.48 - } 1.49 return p, nil 1.50 } 1.51 1.52 @@ -296,9 +289,6 @@ 1.53 if !ok { 1.54 return Profile{}, ErrProfileNotFound 1.55 } 1.56 - if profile.Deleted { 1.57 - return Profile{}, ErrProfileNotFound 1.58 - } 1.59 return profile, nil 1.60 } 1.61 1.62 @@ -340,6 +330,16 @@ 1.63 return nil 1.64 } 1.65 1.66 +func (m *memstore) deleteProfile(id uuid.ID) error { 1.67 + m.profileLock.Lock() 1.68 + defer m.profileLock.Unlock() 1.69 + if _, ok := m.profiles[id.String()]; !ok { 1.70 + return ErrProfileNotFound 1.71 + } 1.72 + delete(m.profiles, id.String()) 1.73 + return nil 1.74 +} 1.75 + 1.76 func (m *memstore) addLogin(login Login) error { 1.77 m.loginLock.Lock() 1.78 defer m.loginLock.Unlock() 1.79 @@ -630,9 +630,6 @@ 1.80 encode(w, r, http.StatusInternalServerError, actOfGodResponse) 1.81 return 1.82 } 1.83 - if !profile.Deleted && req.Deleted != nil && *req.Deleted { 1.84 - go cleanUpAfterProfileDeletion(profile.ID, context) 1.85 - } 1.86 profile.ApplyChange(req) 1.87 encode(w, r, http.StatusOK, response{Profiles: []Profile{profile}}) 1.88 return 1.89 @@ -674,10 +671,7 @@ 1.90 encode(w, r, http.StatusForbidden, response{Errors: errors}) 1.91 return 1.92 } 1.93 - var change ProfileChange 1.94 - deleted := true 1.95 - change.Deleted = &deleted 1.96 - err = context.UpdateProfile(id, change) 1.97 + err = context.DeleteProfile(id) 1.98 if err != nil { 1.99 if err == ErrProfileNotFound { 1.100 errors = append(errors, requestError{Slug: requestErrNotFound}) 1.101 @@ -687,7 +681,6 @@ 1.102 encode(w, r, http.StatusInternalServerError, actOfGodResponse) 1.103 return 1.104 } 1.105 - profile.ApplyChange(change) 1.106 encode(w, r, http.StatusOK, response{Profiles: []Profile{profile}}) 1.107 go cleanUpAfterProfileDeletion(profile.ID, context) 1.108 }