Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
repository: ensure Grant returns not found when repository is not found
Browse files Browse the repository at this point in the history
Related to #183.
  • Loading branch information
Francisco Souza committed Feb 13, 2015
1 parent 3e6abf7 commit 9e8849c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,14 @@ func GrantAccess(rNames, uNames []string, readOnly bool) error {
return err
}
defer conn.Close()
var info *mgo.ChangeInfo
if readOnly {
_, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"readonlyusers": bson.M{"$each": uNames}}})
info, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"readonlyusers": bson.M{"$each": uNames}}})
} else {
_, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"users": bson.M{"$each": uNames}}})
info, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"users": bson.M{"$each": uNames}}})
}
if info.Updated < 1 {
return mgo.ErrNotFound
}
return err
}
Expand Down
5 changes: 5 additions & 0 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ func (s *S) TestGrantAccessShouldSkipDuplicatedUsers(c *check.C) {
c.Assert(r.Users, check.DeepEquals, []string{"umi", "luke", "pade"})
}

func (s *S) TestGrantAccessNotFound(c *check.C) {
err := GrantAccess([]string{"super-repo"}, []string{"someuser"}, false)
c.Assert(err, check.Equals, mgo.ErrNotFound)
}

func (s *S) TestRevokeAccessShouldRemoveUserFromAllRepositories(c *check.C) {
tmpdir, err := commandmocker.Add("git", "$*")
c.Assert(err, check.IsNil)
Expand Down

0 comments on commit 9e8849c

Please sign in to comment.