mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-22 02:04:31 +00:00
Merge pull request #2081 from overleaf/cmg-per-user-trash
Add per-user trashed state to project model GitOrigin-RevId: 16a753702d3503eee011dd2adca5dc8df3da87f4
This commit is contained in:
parent
c1f8ac8de1
commit
6f2b4d3da3
7 changed files with 84 additions and 23 deletions
|
@ -285,13 +285,13 @@ module.exports = ProjectController = {
|
|||
const user_id = AuthenticationController.getLoggedInUserId(req)
|
||||
return ProjectGetter.findAllUsersProjects(
|
||||
user_id,
|
||||
'name lastUpdated publicAccesLevel archived owner_ref tokens',
|
||||
'name lastUpdated publicAccesLevel archived trashed owner_ref tokens',
|
||||
function(err, projects) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
projects = ProjectController._buildProjectList(projects, user_id)
|
||||
.filter(p => !ProjectHelper.isArchived(p, user_id))
|
||||
.filter(p => !ProjectHelper.isArchivedOrTrashed(p, user_id))
|
||||
.filter(p => !p.isV1Project)
|
||||
.map(p => ({ _id: p.id, name: p.name, accessLevel: p.accessLevel }))
|
||||
|
||||
|
|
|
@ -31,10 +31,27 @@ module.exports = ProjectHelper = {
|
|||
if (Array.isArray(project.archived)) {
|
||||
return project.archived.find(id => id.equals(userId)) !== undefined
|
||||
} else {
|
||||
return project.archived
|
||||
return !!project.archived
|
||||
}
|
||||
},
|
||||
|
||||
isTrashed(project, userId) {
|
||||
userId = ObjectId(userId)
|
||||
|
||||
if (project.trashed) {
|
||||
return project.trashed.find(id => id.equals(userId)) !== undefined
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
isArchivedOrTrashed(project, userId) {
|
||||
return (
|
||||
ProjectHelper.isArchived(project, userId) ||
|
||||
ProjectHelper.isTrashed(project, userId)
|
||||
)
|
||||
},
|
||||
|
||||
ensureNameIsUnique(nameList, name, suffixes, maxLength, callback) {
|
||||
// create a set of all project names
|
||||
if (suffixes == null) {
|
||||
|
|
|
@ -308,7 +308,7 @@ module.exports = ProjectLocator = {
|
|||
findUsersProjectByName(user_id, projectName, callback) {
|
||||
return ProjectGetter.findAllUsersProjects(
|
||||
user_id,
|
||||
'name archived',
|
||||
'name archived trashed',
|
||||
function(err, allProjects) {
|
||||
if (typeof error !== 'undefined' && error !== null) {
|
||||
return callback(error)
|
||||
|
@ -320,7 +320,7 @@ module.exports = ProjectLocator = {
|
|||
projects,
|
||||
project =>
|
||||
project.name.toLowerCase() === projectName &&
|
||||
!ProjectHelper.isArchived(project, user_id)
|
||||
!ProjectHelper.isArchivedOrTrashed(project, user_id)
|
||||
)
|
||||
logger.log(
|
||||
{ user_id, projectName, totalProjects: projects.length, project },
|
||||
|
|
|
@ -62,6 +62,7 @@ const ProjectSchema = new Schema({
|
|||
deletedByExternalDataSource: { type: Boolean, default: false },
|
||||
description: { type: String, default: '' },
|
||||
archived: Schema.Types.Mixed,
|
||||
trashed: [{ type: ObjectId, ref: 'User' }],
|
||||
deletedDocs: [DeletedDocSchema],
|
||||
deletedFiles: [DeletedFileSchema],
|
||||
imageName: { type: String },
|
||||
|
|
|
@ -80,7 +80,9 @@ describe('ProjectController', function() {
|
|||
getProject: sinon.stub()
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
isArchived: sinon.stub(),
|
||||
isTrashed: sinon.stub(),
|
||||
isArchivedOrTrashed: sinon.stub()
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
|
||||
|
@ -878,6 +880,7 @@ describe('ProjectController', function() {
|
|||
const projects = [
|
||||
{
|
||||
archived: true,
|
||||
trashed: true,
|
||||
id: 'a',
|
||||
name: 'A',
|
||||
accessLevel: 'a',
|
||||
|
@ -892,6 +895,7 @@ describe('ProjectController', function() {
|
|||
},
|
||||
{
|
||||
archived: false,
|
||||
trashed: true,
|
||||
id: 'c',
|
||||
name: 'C',
|
||||
accessLevel: 'c',
|
||||
|
@ -899,6 +903,7 @@ describe('ProjectController', function() {
|
|||
},
|
||||
{
|
||||
archived: false,
|
||||
trashed: false,
|
||||
id: 'd',
|
||||
name: 'D',
|
||||
accessLevel: 'd',
|
||||
|
@ -906,16 +911,16 @@ describe('ProjectController', function() {
|
|||
}
|
||||
]
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[0], this.user._id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[1], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[2], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[3], this.user._id)
|
||||
.returns(false)
|
||||
|
||||
|
@ -934,7 +939,6 @@ describe('ProjectController', function() {
|
|||
expect(data).to.deep.equal({
|
||||
projects: [
|
||||
{ _id: 'b', name: 'B', accessLevel: 'b' },
|
||||
{ _id: 'c', name: 'C', accessLevel: 'c' },
|
||||
{ _id: 'd', name: 'D', accessLevel: 'd' }
|
||||
]
|
||||
})
|
||||
|
|
|
@ -68,6 +68,43 @@ describe('ProjectHelper', function() {
|
|||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being undefined', function() {
|
||||
it('returns false if archived is undefined', function() {
|
||||
this.project.archived = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('isTrashed', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
this.project.trashed = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
]
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
this.project.trashed = []
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
|
||||
describe('project.trashed being undefined', function() {
|
||||
it('returns false if trashed is undefined', function() {
|
||||
this.project.trashed = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('compilerFromV1Engine', function() {
|
||||
|
|
|
@ -47,7 +47,9 @@ describe('ProjectLocator', function() {
|
|||
getProject: sinon.stub().callsArgWith(2, null, project)
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
isArchived: sinon.stub(),
|
||||
isTrashed: sinon.stub(),
|
||||
isArchivedOrTrashed: sinon.stub()
|
||||
}
|
||||
this.locator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
|
@ -602,31 +604,31 @@ describe('ProjectLocator', function() {
|
|||
owned: [
|
||||
{ name: 'notThis' },
|
||||
{ name: 'wellll' },
|
||||
{ name: 'findThis', archived: true },
|
||||
{ name: 'findThis', archived: true, trashed: true },
|
||||
stubbedProject,
|
||||
{ name: 'findThis', archived: true },
|
||||
{ name: 'Noooo' }
|
||||
{ name: 'findThis', archived: true, trashed: false },
|
||||
{ name: 'Noooo', trashed: true }
|
||||
]
|
||||
}
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[0], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[1], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[2], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[3], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[4], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[5], userId)
|
||||
.returns(false)
|
||||
.returns(true)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
|
|
Loading…
Reference in a new issue