mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #13933 from overleaf/bg-managed-users-add-missing-jsdoc-param
refactor getUserValidationStatus in PermissionsManager GitOrigin-RevId: 80ef8142d3556e47e1d6cb323148f1f1042057aa
This commit is contained in:
parent
558992d947
commit
d2f470450e
4 changed files with 22 additions and 25 deletions
|
@ -282,17 +282,19 @@ function hasPermission(groupPolicy, capability) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously checks which policies a user complies with using the
|
* Asynchronously checks which policies a user complies with using the
|
||||||
* applicable validators. Each validator is an async function that takes a object
|
* applicable validators. Each validator is an async function that takes an object
|
||||||
* with user and subscription properties and returns a boolean.
|
* with user, groupPolicy, and subscription properties and returns a boolean.
|
||||||
*
|
*
|
||||||
* @param {Object} user - The user object to check.
|
* @param {Object} options - The options object.
|
||||||
* @param {Object} groupPolicy - The group policy object to check.
|
* @param {Object} options.user - The user object to check.
|
||||||
|
* @param {Object} options.groupPolicy - The group policy object to check.
|
||||||
|
* @param {Object} options.subscription - The subscription object for the group policy.
|
||||||
* @returns {Promise<Map>} A promise that resolves with a Map object containing
|
* @returns {Promise<Map>} A promise that resolves with a Map object containing
|
||||||
* the validation status for each enforced policy. The keys of the Map are the
|
* the validation status for each enforced policy. The keys of the Map are the
|
||||||
* enforced policy names, and the values are booleans indicating whether the
|
* enforced policy names, and the values are booleans indicating whether the
|
||||||
* user complies with the policy.
|
* user complies with the policy.
|
||||||
*/
|
*/
|
||||||
async function getUserValidationStatus(user, groupPolicy, subscription) {
|
async function getUserValidationStatus({ user, groupPolicy, subscription }) {
|
||||||
// find all the enforced policies for the user
|
// find all the enforced policies for the user
|
||||||
const enforcedPolicyNames = getEnforcedPolicyNames(groupPolicy)
|
const enforcedPolicyNames = getEnforcedPolicyNames(groupPolicy)
|
||||||
// for each enforced policy, we have a list of capabilities with expected values
|
// for each enforced policy, we have a list of capabilities with expected values
|
||||||
|
|
|
@ -93,11 +93,11 @@ async function viewInvite(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
validationStatus =
|
validationStatus =
|
||||||
await PermissionsManager.promises.getUserValidationStatus(
|
await PermissionsManager.promises.getUserValidationStatus({
|
||||||
user,
|
user,
|
||||||
subscription.groupPolicy,
|
groupPolicy: subscription.groupPolicy,
|
||||||
subscription
|
subscription,
|
||||||
)
|
})
|
||||||
|
|
||||||
return res.render('subscriptions/team/invite-managed', {
|
return res.render('subscriptions/team/invite-managed', {
|
||||||
inviterName: invite.inviterName,
|
inviterName: invite.inviterName,
|
||||||
|
|
|
@ -74,13 +74,8 @@ class Subscription {
|
||||||
return PermissionsManager.getUserCapabilities(groupPolicy)
|
return PermissionsManager.getUserCapabilities(groupPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserValidationStatus(user, groupPolicy, subscription, callback) {
|
getUserValidationStatus(params, callback) {
|
||||||
PermissionsManager.getUserValidationStatus(
|
PermissionsManager.getUserValidationStatus(params, callback)
|
||||||
user,
|
|
||||||
groupPolicy,
|
|
||||||
subscription,
|
|
||||||
callback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enrollManagedUser(user, callback) {
|
enrollManagedUser(user, callback) {
|
||||||
|
|
|
@ -288,11 +288,11 @@ describe('PermissionsManager', function () {
|
||||||
const user = { prop: 'allowed' }
|
const user = { prop: 'allowed' }
|
||||||
const subscription = { prop: 'managed' }
|
const subscription = { prop: 'managed' }
|
||||||
const result =
|
const result =
|
||||||
await this.PermissionsManager.promises.getUserValidationStatus(
|
await this.PermissionsManager.promises.getUserValidationStatus({
|
||||||
user,
|
user,
|
||||||
groupPolicy,
|
groupPolicy,
|
||||||
subscription
|
subscription,
|
||||||
)
|
})
|
||||||
expect(result).to.deep.equal(new Map([['policy', true]]))
|
expect(result).to.deep.equal(new Map([['policy', true]]))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -312,11 +312,11 @@ describe('PermissionsManager', function () {
|
||||||
const user = { prop: 'not allowed' }
|
const user = { prop: 'not allowed' }
|
||||||
const subscription = { prop: 'managed' }
|
const subscription = { prop: 'managed' }
|
||||||
const result =
|
const result =
|
||||||
await this.PermissionsManager.promises.getUserValidationStatus(
|
await this.PermissionsManager.promises.getUserValidationStatus({
|
||||||
user,
|
user,
|
||||||
groupPolicy,
|
groupPolicy,
|
||||||
subscription
|
subscription,
|
||||||
)
|
})
|
||||||
expect(result).to.deep.equal(new Map([['policy', false]]))
|
expect(result).to.deep.equal(new Map([['policy', false]]))
|
||||||
})
|
})
|
||||||
it('should return the status for multiple policies according to whether the user conforms', async function () {
|
it('should return the status for multiple policies according to whether the user conforms', async function () {
|
||||||
|
@ -356,11 +356,11 @@ describe('PermissionsManager', function () {
|
||||||
const user = { prop: 'allowed' }
|
const user = { prop: 'allowed' }
|
||||||
const subscription = { prop: 'managed' }
|
const subscription = { prop: 'managed' }
|
||||||
const result =
|
const result =
|
||||||
await this.PermissionsManager.promises.getUserValidationStatus(
|
await this.PermissionsManager.promises.getUserValidationStatus({
|
||||||
user,
|
user,
|
||||||
groupPolicy,
|
groupPolicy,
|
||||||
subscription
|
subscription,
|
||||||
)
|
})
|
||||||
expect(result).to.deep.equal(
|
expect(result).to.deep.equal(
|
||||||
new Map([
|
new Map([
|
||||||
['policy1', true],
|
['policy1', true],
|
||||||
|
|
Loading…
Reference in a new issue