@@ -158,7 +158,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
158158 }
159159
160160 allow_access ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
161- if ( ! _package . gitlab ) { return cb ( ) ; }
161+ if ( ! _package . gitlab ) return cb ( ) ;
162162
163163 if ( ( _package . access || [ ] ) . includes ( '$authenticated' ) && user . name !== undefined ) {
164164 this . logger . debug ( `[gitlab] allow user: ${ user . name } access to package: ${ _package . name } ` ) ;
@@ -170,14 +170,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
170170 this . logger . debug ( `[gitlab] deny user: ${ user . name || '' } access to package: ${ _package . name } ` ) ;
171171 return cb ( null , false ) ;
172172 }
173- 174173 }
175174
176175 allow_publish ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
177- if ( ! _package . gitlab ) { return cb ( ) ; }
176+ if ( ! _package . gitlab ) return cb ( ) ;
178177 let packageScopePermit = false ;
179178 let packagePermit = false ;
180- 181179 // Only allow to publish packages when:
182180 // - the package has exactly the same name as one of the user groups, or
183181 // - the package scope is the same as one of the user groups
@@ -186,31 +184,20 @@ export default class VerdaccioGitLab implements IPluginAuth {
186184 if ( real_group === _package . name ) {
187185 packagePermit = true ;
188186 break ;
189- } else {
190- if ( _package . name . indexOf ( '@' ) === 0 ) {
191- if ( real_group === _package . name . slice ( 1 , _package . name . lastIndexOf ( '/' ) ) ) {
192- packageScopePermit = true ;
193- break ;
194- }
195- }
187+ } else if ( _package . name . indexOf ( '@' ) === 0 && real_group === _package . name . slice ( 1 , _package . name . lastIndexOf ( '/' ) ) ) {
188+ packageScopePermit = true ;
189+ break ;
196190 }
197191 }
198192
199- if ( packagePermit === true ) {
200- this . logger . debug ( `[gitlab] user: ${ user . name || '' } allowed to publish package: ${ _package . name } based on package-name` ) ;
193+ if ( packagePermit || packageScopePermit ) {
194+ const perm = packagePermit ? 'package-name' : 'package-scope' ;
195+ this . logger . debug ( `[gitlab] user: ${ user . name || '' } allowed to publish package: ${ _package . name } based on ${ perm } ` ) ;
201196 return cb ( null , false ) ;
202197 } else {
203- if ( packageScopePermit === true ) {
204- this . logger . debug ( `[gitlab] user: ${ user . name || '' } allowed to publish package: ${ _package . name } based on package-scope` ) ;
205- return cb ( null , false ) ;
206- } else {
207- this . logger . debug ( `[gitlab] user: ${ user . name || '' } denied from publishing package: ${ _package . name } ` ) ;
208- if ( _package . name . indexOf ( '@' ) === 0 ) {
209- return cb ( httperror [ 403 ] ( `must have required permissions: ${ this . config . publish || '' } at package-scope` ) ) ;
210- } else {
211- return cb ( httperror [ 403 ] ( `must have required permissions: ${ this . config . publish || '' } at package-name` ) ) ;
212- }
213- }
198+ this . logger . debug ( `[gitlab] user: ${ user . name || '' } denied from publishing package: ${ _package . name } ` ) ;
199+ const missingPerm = _package . name . indexOf ( '@' ) === 0 ? 'package-scope' : 'package-name' ;
200+ return cb ( httperror [ 403 ] ( `must have required permissions: ${ this . config . publish || '' } at ${ missingPerm } ` ) ) ;
214201 }
215202 }
216203
@@ -237,5 +224,4 @@ export default class VerdaccioGitLab implements IPluginAuth {
237224 }
238225 } ) ;
239226 }
240- 241227}
0 commit comments