mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Check if project has the same repository id with issue when assign project to issue (#20133)
* Check if project has the same repository id with issue when assign project to issue * Check if issue's repository id match project's repository id * Add more permission checking * Remove invalid argument * Fix errors * Add generic check * Remove duplicated check * Return error + add check for new issues * Apply suggestions from code review Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		@@ -124,6 +124,17 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64
 | 
			
		||||
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
 | 
			
		||||
	oldProjectID := issue.projectID(ctx)
 | 
			
		||||
 | 
			
		||||
	// Only check if we add a new project and not remove it.
 | 
			
		||||
	if newProjectID > 0 {
 | 
			
		||||
		newProject, err := project_model.GetProjectByID(ctx, newProjectID)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if newProject.RepoID != issue.RepoID {
 | 
			
		||||
			return fmt.Errorf("issue's repository is not the same as project's repository")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -124,6 +124,11 @@ func NewMilestone(m *Milestone) (err error) {
 | 
			
		||||
	return committer.Commit()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HasMilestoneByRepoID returns if the milestone exists in the repository.
 | 
			
		||||
func HasMilestoneByRepoID(ctx context.Context, repoID, id int64) (bool, error) {
 | 
			
		||||
	return db.GetEngine(ctx).ID(id).Where("repo_id=?", repoID).Exist(new(Milestone))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetMilestoneByRepoID returns the milestone in a repository.
 | 
			
		||||
func GetMilestoneByRepoID(ctx context.Context, repoID, id int64) (*Milestone, error) {
 | 
			
		||||
	m := new(Milestone)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user