@ -321,7 +321,7 @@ func GetLabelsByIDs(labelIDs []int64) ([]*Label, error) {
return labels , x . Table ( "label" ) .
return labels , x . Table ( "label" ) .
In ( "id" , labelIDs ) .
In ( "id" , labelIDs ) .
Asc ( "name" ) .
Asc ( "name" ) .
Cols ( "id" ) .
Cols ( "id" , "repo_id" , "org_id" ) .
Find ( & labels )
Find ( & labels )
}
}
@ -632,6 +632,8 @@ func HasIssueLabel(issueID, labelID int64) bool {
return hasIssueLabel ( x , issueID , labelID )
return hasIssueLabel ( x , issueID , labelID )
}
}
// newIssueLabel this function creates a new label it does not check if the label is valid for the issue
// YOU MUST CHECK THIS BEFORE THIS FUNCTION
func newIssueLabel ( e * xorm . Session , issue * Issue , label * Label , doer * User ) ( err error ) {
func newIssueLabel ( e * xorm . Session , issue * Issue , label * Label , doer * User ) ( err error ) {
if _ , err = e . Insert ( & IssueLabel {
if _ , err = e . Insert ( & IssueLabel {
IssueID : issue . ID ,
IssueID : issue . ID ,
@ -671,6 +673,15 @@ func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
return err
return err
}
}
if err = issue . loadRepo ( sess ) ; err != nil {
return err
}
// Do NOT add invalid labels
if issue . RepoID != label . RepoID && issue . Repo . OwnerID != label . OrgID {
return nil
}
if err = newIssueLabel ( sess , issue , label , doer ) ; err != nil {
if err = newIssueLabel ( sess , issue , label , doer ) ; err != nil {
return err
return err
}
}
@ -683,13 +694,19 @@ func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
return sess . Commit ( )
return sess . Commit ( )
}
}
// newIssueLabels add labels to an issue. It will check if the labels are valid for the issue
func newIssueLabels ( e * xorm . Session , issue * Issue , labels [ ] * Label , doer * User ) ( err error ) {
func newIssueLabels ( e * xorm . Session , issue * Issue , labels [ ] * Label , doer * User ) ( err error ) {
for i := range labels {
if err = issue . loadRepo ( e ) ; err != nil {
if hasIssueLabel ( e , issue . ID , labels [ i ] . ID ) {
return err
}
for _ , label := range labels {
// Don't add already present labels and invalid labels
if hasIssueLabel ( e , issue . ID , label . ID ) ||
( label . RepoID != issue . RepoID && label . OrgID != issue . Repo . OwnerID ) {
continue
continue
}
}
if err = newIssueLabel ( e , issue , labels [ i ] , doer ) ; err != nil {
if err = newIssueLabel ( e , issue , label , doer ) ; err != nil {
return fmt . Errorf ( "newIssueLabel: %v" , err )
return fmt . Errorf ( "newIssueLabel: %v" , err )
}
}
}
}