@@ -19,6 +19,7 @@ import (
19
19
"github.com/gitploy-io/gitploy/ent"
20
20
"github.com/gitploy-io/gitploy/ent/event"
21
21
gb "github.com/gitploy-io/gitploy/internal/server/global"
22
+ "github.com/gitploy-io/gitploy/pkg/e"
22
23
)
23
24
24
25
// GetEvents streams events of deployment, or review.
@@ -42,12 +43,12 @@ func (s *Stream) GetEvents(c *gin.Context) {
42
43
return
43
44
}
44
45
45
- if ok , err := s .hasPermForEvent (ctx , u , e ); ! ok {
46
- s .log .Debug ("Skip the event. The user has not the perm." )
47
- return
48
- } else if err != nil {
46
+ if ok , err := s .hasPermForEvent (ctx , u , e ); err != nil {
49
47
s .log .Error ("It has failed to check the perm." , zap .Error (err ))
50
48
return
49
+ } else if ! ok {
50
+ s .log .Debug ("Skip the event. The user has not the perm." )
51
+ return
51
52
}
52
53
53
54
events <- e
93
94
}
94
95
95
96
// hasPermForEvent checks the user has permission for the event.
96
- func (s * Stream ) hasPermForEvent (ctx context.Context , u * ent.User , e * ent.Event ) (bool , error ) {
97
- if e .Kind == event .KindDeployment {
98
- d , err := s .i .FindDeploymentByID (ctx , e .DeploymentID )
97
+ func (s * Stream ) hasPermForEvent (ctx context.Context , u * ent.User , evt * ent.Event ) (bool , error ) {
98
+ if evt .Kind == event .KindDeployment {
99
+ d , err := s .i .FindDeploymentByID (ctx , evt .DeploymentID )
99
100
if err != nil {
100
101
return false , err
101
102
}
102
103
103
- if _ , err = s .i .FindPermOfRepo (ctx , d .Edges .Repo , u ); ent . IsNotFound (err ) {
104
+ if _ , err = s .i .FindPermOfRepo (ctx , d .Edges .Repo , u ); e . HasErrorCode (err , e . ErrorCodeEntityNotFound ) {
104
105
return false , nil
105
106
} else if err != nil {
106
107
return false , err
@@ -109,8 +110,8 @@ func (s *Stream) hasPermForEvent(ctx context.Context, u *ent.User, e *ent.Event)
109
110
return true , nil
110
111
}
111
112
112
- if e .Kind == event .KindReview {
113
- rv , err := s .i .FindReviewByID (ctx , e .ReviewID )
113
+ if evt .Kind == event .KindReview {
114
+ rv , err := s .i .FindReviewByID (ctx , evt .ReviewID )
114
115
if err != nil {
115
116
return false , err
116
117
}
@@ -120,7 +121,7 @@ func (s *Stream) hasPermForEvent(ctx context.Context, u *ent.User, e *ent.Event)
120
121
return false , err
121
122
}
122
123
123
- if _ , err = s .i .FindPermOfRepo (ctx , d .Edges .Repo , u ); ent . IsNotFound (err ) {
124
+ if _ , err = s .i .FindPermOfRepo (ctx , d .Edges .Repo , u ); e . HasErrorCode (err , e . ErrorCodeEntityNotFound ) {
124
125
return false , nil
125
126
} else if err != nil {
126
127
return false , err
0 commit comments