mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
refactor: add types on auth files
This commit is contained in:
parent
66118ad008
commit
9ade39a264
2 changed files with 14 additions and 10 deletions
|
@ -1,8 +1,12 @@
|
|||
// @flow
|
||||
|
||||
import {ErrorCode} from './utils';
|
||||
import {API_ERROR} from './constants';
|
||||
|
||||
export function allow_action(action) {
|
||||
return function(user, pkg, callback) {
|
||||
import type {RemoteUser, Package, Callback} from '@verdaccio/types';
|
||||
|
||||
export function allow_action(action: string) {
|
||||
return function(user: RemoteUser, pkg: Package, callback: Callback) {
|
||||
const {name, groups} = user;
|
||||
const hasPermission = pkg[action].some((group) => name === group || groups.includes(group));
|
||||
|
||||
|
@ -20,11 +24,11 @@ export function allow_action(action) {
|
|||
|
||||
export function getDefaultPlugins() {
|
||||
return {
|
||||
authenticate(user, password, cb) {
|
||||
authenticate(user: string, password: string, cb: Callback) {
|
||||
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||
},
|
||||
|
||||
add_user(user, password, cb) {
|
||||
add_user(user: string, password: string, cb: Callback) {
|
||||
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||
},
|
||||
|
||||
|
|
|
@ -126,11 +126,11 @@ class Auth implements IAuth {
|
|||
(function next() {
|
||||
const plugin = plugins.shift();
|
||||
|
||||
if (typeof(plugin.allow_access) !== 'function') {
|
||||
if (_.isFunction(plugin.allow_access) === false) {
|
||||
return next();
|
||||
}
|
||||
|
||||
plugin.allow_access(user, pkg, function(err, ok) {
|
||||
plugin.allow_access(user, pkg, function(err, ok: boolean) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -155,11 +155,11 @@ class Auth implements IAuth {
|
|||
(function next() {
|
||||
const plugin = plugins.shift();
|
||||
|
||||
if (typeof(plugin.allow_publish) !== 'function') {
|
||||
if (_.isFunction(plugin.allow_publish) === false) {
|
||||
return next();
|
||||
}
|
||||
|
||||
plugin.allow_publish(user, pkg, (err, ok) => {
|
||||
plugin.allow_publish(user, pkg, (err, ok: boolean) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -188,7 +188,8 @@ class Auth implements IAuth {
|
|||
return _next();
|
||||
};
|
||||
|
||||
if (req.remote_user != null && req.remote_user.name !== undefined) {
|
||||
if (_.isUndefined(req.remote_user) === false
|
||||
&& _.isUndefined(req.remote_user.name) === false) {
|
||||
return next();
|
||||
}
|
||||
req.remote_user = buildAnonymousUser();
|
||||
|
@ -204,7 +205,6 @@ class Auth implements IAuth {
|
|||
}
|
||||
|
||||
const credentials = this._parseCredentials(parts);
|
||||
|
||||
if (!credentials) {
|
||||
return next();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue