You've already forked woodpecker
							
							
				mirror of
				https://github.com/woodpecker-ci/woodpecker.git
				synced 2025-10-30 23:27:39 +02:00 
			
		
		
		
	fixed permission insert to use upsert for improved sync
This commit is contained in:
		| @@ -23,6 +23,11 @@ func (db *Permstore) GetPerm(user *model.User, repo *model.Repo) (*model.Perm, e | ||||
|  | ||||
| // PostPerm saves permission in the datastore. | ||||
| func (db *Permstore) PostPerm(perm *model.Perm) error { | ||||
| 	var _perm = new(model.Perm) | ||||
| 	meddler.QueryRow(db, _perm, rebind(permQuery), perm.UserID, perm.RepoID) | ||||
| 	if _perm.ID != 0 { | ||||
| 		perm.ID = _perm.ID | ||||
| 	} | ||||
| 	return meddler.Save(db, permTable, perm) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -47,6 +47,29 @@ func TestPermstore(t *testing.T) { | ||||
| 			g.Assert(perm1.ID != 0).IsTrue() | ||||
| 		}) | ||||
|  | ||||
| 		g.It("Should Upsert a Perm", func() { | ||||
| 			perm1 := model.Perm{ | ||||
| 				UserID: 1, | ||||
| 				RepoID: 2, | ||||
| 				Read:   true, | ||||
| 				Write:  true, | ||||
| 				Admin:  true, | ||||
| 			} | ||||
| 			ps.PostPerm(&perm1) | ||||
| 			perm1.Read = true | ||||
| 			perm1.Write = true | ||||
| 			perm1.Admin = false | ||||
| 			perm1.ID = 0 | ||||
| 			err := ps.PostPerm(&perm1) | ||||
| 			g.Assert(err == nil).IsTrue() | ||||
| 			g.Assert(perm1.ID != 0).IsTrue() | ||||
| 			getperm, err := ps.GetPerm(&model.User{ID: 1}, &model.Repo{ID: 2}) | ||||
| 			g.Assert(err == nil).IsTrue() | ||||
| 			g.Assert(getperm.Read).IsTrue() | ||||
| 			g.Assert(getperm.Write).IsTrue() | ||||
| 			g.Assert(getperm.Admin).IsFalse() | ||||
| 		}) | ||||
|  | ||||
| 		g.It("Should Get a Perm", func() { | ||||
| 			ps.PostPerm(&model.Perm{ | ||||
| 				UserID: 1, | ||||
| @@ -81,24 +104,5 @@ func TestPermstore(t *testing.T) { | ||||
| 			g.Assert(err2 == nil).IsTrue() | ||||
| 			g.Assert(err3 == nil).IsFalse() | ||||
| 		}) | ||||
|  | ||||
| 		g.It("Should Enforce Unique Perm", func() { | ||||
| 			err1 := ps.PostPerm(&model.Perm{ | ||||
| 				UserID: 1, | ||||
| 				RepoID: 2, | ||||
| 				Read:   true, | ||||
| 				Write:  true, | ||||
| 				Admin:  true, | ||||
| 			}) | ||||
| 			err2 := ps.PostPerm(&model.Perm{ | ||||
| 				UserID: 1, | ||||
| 				RepoID: 2, | ||||
| 				Read:   true, | ||||
| 				Write:  true, | ||||
| 				Admin:  true, | ||||
| 			}) | ||||
| 			g.Assert(err1 == nil).IsTrue() | ||||
| 			g.Assert(err2 == nil).IsFalse() | ||||
| 		}) | ||||
| 	}) | ||||
| } | ||||
|   | ||||
| @@ -94,9 +94,6 @@ func GetLogin(c web.C, w http.ResponseWriter, r *http.Request) { | ||||
| 	// | ||||
| 	// todo(bradrydzewski) this login should be a bit more intelligent | ||||
| 	//      than the current implementation. | ||||
| 	// | ||||
| 	// todo(bradrydzewski) the github implementation will only sync a | ||||
| 	//      maximum of 100 repositories due to the api pagination. need to fix. | ||||
| 	if u.Syncing { | ||||
| 		redirect = "/sync" | ||||
| 		log.Println("sync user account.", u.Login) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user