@@ -545,5 +545,51 @@ func DelCommentReaction(ctx *context.APIContext, form api.CommentReaction) {
545
545
}
546
546
547
547
func setCommentReaction (ctx * context.APIContext , form api.CommentReaction , create bool ) {
548
+ comment , err := models .GetCommentByID (ctx .ParamsInt64 (":id" ))
549
+ if err != nil {
550
+ if models .IsErrCommentNotExist (err ) {
551
+ ctx .NotFound (err )
552
+ } else {
553
+ ctx .Error (500 , "GetCommentByID" , err )
554
+ }
555
+ return
556
+ }
557
+ issue , err := models .GetIssueByIndex (ctx .Repo .Repository .ID , comment .IssueID )
558
+ if err != nil {
559
+ if models .IsErrIssueNotExist (err ) {
560
+ ctx .NotFound ()
561
+ } else {
562
+ ctx .Error (500 , "GetIssueByIndex" , err )
563
+ }
564
+
565
+ return
566
+ }
567
+
568
+ for _ , u := range form .Users {
569
+ user , err := models .GetUserByName (* u )
570
+ if err != nil {
571
+ ctx .Error (500 , "GetUserByName" , err )
572
+ }
573
+
574
+ if ctx .User .ID != user .ID && ! ctx .Repo .IsAdmin () {
575
+ ctx .Status (403 )
576
+ return
577
+ }
578
+
579
+ if create {
580
+ // Create Reaction
581
+ _ , err = models .CreateCommentReaction (user ,issue ,comment ,form .Reaction )
582
+ if err != nil {
583
+ ctx .Error (500 , "CreateCommentReaction" , err )
584
+ }
585
+ } else {
586
+ // Delete Reaction
587
+ err = models .DeleteCommentReaction (user ,issue ,comment ,form .Reaction )
588
+ if err != nil {
589
+ ctx .Error (500 , "DeleteCommentReaction" , err )
590
+ }
591
+ }
592
+ }
548
593
594
+ ctx .Status (201 )
549
595
}
0 commit comments