Merge pull request #2891 from overleaf/jel-remove-unused-feature-flags

Remove unused redirect-sl feature flag and sharelatex-redirects module

GitOrigin-RevId: a13ae586db3b7ab4440f2e941947be3a28d97741
This commit is contained in:
Jessica Lawshe 2020-06-11 10:24:11 -05:00 committed by Copybot
parent f024483aa0
commit 7d98a82208
2 changed files with 179 additions and 28 deletions

View file

@ -1,15 +1,4 @@
/* eslint-disable
max-len,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let Features
const _ = require('lodash')
const Settings = require('settings-sharelatex')
const fs = require('fs')
@ -25,12 +14,12 @@ const trackChangesModuleAvailable = fs.existsSync(
`${__dirname}/../../../modules/track-changes`
)
module.exports = Features = {
const Features = {
externalAuthenticationSystemUsed() {
return (
Settings.ldap != null ||
Settings.saml != null ||
(Settings.overleaf != null ? Settings.overleaf.oauth : undefined) != null
!!Settings.ldap ||
!!Settings.saml ||
!!_.get(Settings, ['overleaf', 'oauth'])
)
},
@ -39,18 +28,15 @@ module.exports = Features = {
case 'homepage':
return Settings.enableHomepage
case 'registration':
return (
!Features.externalAuthenticationSystemUsed() ||
Settings.overleaf != null
)
return !Features.externalAuthenticationSystemUsed() || Settings.overleaf
case 'github-sync':
return Settings.enableGithubSync
case 'git-bridge':
return Settings.enableGitBridge
case 'custom-togglers':
return Settings.overleaf != null
return !!Settings.overleaf
case 'oauth':
return Settings.oauth != null
return !!Settings.oauth
case 'templates-server-pro':
return Settings.overleaf == null
case 'affiliations':
@ -58,17 +44,15 @@ module.exports = Features = {
// Checking both properties is needed for the time being to allow
// enabling the feature in web-api and disabling in Server Pro
// see https://github.com/overleaf/web-internal/pull/2127
return Settings.apis.v1 && !!Settings.apis.v1.url
case 'redirect-sl':
return Settings.redirectToV2 != null
return Settings.apis && Settings.apis.v1 && !!Settings.apis.v1.url
case 'overleaf-integration':
return Settings.overleaf != null
return !!Settings.overleaf
case 'references':
return Settings.apis.references.url != null
return !!_.get(Settings, ['apis', 'references', 'url'])
case 'saml':
return Settings.enableSaml
case 'link-url':
return Settings.apis.linkedUrlProxy && Settings.apis.linkedUrlProxy.url
return _.get(Settings, ['apis', 'linkedUrlProxy', 'url'])
case 'public-registration':
return publicRegistrationModuleAvailable
case 'support':
@ -80,3 +64,5 @@ module.exports = Features = {
}
}
}
module.exports = Features

View file

@ -0,0 +1,165 @@
const chai = require('chai')
const { expect } = chai
const modulePath = '../../../../app/src/infrastructure/Features.js'
const SandboxedModule = require('sandboxed-module')
describe('Features', function() {
beforeEach(function() {
this.Features = SandboxedModule.require(modulePath, {
globals: {
console: console
},
requires: {
'settings-sharelatex': (this.settings = {})
}
})
})
describe('externalAuthenticationSystemUsed', function() {
describe('without any settings', function() {
it('should return false', function() {
expect(this.Features.externalAuthenticationSystemUsed()).to.be.false
})
})
describe('with ldap setting', function() {
beforeEach(function() {
this.settings.ldap = true
})
it('should return true', function() {
expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
})
})
describe('with saml setting', function() {
beforeEach(function() {
this.settings.saml = true
})
it('should return true', function() {
expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
})
})
describe('with oauth setting', function() {
beforeEach(function() {
this.settings.overleaf = { oauth: true }
})
it('should return true', function() {
expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
})
})
})
describe('hasFeature', function() {
describe('without any settings', function() {
it('should return true', function() {
expect(this.Features.hasFeature('registration')).to.be.true
expect(this.Features.hasFeature('templates-server-pro')).to.be.true
})
it('should return false', function() {
expect(this.Features.hasFeature('custom-togglers')).to.be.false
expect(this.Features.hasFeature('oauth')).to.be.false
expect(this.Features.hasFeature('overleaf-integration')).to.be.false
expect(this.Features.hasFeature('references')).to.be.false
})
it('should return undefined', function() {
expect(this.Features.hasFeature('affiliations')).to.be.undefined
expect(this.Features.hasFeature('analytics')).to.be.undefined
expect(this.Features.hasFeature('github-sync')).to.be.undefined
expect(this.Features.hasFeature('git-bridge')).to.be.undefined
expect(this.Features.hasFeature('homepage')).to.be.undefined
expect(this.Features.hasFeature('link-url')).to.be.undefined
expect(this.Features.hasFeature('saml')).to.be.undefined
})
})
describe('with settings', function() {
describe('empty overleaf object', function() {
beforeEach(function() {
this.settings.overleaf = {}
this.settings.apis = {}
})
it('should return true', function() {
expect(this.Features.hasFeature('custom-togglers')).to.be.true
expect(this.Features.hasFeature('overleaf-integration')).to.be.true
expect(this.Features.hasFeature('registration')).to.be.true
})
it('should return false', function() {
expect(this.Features.hasFeature('oauth')).to.be.false
expect(this.Features.hasFeature('references')).to.be.false
expect(this.Features.hasFeature('templates-server-pro')).to.be.false
})
it('should return undefined', function() {
expect(this.Features.hasFeature('affiliations')).to.be.undefined
expect(this.Features.hasFeature('analytics')).to.be.undefined
expect(this.Features.hasFeature('github-sync')).to.be.undefined
expect(this.Features.hasFeature('git-bridge')).to.be.undefined
expect(this.Features.hasFeature('homepage')).to.be.undefined
expect(this.Features.hasFeature('link-url')).to.be.undefined
expect(this.Features.hasFeature('saml')).to.be.undefined
})
describe('with APIs', function() {
beforeEach(function() {
this.settings.apis = {
linkedUrlProxy: {
url: 'https://www.overleaf.com'
},
references: {
url: 'https://www.overleaf.com'
},
v1: {
url: 'https://www.overleaf.com'
}
}
})
it('should return true', function() {
expect(this.Features.hasFeature('affiliations')).to.be.true
expect(this.Features.hasFeature('analytics')).to.be.true
expect(this.Features.hasFeature('custom-togglers')).to.be.true
expect(this.Features.hasFeature('link-url')).to.equal(
'https://www.overleaf.com'
)
expect(this.Features.hasFeature('overleaf-integration')).to.be.true
expect(this.Features.hasFeature('references')).to.be.true
expect(this.Features.hasFeature('registration')).to.be.true
})
it('should return false', function() {
expect(this.Features.hasFeature('oauth')).to.be.false
expect(this.Features.hasFeature('templates-server-pro')).to.be.false
})
it('should return undefined', function() {
expect(this.Features.hasFeature('github-sync')).to.be.undefined
expect(this.Features.hasFeature('git-bridge')).to.be.undefined
expect(this.Features.hasFeature('homepage')).to.be.undefined
expect(this.Features.hasFeature('saml')).to.be.undefined
})
describe('with all other settings flags', function() {
beforeEach(function() {
this.settings.enableHomepage = true
this.settings.enableGitBridge = true
this.settings.enableGithubSync = true
this.settings.enableSaml = true
this.settings.oauth = true
})
it('should return true or return value', function() {
expect(this.Features.hasFeature('affiliations')).to.be.true
expect(this.Features.hasFeature('analytics')).to.be.true
expect(this.Features.hasFeature('custom-togglers')).to.be.true
expect(this.Features.hasFeature('github-sync')).to.be.true
expect(this.Features.hasFeature('git-bridge')).to.be.true
expect(this.Features.hasFeature('homepage')).to.be.true
expect(this.Features.hasFeature('link-url')).to.equal(
'https://www.overleaf.com'
)
expect(this.Features.hasFeature('oauth')).to.be.true
expect(this.Features.hasFeature('overleaf-integration')).to.be
.true
expect(this.Features.hasFeature('references')).to.be.true
expect(this.Features.hasFeature('registration')).to.be.true
expect(this.Features.hasFeature('saml')).to.be.true
})
it('should return false', function() {
expect(this.Features.hasFeature('templates-server-pro')).to.be
.false
})
})
})
})
})
})
})