@@ -158,7 +158,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
158
158
}
159
159
160
160
allow_access ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
161
- if ( ! _package . gitlab ) { return cb ( ) ; }
161
+ if ( ! _package . gitlab ) return cb ( ) ;
162
162
163
163
if ( ( _package . access || [ ] ) . includes ( '$authenticated' ) && user . name !== undefined ) {
164
164
this . logger . debug ( `[gitlab] allow user: ${ user . name } access to package: ${ _package . name } ` ) ;
@@ -170,14 +170,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
170
170
this . logger . debug ( `[gitlab] deny user: ${ user . name || '' } access to package: ${ _package . name } ` ) ;
171
171
return cb ( null , false ) ;
172
172
}
173
-
174
173
}
175
174
176
175
allow_publish ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
177
- if ( ! _package . gitlab ) { return cb ( ) ; }
176
+ if ( ! _package . gitlab ) return cb ( ) ;
178
177
let packageScopePermit = false ;
179
178
let packagePermit = false ;
180
-
181
179
// Only allow to publish packages when:
182
180
// - the package has exactly the same name as one of the user groups, or
183
181
// - the package scope is the same as one of the user groups
@@ -186,31 +184,20 @@ export default class VerdaccioGitLab implements IPluginAuth {
186
184
if ( real_group === _package . name ) {
187
185
packagePermit = true ;
188
186
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 ;
196
190
}
197
191
}
198
192
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 } ` ) ;
201
196
return cb ( null , false ) ;
202
197
} 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 } ` ) ) ;
214
201
}
215
202
}
216
203
@@ -237,5 +224,4 @@ export default class VerdaccioGitLab implements IPluginAuth {
237
224
}
238
225
} ) ;
239
226
}
240
-
241
227
}
0 commit comments