Skip to content

Commit

Permalink
improve flush capability during sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Jul 16, 2017
1 parent b078f1a commit d5200ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion model/perm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type PermStore interface {
PermUpsert(perm *Perm) error
PermBatch(perms []*Perm) error
PermDelete(perm *Perm) error
// PermFlush(user *User) error
PermFlush(user *User, before int64) error
}

// Perm defines a repository permission for an individual user.
Expand Down
15 changes: 13 additions & 2 deletions server/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type syncer struct {
}

func (s *syncer) Sync(user *model.User) error {
unix := time.Now().Unix()
unix := time.Now().Unix() - 1 // force immediate expiration
repos, err := s.remote.Repos(user)
if err != nil {
return err
Expand Down Expand Up @@ -51,5 +51,16 @@ func (s *syncer) Sync(user *model.User) error {
return err
}

return nil
// this is here as a precaution. I want to make sure that if an api
// call to the version control system fails and (for some reason) returns
// an empty list, we don't wipe out the user repository permissions.
//
// the side-effect of this code is that a user with 1 repository whose
// access is removed will still display in the feed, but they will not
// be able to access the actual repository data.
if len(repos) == 0 {
return nil
}

return s.perms.PermFlush(user, unix)
}
6 changes: 6 additions & 0 deletions store/datastore/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ func (db *datastore) PermDelete(perm *model.Perm) error {
_, err := db.Exec(stmt, perm.UserID, perm.RepoID)
return err
}

func (db *datastore) PermFlush(user *model.User, before int64) error {
stmt := sql.Lookup(db.driver, "perms-delete-user-date")
_, err := db.Exec(stmt, user.ID, before)
return err
}
1 change: 1 addition & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type Store interface {
PermUpsert(perm *model.Perm) error
PermBatch(perms []*model.Perm) error
PermDelete(perm *model.Perm) error
PermFlush(user *model.User, before int64) error

ConfigLoad(int64) (*model.Config, error)
ConfigFind(*model.Repo, string) (*model.Config, error)
Expand Down

0 comments on commit d5200ad

Please sign in to comment.