mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 02:56:43 +00:00
Merge pull request #1948 from overleaf/cmg-allow-array-archiving
Make checking for project.archived array-friendly GitOrigin-RevId: 2902a12fb4611a5786d4b10feba534b1cd29668b
This commit is contained in:
parent
c8140f9641
commit
3422c17dc4
7 changed files with 122 additions and 13 deletions
services/web
app/src
test/unit/src/Project
|
@ -23,6 +23,7 @@ const projectDeleter = require('./ProjectDeleter')
|
|||
const projectDuplicator = require('./ProjectDuplicator')
|
||||
const projectCreationHandler = require('./ProjectCreationHandler')
|
||||
const editorController = require('../Editor/EditorController')
|
||||
const ProjectHelper = require('./ProjectHelper')
|
||||
const metrics = require('metrics-sharelatex')
|
||||
const { User } = require('../../models/User')
|
||||
const TagsHandler = require('../Tags/TagsHandler')
|
||||
|
@ -289,8 +290,8 @@ module.exports = ProjectController = {
|
|||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
projects = ProjectController._buildProjectList(projects)
|
||||
.filter(p => !p.archived)
|
||||
projects = ProjectController._buildProjectList(projects, user_id)
|
||||
.filter(p => !ProjectHelper.isArchived(p, user_id))
|
||||
.filter(p => !p.isV1Project)
|
||||
.map(p => ({ _id: p.id, name: p.name, accessLevel: p.accessLevel }))
|
||||
|
||||
|
@ -405,6 +406,7 @@ module.exports = ProjectController = {
|
|||
)
|
||||
const projects = ProjectController._buildProjectList(
|
||||
results.projects,
|
||||
user_id,
|
||||
results.v1Projects != null ? results.v1Projects.projects : undefined
|
||||
)
|
||||
const { user } = results
|
||||
|
@ -720,7 +722,7 @@ module.exports = ProjectController = {
|
|||
)
|
||||
},
|
||||
|
||||
_buildProjectList(allProjects, v1Projects) {
|
||||
_buildProjectList(allProjects, userId, v1Projects) {
|
||||
let project
|
||||
if (v1Projects == null) {
|
||||
v1Projects = []
|
||||
|
@ -738,7 +740,8 @@ module.exports = ProjectController = {
|
|||
ProjectController._buildProjectViewModel(
|
||||
project,
|
||||
'owner',
|
||||
Sources.OWNER
|
||||
Sources.OWNER,
|
||||
userId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -748,7 +751,8 @@ module.exports = ProjectController = {
|
|||
ProjectController._buildProjectViewModel(
|
||||
project,
|
||||
'readWrite',
|
||||
Sources.INVITE
|
||||
Sources.INVITE,
|
||||
userId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -757,7 +761,8 @@ module.exports = ProjectController = {
|
|||
ProjectController._buildProjectViewModel(
|
||||
project,
|
||||
'readOnly',
|
||||
Sources.INVITE
|
||||
Sources.INVITE,
|
||||
userId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -776,7 +781,8 @@ module.exports = ProjectController = {
|
|||
ProjectController._buildProjectViewModel(
|
||||
project,
|
||||
'readAndWrite',
|
||||
Sources.TOKEN
|
||||
Sources.TOKEN,
|
||||
userId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -790,7 +796,8 @@ module.exports = ProjectController = {
|
|||
ProjectController._buildProjectViewModel(
|
||||
project,
|
||||
'readOnly',
|
||||
Sources.TOKEN
|
||||
Sources.TOKEN,
|
||||
userId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -799,7 +806,7 @@ module.exports = ProjectController = {
|
|||
return projects
|
||||
},
|
||||
|
||||
_buildProjectViewModel(project, accessLevel, source) {
|
||||
_buildProjectViewModel(project, accessLevel, source, userId) {
|
||||
TokenAccessHandler.protectTokens(project, accessLevel)
|
||||
const model = {
|
||||
id: project._id,
|
||||
|
@ -809,7 +816,7 @@ module.exports = ProjectController = {
|
|||
publicAccessLevel: project.publicAccesLevel,
|
||||
accessLevel,
|
||||
source,
|
||||
archived: !!project.archived,
|
||||
archived: ProjectHelper.isArchived(project, userId),
|
||||
owner_ref: project.owner_ref,
|
||||
tokens: project.tokens,
|
||||
isV1Project: false
|
||||
|
|
|
@ -18,12 +18,23 @@ const ENGINE_TO_COMPILER_MAP = {
|
|||
xelatex: 'xelatex',
|
||||
lualatex: 'lualatex'
|
||||
}
|
||||
const { ObjectId } = require('../../infrastructure/mongojs')
|
||||
|
||||
module.exports = ProjectHelper = {
|
||||
compilerFromV1Engine(engine) {
|
||||
return ENGINE_TO_COMPILER_MAP[engine]
|
||||
},
|
||||
|
||||
isArchived(project, userId) {
|
||||
userId = ObjectId(userId)
|
||||
|
||||
if (Array.isArray(project.archived)) {
|
||||
return project.archived.find(id => id.equals(userId)) !== undefined
|
||||
} else {
|
||||
return project.archived
|
||||
}
|
||||
},
|
||||
|
||||
ensureNameIsUnique(nameList, name, suffixes, maxLength, callback) {
|
||||
// create a set of all project names
|
||||
if (suffixes == null) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
let ProjectLocator
|
||||
const { Project } = require('../../models/Project')
|
||||
const ProjectGetter = require('./ProjectGetter')
|
||||
const ProjectHelper = require('./ProjectHelper')
|
||||
const Errors = require('../Errors/Errors')
|
||||
const _ = require('underscore')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
@ -319,7 +320,7 @@ module.exports = ProjectLocator = {
|
|||
projects,
|
||||
project =>
|
||||
project.name.toLowerCase() === projectName &&
|
||||
project.archived !== true
|
||||
!ProjectHelper.isArchived(project, user_id)
|
||||
)
|
||||
logger.log(
|
||||
{ user_id, projectName, totalProjects: projects.length, project },
|
||||
|
|
|
@ -61,7 +61,7 @@ const ProjectSchema = new Schema({
|
|||
spellCheckLanguage: { type: String, default: 'en' },
|
||||
deletedByExternalDataSource: { type: Boolean, default: false },
|
||||
description: { type: String, default: '' },
|
||||
archived: { type: Boolean },
|
||||
archived: Schema.Types.Mixed,
|
||||
deletedDocs: [DeletedDocSchema],
|
||||
deletedFiles: [DeletedFileSchema],
|
||||
imageName: { type: String },
|
||||
|
|
|
@ -79,6 +79,9 @@ describe('ProjectController', function() {
|
|||
findAllUsersProjects: sinon.stub(),
|
||||
getProject: sinon.stub()
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
|
@ -136,6 +139,7 @@ describe('ProjectController', function() {
|
|||
'./ProjectDuplicator': this.ProjectDuplicator,
|
||||
'./ProjectCreationHandler': this.ProjectCreationHandler,
|
||||
'../Editor/EditorController': this.EditorController,
|
||||
'./ProjectHelper': this.ProjectHelper,
|
||||
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
||||
'../Subscription/LimitationsManager': this.LimitationsManager,
|
||||
'../Tags/TagsHandler': this.TagsHandler,
|
||||
|
@ -897,13 +901,27 @@ describe('ProjectController', function() {
|
|||
somethingElse: 1
|
||||
}
|
||||
]
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[0], this.user._id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[1], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[2], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[3], this.user._id)
|
||||
.returns(false)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, [])
|
||||
this.ProjectController._buildProjectList = sinon.stub().returns(projects)
|
||||
this.AuthenticationController.getLoggedInUserId = sinon
|
||||
.stub()
|
||||
.returns('abc')
|
||||
.returns(this.user._id)
|
||||
return done()
|
||||
})
|
||||
|
||||
|
|
|
@ -16,12 +16,60 @@ const should = chai.should()
|
|||
const { expect } = chai
|
||||
const modulePath = '../../../../app/src/Features/Project/ProjectHelper.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongojs')
|
||||
|
||||
describe('ProjectHelper', function() {
|
||||
beforeEach(function() {
|
||||
this.project = {
|
||||
_id: '123213jlkj9kdlsaj'
|
||||
}
|
||||
|
||||
this.user = {
|
||||
_id: '588f3ddae8ebc1bac07c9fa4',
|
||||
first_name: 'bjkdsjfk',
|
||||
features: {}
|
||||
}
|
||||
|
||||
return (this.ProjectHelper = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('isArchived', function() {
|
||||
describe('project.archived being an array', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
this.project.archived = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
]
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
this.project.archived = []
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being a boolean', function() {
|
||||
it('returns true if archived is true', function() {
|
||||
this.project.archived = true
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if archived is false', function() {
|
||||
this.project.archived = false
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('compilerFromV1Engine', function() {
|
||||
it('returns the correct engine for latex_dvipdf', function() {
|
||||
return expect(
|
||||
|
|
|
@ -65,6 +65,9 @@ describe('ProjectLocator', function() {
|
|||
this.ProjectGetter = {
|
||||
getProject: sinon.stub().callsArgWith(2, null, project)
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
}
|
||||
return (this.locator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
|
@ -73,6 +76,7 @@ describe('ProjectLocator', function() {
|
|||
'../../models/Project': { Project },
|
||||
'../../models/User': { User: this.User },
|
||||
'./ProjectGetter': this.ProjectGetter,
|
||||
'./ProjectHelper': this.ProjectHelper,
|
||||
'logger-sharelatex': {
|
||||
log() {},
|
||||
err() {},
|
||||
|
@ -562,6 +566,26 @@ describe('ProjectLocator', function() {
|
|||
{ name: 'Noooo' }
|
||||
]
|
||||
}
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[0], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[1], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[2], user_id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[3], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[4], user_id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[5], user_id)
|
||||
.returns(false)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, projects)
|
||||
|
|
Loading…
Add table
Reference in a new issue