Skip to content

Commit

Permalink
feat(minor): removed calculateRemitForUser method. Not used.
Browse files Browse the repository at this point in the history
affects: tymly
  • Loading branch information
jezhiggins committed May 22, 2018
1 parent 13a4ba1 commit 7d49f6e
Showing 1 changed file with 0 additions and 89 deletions.
89 changes: 0 additions & 89 deletions lib/plugin/components/services/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,95 +186,6 @@ class UsersService {
}
)
}

static userCreatableFlow (stateMachine) {
return _.isArray(stateMachine.definition.instigators) && stateMachine.definition.instigators.indexOf('user') !== -1
}

/**
* Returns a list of state-machines a user has the correct credentials to start, along with any form-definitions they can interact with. Useful for client apps wanting to configure themselves around an individual.
* @param {string} userId Specifies which useId to return a remit-object for
* @param {Function} callback Called with a 'remit' object
* @returns {undefined}
* @example
* users.calculateRemitForUser(
* 'Dave',
* function (err, remit) {
* // remit is an object:
* // stateMachinesUserCanStart: []
* // forms: {}
* }
* )
*/
calculateRemitForUser (userId, callback) {
const _this = this

const remit = {
stateMachinesUserCanStart: [],
forms: {}
}

this.getUserRoles(
userId,
function (err, roles) {
if (err) {
callback(err)
} else {
const formFillingStates = _this.statebox.findStates(
{
resourceToFind: 'module:formFilling'
}
)

let firstError

formFillingStates.forEach(
function (state) {
const stateMachineName = state.stateMachine.name
if (
UsersService.userCreatableFlow(state.stateMachine) &&
_this.rbac.checkRoleAuthorization(
userId,
{}, // Context {userId: userId},
roles,
'stateMachine',
stateMachineName,
'create'
)) {
remit.stateMachinesUserCanStart.push(
{
stateMachineName: stateMachineName,
label: stateMachineName,
description: state.stateMachine.definition.Comment || 'No comment?'
}
)

const formId = state.definition.ResourceConfig.formId
const form = _this.forms[formId]

if (form) {
remit.forms[formId] = {
label: form.label,
form: form.form,
schema: form.schema
}
} else {
if (!firstError) {
firstError = new Error(`State machine '${stateMachineName}' refers to an unknown formId '${formId}'`)
}
}
}
}
)
if (firstError) {
callback(firstError)
} else {
callback(null, remit)
}
}
}
)
}
}

module.exports = {
Expand Down

0 comments on commit 7d49f6e

Please sign in to comment.