Browse Source

tidy up

master
Martin McKeaveney 6 years ago
parent
commit
a071d7b365
  1. 31
      packages/auth/src/db/utils.js

31
packages/auth/src/db/utils.js

@ -132,29 +132,28 @@ const determineScopedConfig = async function(db, { type, user, group }) {
} }
) )
) )
const configs = response.rows.map(row => row.doc) const configs = response.rows.map(row => {
const config = row.doc
// Find the config with the most granular scope based on context
const scopedConfig = configs.find(config => {
// Config is specific to a user and a group // Config is specific to a user and a group
if (config._id.includes(generateConfigID({ type, user, group }))) { if (config._id.includes(generateConfigID({ type, user, group }))) {
return config config.score = 4
} } else if (config._id.includes(generateConfigID({ type, user }))) {
// Config is specific to a user only
// Config is specific to a user config.score = 3
if (config._id.includes(generateConfigID({ type, user }))) { } else if (config._id.includes(generateConfigID({ type, group }))) {
return config // Config is specific to a group only
} config.score = 2
} else if (config._id.includes(generateConfigID({ type }))) {
// Config is specific to a group only // Config is specific to a type only
if (config._id.includes(generateConfigID({ type, group }))) { config.score = 1
return config
} }
// Config specific to a config type only
return config return config
}) })
// Find the config with the most granular scope based on context
const scopedConfig = configs.sort((a, b) => b.score - a.score)[0]
return scopedConfig return scopedConfig
} }

Loading…
Cancel
Save