mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Rename almost all Ctx functions (#22071)
This commit is contained in:
		@@ -99,55 +99,42 @@ func getCollaborations(ctx context.Context, repoID int64, listOptions db.ListOpt
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ChangeCollaborationAccessMode sets new access mode for the collaboration.
 | 
			
		||||
func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid int64, mode perm.AccessMode) error {
 | 
			
		||||
func ChangeCollaborationAccessMode(ctx context.Context, repo *Repository, uid int64, mode perm.AccessMode) error {
 | 
			
		||||
	// Discard invalid input
 | 
			
		||||
	if mode <= perm.AccessModeNone || mode > perm.AccessModeOwner {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	e := db.GetEngine(ctx)
 | 
			
		||||
	return db.AutoTx(ctx, func(ctx context.Context) error {
 | 
			
		||||
		e := db.GetEngine(ctx)
 | 
			
		||||
 | 
			
		||||
		collaboration := &Collaboration{
 | 
			
		||||
			RepoID: repo.ID,
 | 
			
		||||
			UserID: uid,
 | 
			
		||||
		}
 | 
			
		||||
		has, err := e.Get(collaboration)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("get collaboration: %w", err)
 | 
			
		||||
		} else if !has {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if collaboration.Mode == mode {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		collaboration.Mode = mode
 | 
			
		||||
 | 
			
		||||
		if _, err = e.
 | 
			
		||||
			ID(collaboration.ID).
 | 
			
		||||
			Cols("mode").
 | 
			
		||||
			Update(collaboration); err != nil {
 | 
			
		||||
			return fmt.Errorf("update collaboration: %w", err)
 | 
			
		||||
		} else if _, err = e.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, uid, repo.ID); err != nil {
 | 
			
		||||
			return fmt.Errorf("update access table: %w", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	collaboration := &Collaboration{
 | 
			
		||||
		RepoID: repo.ID,
 | 
			
		||||
		UserID: uid,
 | 
			
		||||
	}
 | 
			
		||||
	has, err := e.Get(collaboration)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("get collaboration: %w", err)
 | 
			
		||||
	} else if !has {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if collaboration.Mode == mode {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	collaboration.Mode = mode
 | 
			
		||||
 | 
			
		||||
	if _, err = e.
 | 
			
		||||
		ID(collaboration.ID).
 | 
			
		||||
		Cols("mode").
 | 
			
		||||
		Update(collaboration); err != nil {
 | 
			
		||||
		return fmt.Errorf("update collaboration: %w", err)
 | 
			
		||||
	} else if _, err = e.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, uid, repo.ID); err != nil {
 | 
			
		||||
		return fmt.Errorf("update access table: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ChangeCollaborationAccessMode sets new access mode for the collaboration.
 | 
			
		||||
func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.AccessMode) error {
 | 
			
		||||
	ctx, committer, err := db.TxContext(db.DefaultContext)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer committer.Close()
 | 
			
		||||
 | 
			
		||||
	if err := ChangeCollaborationAccessModeCtx(ctx, repo, uid, mode); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return committer.Commit()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user