@@ -33,30 +33,31 @@ func (rm *RepoMiddleware) RepoReadPerm() gin.HandlerFunc {
33
33
ctx := c .Request .Context ()
34
34
35
35
var (
36
- id = c .Param ("id" )
36
+ namespace = c .Param ("namespace" )
37
+ name = c .Param ("name" )
37
38
)
38
39
39
40
v , _ := c .Get (gb .KeyUser )
40
41
u := v .(* ent.User )
41
42
42
- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
43
+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
43
44
if ent .IsNotFound (err ) {
44
- rm .log .Warn ("The repository is not found." , zap .String ("repo_id " , id ), zap .Error (err ))
45
+ rm .log .Warn ("The repository is not found." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
45
46
gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
46
47
return
47
48
} else if err != nil {
48
- rm .log .Error ("It has failed to get the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
49
+ rm .log .Error ("It has failed to get the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
49
50
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
50
51
return
51
52
}
52
53
53
54
_ , err = rm .i .FindPermOfRepo (ctx , r , u )
54
55
if ent .IsNotFound (err ) {
55
- rm .log .Warn ("It is denied to access the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
56
+ rm .log .Warn ("It is denied to access the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
56
57
gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repository." )
57
58
return
58
59
} else if err != nil {
59
- rm .log .Error ("It has failed to get the permission." , zap .String ("repoID " , id ), zap .Error (err ))
60
+ rm .log .Error ("It has failed to get the permission." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
60
61
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
61
62
return
62
63
}
@@ -70,36 +71,37 @@ func (rm *RepoMiddleware) RepoWritePerm() gin.HandlerFunc {
70
71
ctx := c .Request .Context ()
71
72
72
73
var (
73
- id = c .Param ("id" )
74
+ namespace = c .Param ("namespace" )
75
+ name = c .Param ("name" )
74
76
)
75
77
76
78
v , _ := c .Get (gb .KeyUser )
77
79
u := v .(* ent.User )
78
80
79
- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
81
+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
80
82
if ent .IsNotFound (err ) {
81
- rm .log .Warn ("The repository is not found." , zap .String ("repo_id " , id ), zap .Error (err ))
83
+ rm .log .Warn ("The repository is not found." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
82
84
gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
83
85
return
84
86
} else if err != nil {
85
- rm .log .Error ("It has failed to get the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
87
+ rm .log .Error ("It has failed to get the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
86
88
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
87
89
return
88
90
}
89
91
90
92
p , err := rm .i .FindPermOfRepo (ctx , r , u )
91
93
if ent .IsNotFound (err ) {
92
- rm .log .Warn ("It is denied to access the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
94
+ rm .log .Warn ("It is denied to access the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
93
95
gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repository." )
94
96
return
95
97
} else if err != nil {
96
- rm .log .Error ("It has failed to get the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
98
+ rm .log .Error ("It has failed to get the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
97
99
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
98
100
return
99
101
}
100
102
101
103
if ! (p .RepoPerm == perm .RepoPermWrite || p .RepoPerm == perm .RepoPermAdmin ) {
102
- rm .log .Warn ("The access is forbidden. Only write permission can access." , zap .String ("repo_id " , id ))
104
+ rm .log .Warn ("The access is forbidden. Only write permission can access." , zap .String ("repo " , namespace + "/" + name ))
103
105
gb .AbortWithErrorResponse (c , http .StatusForbidden , "Only write permission can access." )
104
106
return
105
107
}
@@ -113,36 +115,37 @@ func (rm *RepoMiddleware) RepoAdminPerm() gin.HandlerFunc {
113
115
ctx := c .Request .Context ()
114
116
115
117
var (
116
- id = c .Param ("id" )
118
+ namespace = c .Param ("namespace" )
119
+ name = c .Param ("name" )
117
120
)
118
121
119
122
v , _ := c .Get (gb .KeyUser )
120
123
u := v .(* ent.User )
121
124
122
- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
125
+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
123
126
if ent .IsNotFound (err ) {
124
- rm .log .Warn ("The repository is not found." , zap .String ("repo_id " , id ), zap .Error (err ))
127
+ rm .log .Warn ("The repository is not found." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
125
128
gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
126
129
return
127
130
} else if err != nil {
128
- rm .log .Error ("It has failed to get the repository." , zap .String ("repo_id " , id ), zap .Error (err ))
131
+ rm .log .Error ("It has failed to get the repository." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
129
132
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
130
133
return
131
134
}
132
135
133
136
p , err := rm .i .FindPermOfRepo (ctx , r , u )
134
137
if ent .IsNotFound (err ) {
135
- rm .log .Warn ("It is denied to access the repo." , zap .String ("repo_id " , id ), zap .Error (err ))
138
+ rm .log .Warn ("It is denied to access the repo." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
136
139
gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repo." )
137
140
return
138
141
} else if err != nil {
139
- rm .log .Error ("It has failed to get the permission." , zap .String ("repo_id " , id ), zap .Error (err ))
142
+ rm .log .Error ("It has failed to get the permission." , zap .String ("repo " , namespace + "/" + name ), zap .Error (err ))
140
143
gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
141
144
return
142
145
}
143
146
144
147
if p .RepoPerm != perm .RepoPermAdmin {
145
- rm .log .Warn ("The access is forbidden. Only admin permission can access." , zap .String ("repo_id " , id ))
148
+ rm .log .Warn ("The access is forbidden. Only admin permission can access." , zap .String ("repo " , namespace + "/" + name ))
146
149
gb .AbortWithErrorResponse (c , http .StatusForbidden , "Only admin permission can access." )
147
150
return
148
151
}
0 commit comments