-
checkAdmin(req, res, next)
-
Checks if user is authenticated, by searching req.session.user
If auth pass next, else throw error
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request object |
res |
object
|
Express Repost object |
next |
function
|
callback |
-
checkCredentials(rule, auth, role, admin)
-
Check rule against presented credentials
Parameters:
Name |
Type |
Description |
rule |
object
|
action rule
{
auth - if user should be authenticated
role - if user shoud have some role
admin - if user should be super user
} |
auth |
Boolean
|
user state of auth |
role |
String
|
Array
|
user state of role |
admin |
Boolean
|
user state of admin |
Returns:
pass or not
-
Type
-
boolean
-
checkRoleBuilder(role)
-
Returns Express middleware witch check role against one presented in request
Parameters:
Name |
Type |
Description |
role |
string
|
array
|
action roles |
Returns:
express middleware
-
Type
-
function
-
checkSupremacy(base, against, roles)
-
Check to sets of roles against each other
to define if base is strictly higher than second
Parameters:
Name |
Type |
Description |
base |
String
|
Array
|
first set of roles |
against |
String
|
Array
|
second set of roles |
roles |
Array
|
roles in order of supremacy from highest to lowest |
Returns:
true if base > against
-
Type
-
boolean
-
checkUser(req, res, next)
-
Checks if user is authenticated, by searching req.session.user
If auth pass next, else throw error
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request object |
res |
object
|
Express Repost object |
next |
function
|
callback |
-
cleanse(req)
-
Reset session
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
-
compareRoles(userRoles, actionRoles, strict)
-
Compares two list of roles
Parameters:
Name |
Type |
Default |
Description |
userRoles |
array
|
string
|
|
roles of user |
actionRoles |
array
|
string
|
|
roles of action |
strict |
boolean
|
true
|
if true userRoles should contain all of actionRoles. else atleast one |
Returns:
if user roles comply to action roles
-
Type
-
boolean
-
createSpecial(owner, system)
-
Creates array of special roles
Parameters:
Name |
Type |
Description |
owner |
boolean
|
if actor is owner of document |
system |
boolean
|
if actor is a system process |
Returns:
list of special roles
-
Type
-
Array.<string>
-
-
Collects various authentification and authorization data from request object
Returns:
various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
-
Type
-
object
-
-
Using schema and information about action and actor to extract only safe information
forming new object with data only from safe fields
Parameters:
Name |
Type |
Default |
Description |
schema |
Object
|
|
mongoose model schema with extended fields from not-* |
action |
string
|
|
action to check against |
data |
Object
|
|
source of data to extract from |
roles |
Array.<string>
|
|
actor roles |
actorId |
string
|
ObjectId
|
|
actor objectId |
system |
boolean
|
false
|
true if actor is a system procedure |
Returns:
object containing only data from safe fields
-
Type
-
Object
-
fieldIsSafe(field, action, roles, special)
-
Check if field of target object is safe to access by actor with defined
roles in specific action
Parameters:
Name |
Type |
Description |
field |
Object
|
description of field from schema |
action |
string
|
action to check against |
roles |
Array.<string>
|
actor roles |
special |
string
|
special relations of actor and target (@owner, @system) |
Returns:
true - safe
-
Type
-
boolean
-
fromSchema(schema, rawMutationsList)
-
Takes in mongoose model schema, scans for fields names nad creates list of
field's names to initialize from LIB, if in supplied rawMutationsList, exists
mutation for a field in list, field name in list will be replaced by a
mutation description
Parameters:
Name |
Type |
Description |
schema |
Object
|
mongoose model schema |
rawMutationsList |
Array
|
list of mutations [src, mutation]/[dst,mutation,src] |
Returns:
initialized ui descriptions of fields for schema
-
Type
-
Object
-
getIP(req)
-
Get request ip
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
-
getMutationForField(name, list)
-
Returns mutation tuple for a field or false
Parameters:
Name |
Type |
Description |
name |
string
|
field name |
list |
Array
|
fields description lists |
Returns:
-
Type
-
boolean
|
item
-
getOwnerId(data)
-
Get data owner ObjectId
Parameters:
Name |
Type |
Description |
data |
Object
|
Document Object |
Returns:
owner ObjectId or undefined if field is not found
-
Type
-
ObjectId
|
undefined
-
getRole(req)
-
Returns user role from request object
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
Returns:
user role
-
getSafeFieldsForRoleAction(schema, action, roles, owner, system)
-
Scans schema checks every field access regulations for specific action of
actor with roles. Returns list of fields that could be accessed safely.
Parameters:
Name |
Type |
Description |
schema |
Object
|
mongoose model schema with extended fields from not-* |
action |
string
|
action to check against |
roles |
Array.<string>
|
actor roles |
owner |
boolean
|
actor is an owner of document |
system |
boolean
|
actor is a system procedure |
Returns:
list of accessible fields
-
Type
-
Array.<string>
-
getSessionId(req)
-
Get session id for active session
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
-
getUserId(req)
-
Get user id for active session
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
-
ifAdmin(req)
-
Returns true if user is admin
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request object |
Returns:
true - admin, false - not admin
-
Type
-
boolean
-
initField(field, resultOnly, type)
-
Retrieves field information
there are few signatures of this function
(field:string, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
(field:Array, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
Parameters:
Name |
Type |
Description |
field |
string
|
Array
|
field to retrieve from store and init
field: string - just name of the field
field: Array - [destinationField:string, mutation: Object, sourceField:string]
field: Array - [sourceField:string, mutation: Object]
sourceField - standart field to extend
mutation - to extend by
destinationField - name of resulting field,
if no dest then src will be used |
resultOnly |
boolean
|
return only result, if false then returns [name, value] |
type |
string
|
type of field information |
-
initFields()
-
list = [
'title', //for standart only name
['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
['someID', {}, 'ID'], //copy of standart ID field under name as someID
]
-
intersect_safe(a, b)
-
Two arrays in - one intersection of two out
Parameters:
Name |
Type |
Description |
a |
array
|
first array |
b |
array
|
scecond array |
Returns:
array consisted of elements presented in both input arrays
-
Type
-
array
-
isOwner(data, user_id)
-
Check if data is belongs to user
Parameters:
Name |
Type |
Description |
data |
Object
|
object |
user_id |
ObjectId
|
possible owner |
Returns:
true - belongs, false - not belongs
-
Type
-
boolean
-
isUser(req)
-
Checks if user is authenticated, by searching req.session.user
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request object |
Returns:
true - authenticated, false - guest
-
Type
-
boolean
-
module:Model/Validator()
-
Take array of validator (https://www.npmjs.com/package/validator) rules
and create array of mongoose-validator (https://www.npmjs.com/package/mongoose-validator) rules
then return it
-
ruleIsWildcard(safeFor)
-
Checks if safe field rule is some sort variant of wild card
Parameters:
Name |
Type |
Description |
safeFor |
string
|
Array.<string>
|
safe field rule |
Returns:
if it's wildcard
-
Type
-
boolean
-
setAuth(req, id, role)
-
Set auth data in session, user id and role
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
id |
string
|
user id |
role |
string
|
user role |
-
setGuest(req)
-
Set auth data in session to Guest
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
-
setRole(req, role)
-
Set user role for active session
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
role |
Array.<string>
|
array of roles |
-
setUserId(req, _id)
-
Set user id for active session
Parameters:
Name |
Type |
Description |
req |
object
|
Express Request |
_id |
string
|
user id |