mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	Backport #27902 by @earl-warren
- On user deletion, delete action runners that the user has created.
- Add a database consistency check to remove action runners that have
nonexistent belonging owner.
- Resolves https://codeberg.org/forgejo/forgejo/issues/1720
(cherry picked from commit 009ca7223d)
Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>
Co-authored-by: Gusted <postmaster@gusted.xyz>
	
	
This commit is contained in:
		
					parent
					
						
							
								4c67c05480
							
						
					
				
			
			
				commit
				
					
						28e3d0b0d3
					
				
			
		
					 3 changed files with 33 additions and 0 deletions
				
			
		|  | @ -266,3 +266,27 @@ func CreateRunner(ctx context.Context, t *ActionRunner) error { | |||
| 	_, err := db.GetEngine(ctx).Insert(t) | ||||
| 	return err | ||||
| } | ||||
| 
 | ||||
| func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) { | ||||
| 	// Only affect action runners were a owner ID is set, as actions runners | ||||
| 	// could also be created on a repository. | ||||
| 	return db.GetEngine(ctx).Table("action_runner"). | ||||
| 		Join("LEFT", "user", "`action_runner`.owner_id = `user`.id"). | ||||
| 		Where("`action_runner`.owner_id != ?", 0). | ||||
| 		And(builder.IsNull{"`user`.id"}). | ||||
| 		Count(new(ActionRunner)) | ||||
| } | ||||
| 
 | ||||
| func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) { | ||||
| 	subQuery := builder.Select("`action_runner`.id"). | ||||
| 		From("`action_runner`"). | ||||
| 		Join("LEFT", "user", "`action_runner`.owner_id = `user`.id"). | ||||
| 		Where(builder.Neq{"`action_runner`.owner_id": 0}). | ||||
| 		And(builder.IsNull{"`user`.id"}) | ||||
| 	b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`") | ||||
| 	res, err := db.GetEngine(ctx).Exec(b) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return res.RowsAffected() | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue