Merge pull request #23006 from overleaf/msm-chat-capabilities-poc-2

[web] Add option to disable chat for subscription

GitOrigin-RevId: 0052d060c74c39400496f7f9f54c820398d60012
This commit is contained in:
Miguel Serrano
2025-01-31 09:05:18 +00:00
committed by Copybot
parent ba60f885a4
commit 8ff8e7a4bf
14 changed files with 138 additions and 5 deletions
@@ -64,6 +64,48 @@ describe('PermissionsManager', function () {
]
})
describe('validatePolicies', function () {
it('accepts empty object', function () {
expect(() => this.PermissionsManager.validatePolicies({})).not.to.throw
})
it('accepts object with registered policies', function () {
expect(() =>
this.PermissionsManager.validatePolicies({
openPolicy: true,
restrictivePolicy: false,
})
).not.to.throw
})
it('accepts object with policies containing non-boolean values', function () {
expect(() =>
this.PermissionsManager.validatePolicies({
openPolicy: 1,
})
).to.throw('policy value must be a boolean: openPolicy = 1')
expect(() =>
this.PermissionsManager.validatePolicies({
openPolicy: undefined,
})
).to.throw('policy value must be a boolean: openPolicy = undefined')
expect(() =>
this.PermissionsManager.validatePolicies({
openPolicy: null,
})
).to.throw('policy value must be a boolean: openPolicy = null')
})
it('throws error on object with policies that are not registered', function () {
expect(() =>
this.PermissionsManager.validatePolicies({
openPolicy: true,
unregisteredPolicy: false,
})
).to.throw('unknown policy: unregisteredPolicy')
})
})
describe('hasPermission', function () {
describe('when no policies apply to the user', function () {
it('should return true if default permission is true', function () {
@@ -1132,6 +1132,40 @@ describe('ProjectController', function () {
})
})
})
describe('chatEnabled flag', function () {
it('should be set to false when the feature is disabled', function (done) {
this.Features.hasFeature = sinon.stub().withArgs('chat').returns(false)
this.res.render = (pageName, opts) => {
expect(opts.chatEnabled).to.be.false
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
it('should be set to false when the feature is enabled but the capability is not available', function (done) {
this.Features.hasFeature = sinon.stub().withArgs('chat').returns(false)
this.req.capabilitySet = new Set()
this.res.render = (pageName, opts) => {
expect(opts.chatEnabled).to.be.false
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
it('should be set to true when the feature is enabled and the capability is available', function (done) {
this.Features.hasFeature = sinon.stub().withArgs('chat').returns(true)
this.req.capabilitySet = new Set(['chat'])
this.res.render = (pageName, opts) => {
expect(opts.chatEnabled).to.be.true
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
})
})
describe('userProjectsJson', function () {