@@ -33,30 +33,31 @@ func (rm *RepoMiddleware) RepoReadPerm() gin.HandlerFunc {
3333 ctx := c .Request .Context ()
3434
3535 var (
36- id = c .Param ("id" )
36+ namespace = c .Param ("namespace" )
37+ name = c .Param ("name" )
3738 )
3839
3940 v , _ := c .Get (gb .KeyUser )
4041 u := v .(* ent.User )
4142
42- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
43+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
4344 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 ))
4546 gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
4647 return
4748 } 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 ))
4950 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
5051 return
5152 }
5253
5354 _ , err = rm .i .FindPermOfRepo (ctx , r , u )
5455 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 ))
5657 gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repository." )
5758 return
5859 } 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 ))
6061 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
6162 return
6263 }
@@ -70,36 +71,37 @@ func (rm *RepoMiddleware) RepoWritePerm() gin.HandlerFunc {
7071 ctx := c .Request .Context ()
7172
7273 var (
73- id = c .Param ("id" )
74+ namespace = c .Param ("namespace" )
75+ name = c .Param ("name" )
7476 )
7577
7678 v , _ := c .Get (gb .KeyUser )
7779 u := v .(* ent.User )
7880
79- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
81+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
8082 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 ))
8284 gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
8385 return
8486 } 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 ))
8688 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
8789 return
8890 }
8991
9092 p , err := rm .i .FindPermOfRepo (ctx , r , u )
9193 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 ))
9395 gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repository." )
9496 return
9597 } 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 ))
9799 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
98100 return
99101 }
100102
101103 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 ))
103105 gb .AbortWithErrorResponse (c , http .StatusForbidden , "Only write permission can access." )
104106 return
105107 }
@@ -113,36 +115,37 @@ func (rm *RepoMiddleware) RepoAdminPerm() gin.HandlerFunc {
113115 ctx := c .Request .Context ()
114116
115117 var (
116- id = c .Param ("id" )
118+ namespace = c .Param ("namespace" )
119+ name = c .Param ("name" )
117120 )
118121
119122 v , _ := c .Get (gb .KeyUser )
120123 u := v .(* ent.User )
121124
122- r , err := rm .i .FindRepoOfUserByID (ctx , u , id )
125+ r , err := rm .i .FindRepoOfUserByNamespaceName (ctx , u , namespace , name )
123126 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 ))
125128 gb .AbortWithErrorResponse (c , http .StatusNotFound , "The repository is not found." )
126129 return
127130 } 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 ))
129132 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the repository." )
130133 return
131134 }
132135
133136 p , err := rm .i .FindPermOfRepo (ctx , r , u )
134137 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 ))
136139 gb .AbortWithErrorResponse (c , http .StatusForbidden , "It is denied to access the repo." )
137140 return
138141 } 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 ))
140143 gb .AbortWithErrorResponse (c , http .StatusInternalServerError , "It has failed to get the permission." )
141144 return
142145 }
143146
144147 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 ))
146149 gb .AbortWithErrorResponse (c , http .StatusForbidden , "Only admin permission can access." )
147150 return
148151 }
0 commit comments