Merge pull request #1127 from sharelatex/as-keep-tags-archive

Keep tags when archiving project

GitOrigin-RevId: 40b23895ef27a69500194cfc149a236ae615f271
This commit is contained in:
Chrystal Maria Griffiths 2018-11-13 10:34:27 +00:00 committed by sharelatex
parent 568273ba14
commit f1c8dcdf1e
4 changed files with 56 additions and 68 deletions

View file

@ -18,7 +18,12 @@
"mocha": true "mocha": true
}, },
"globals": { "globals": {
"expect": true "expect": true,
"define": true,
"$": true,
"angular": true,
// Injected in layout.pug
"user_id": true
}, },
"settings": { "settings": {
// Tell eslint-plugin-react which version of React we are using // Tell eslint-plugin-react which version of React we are using

View file

@ -30,13 +30,7 @@ module.exports = ProjectDeleter =
CollaboratorsHandler.removeUserFromAllProjets user_id, callback CollaboratorsHandler.removeUserFromAllProjets user_id, callback
deleteProject: (project_id, callback = (error) ->) -> deleteProject: (project_id, callback = (error) ->) ->
# archiveProject takes care of the clean-up logger.log project_id: project_id, "deleting project"
ProjectDeleter.archiveProject project_id, (error) ->
logger.log project_id: project_id, "deleting project"
Project.remove _id: project_id, callback
archiveProject: (project_id, callback = (error) ->)->
logger.log project_id:project_id, "archived project from user request"
async.series [ async.series [
(cb)-> (cb)->
documentUpdaterHandler.flushProjectToMongoAndDelete project_id, cb documentUpdaterHandler.flushProjectToMongoAndDelete project_id, cb
@ -45,9 +39,18 @@ module.exports = ProjectDeleter =
for member_id in member_ids for member_id in member_ids
tagsHandler.removeProjectFromAllTags member_id, project_id, (err)-> tagsHandler.removeProjectFromAllTags member_id, project_id, (err)->
cb() #doesn't matter if this fails or the order it happens in cb() #doesn't matter if this fails or the order it happens in
(cb)-> (cb) ->
Project.update {_id:project_id}, { $set: { archived: true }}, cb Project.remove _id: project_id, cb
], (err)-> ], (err) ->
if err?
logger.err err:err, "problem deleting project"
return callback(err)
logger.log project_id:project_id, "successfully deleting project from user request"
callback()
archiveProject: (project_id, callback = (error) ->)->
logger.log project_id:project_id, "archived project from user request"
Project.update {_id:project_id}, { $set: { archived: true }}, (err)->
if err? if err?
logger.err err:err, "problem archived project" logger.err err:err, "problem archived project"
return callback(err) return callback(err)

View file

@ -1,9 +1,5 @@
/* eslint-disable /* eslint-disable
camelcase, camelcase,
max-len,
no-return-assign,
no-undef,
no-unused-vars,
*/ */
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
@ -27,7 +23,6 @@ define(['base'], function(App) {
$timeout, $timeout,
localStorage localStorage
) { ) {
let project_id
$scope.projects = window.data.projects $scope.projects = window.data.projects
$scope.tags = window.data.tags $scope.tags = window.data.tags
$scope.notifications = window.data.notifications $scope.notifications = window.data.notifications
@ -80,7 +75,7 @@ define(['base'], function(App) {
} }
for (var tag of Array.from($scope.tags)) { for (var tag of Array.from($scope.tags)) {
for (project_id of Array.from(tag.project_ids || [])) { for (let project_id of Array.from(tag.project_ids || [])) {
project = projectsById[project_id] project = projectsById[project_id]
if (project != null) { if (project != null) {
if (!project.tags) { if (!project.tags) {
@ -146,9 +141,9 @@ define(['base'], function(App) {
$scope.selectedProjects = $scope.projects.filter( $scope.selectedProjects = $scope.projects.filter(
project => project.selected project => project.selected
) )
return ($scope.isArchiveableProjectSelected = $scope.selectedProjects.some( $scope.isArchiveableProjectSelected = $scope.selectedProjects.some(
project => window.user_id === project.owner._id project => window.user_id === project.owner._id
)) )
} }
$scope.getSelectedProjects = () => $scope.selectedProjects $scope.getSelectedProjects = () => $scope.selectedProjects
@ -252,7 +247,7 @@ define(['base'], function(App) {
// Remove project_id from tag.project_ids // Remove project_id from tag.project_ids
const remaining_project_ids = [] const remaining_project_ids = []
const removed_project_ids = [] const removed_project_ids = []
for (project_id of Array.from(tag.project_ids)) { for (let project_id of Array.from(tag.project_ids)) {
if (!Array.from(remove_project_ids).includes(project_id)) { if (!Array.from(remove_project_ids).includes(project_id)) {
remaining_project_ids.push(project_id) remaining_project_ids.push(project_id)
} else { } else {
@ -282,7 +277,6 @@ define(['base'], function(App) {
) )
// Remove tag from project.tags // Remove tag from project.tags
const remaining_tags = []
for (project of Array.from(selected_projects)) { for (project of Array.from(selected_projects)) {
if (!project.tags) { if (!project.tags) {
project.tags = [] project.tags = []
@ -293,7 +287,7 @@ define(['base'], function(App) {
} }
} }
for (project_id of Array.from(removed_project_ids)) { for (let project_id of Array.from(removed_project_ids)) {
queuedHttp({ queuedHttp({
method: 'DELETE', method: 'DELETE',
url: `/tag/${tag._id}/project/${project_id}`, url: `/tag/${tag._id}/project/${project_id}`,
@ -340,7 +334,7 @@ define(['base'], function(App) {
// Add project_ids into tag.project_ids // Add project_ids into tag.project_ids
const added_project_ids = [] const added_project_ids = []
for (project_id of Array.from($scope.getSelectedProjectIds())) { for (let project_id of Array.from($scope.getSelectedProjectIds())) {
if (!Array.from(tag.project_ids).includes(project_id)) { if (!Array.from(tag.project_ids).includes(project_id)) {
tag.project_ids.push(project_id) tag.project_ids.push(project_id)
added_project_ids.push(project_id) added_project_ids.push(project_id)
@ -359,7 +353,7 @@ define(['base'], function(App) {
return (() => { return (() => {
const result = [] const result = []
for (project_id of Array.from(added_project_ids)) { for (let project_id of Array.from(added_project_ids)) {
result.push( result.push(
queuedHttp.post(`/tag/${tag._id}/project/${project_id}`, { queuedHttp.post(`/tag/${tag._id}/project/${project_id}`, {
_csrf: window.csrfToken _csrf: window.csrfToken
@ -441,7 +435,6 @@ define(['base'], function(App) {
.then(() => (project.name = newName)) .then(() => (project.name = newName))
$scope.openRenameProjectModal = function() { $scope.openRenameProjectModal = function() {
let modalInstance
project = $scope.getFirstSelectedProject() project = $scope.getFirstSelectedProject()
if (project == null || project.accessLevel !== 'owner') { if (project == null || project.accessLevel !== 'owner') {
return return
@ -451,7 +444,7 @@ define(['base'], function(App) {
'project action', 'project action',
'Rename' 'Rename'
) )
return (modalInstance = $modal.open({ $modal.open({
templateUrl: 'renameProjectModalTemplate', templateUrl: 'renameProjectModalTemplate',
controller: 'RenameProjectModalController', controller: 'RenameProjectModalController',
resolve: { resolve: {
@ -460,7 +453,7 @@ define(['base'], function(App) {
} }
}, },
scope: $scope scope: $scope
})) })
} }
$scope.cloneProject = function(project, cloneName) { $scope.cloneProject = function(project, cloneName) {
@ -491,13 +484,12 @@ define(['base'], function(App) {
} }
$scope.openCloneProjectModal = function() { $scope.openCloneProjectModal = function() {
let modalInstance
project = $scope.getFirstSelectedProject() project = $scope.getFirstSelectedProject()
if (project == null) { if (project == null) {
return return
} }
return (modalInstance = $modal.open({ $modal.open({
templateUrl: 'cloneProjectModalTemplate', templateUrl: 'cloneProjectModalTemplate',
controller: 'CloneProjectModalController', controller: 'CloneProjectModalController',
resolve: { resolve: {
@ -506,7 +498,7 @@ define(['base'], function(App) {
} }
}, },
scope: $scope scope: $scope
})) })
} }
$scope.openArchiveProjectsModal = function() { $scope.openArchiveProjectsModal = function() {
@ -533,14 +525,7 @@ define(['base'], function(App) {
$scope.archiveOrLeaveProjects($scope.getSelectedProjects()) $scope.archiveOrLeaveProjects($scope.getSelectedProjects())
$scope.archiveOrLeaveProjects = function(projects) { $scope.archiveOrLeaveProjects = function(projects) {
const projectIds = projects.map(p => p.id) for (let project of projects) {
// Remove project from any tags
for (tag of Array.from($scope.tags)) {
$scope._removeProjectIdsFromTagArray(tag, projectIds)
}
for (project of Array.from(projects)) {
project.tags = []
if (project.accessLevel === 'owner') { if (project.accessLevel === 'owner') {
project.archived = true project.archived = true
queuedHttp({ queuedHttp({
@ -594,7 +579,7 @@ define(['base'], function(App) {
$scope._removeProjectIdsFromTagArray(tag, selected_project_ids) $scope._removeProjectIdsFromTagArray(tag, selected_project_ids)
} }
for (project_id of Array.from(selected_project_ids)) { for (let project_id of Array.from(selected_project_ids)) {
queuedHttp({ queuedHttp({
method: 'DELETE', method: 'DELETE',
url: `/project/${project_id}?forever=true`, url: `/project/${project_id}?forever=true`,
@ -630,11 +615,10 @@ define(['base'], function(App) {
} }
$scope.openUploadProjectModal = function() { $scope.openUploadProjectModal = function() {
let modalInstance $modal.open({
return (modalInstance = $modal.open({
templateUrl: 'uploadProjectModalTemplate', templateUrl: 'uploadProjectModalTemplate',
controller: 'UploadProjectModalController' controller: 'UploadProjectModalController'
})) })
} }
$scope.downloadSelectedProjects = () => $scope.downloadSelectedProjects = () =>
@ -733,7 +717,7 @@ define(['base'], function(App) {
.catch(function(response) { .catch(function(response) {
const { data, status } = response const { data, status } = response
const error = status === 400 ? { message: data } : true const error = status === 400 ? { message: data } : true
const modalInstance = $modal.open({ $modal.open({
templateUrl: 'showErrorModalTemplate', templateUrl: 'showErrorModalTemplate',
controller: 'ShowErrorModalController', controller: 'ShowErrorModalController',
resolve: { resolve: {

View file

@ -82,32 +82,34 @@ describe 'ProjectDeleter', ->
describe "deleteProject", -> describe "deleteProject", ->
beforeEach (done) -> beforeEach (done) ->
@project_id = "mock-project-id-123" @project_id = "mock-project-id-123"
@deleter.archiveProject = sinon.stub().callsArg(1)
@deleter.deleteProject @project_id, done
it "should archive the project to clean it up", ->
@deleter.archiveProject
.calledWith(@project_id)
.should.equal true
it "should remove the project from Mongo", ->
@Project.remove
.calledWith(_id: @project_id)
.should.equal true
describe "archiveProject", ->
beforeEach ->
@CollaboratorsHandler.getMemberIds = sinon.stub() @CollaboratorsHandler.getMemberIds = sinon.stub()
@CollaboratorsHandler.getMemberIds.withArgs(@project_id).yields(null, ["member-id-1", "member-id-2"]) @CollaboratorsHandler.getMemberIds.withArgs(@project_id).yields(null, ["member-id-1", "member-id-2"])
@Project.update.callsArgWith(2) @Project.remove.callsArgWith(1)
done()
it "should flushProjectToMongoAndDelete in doc updater", (done)-> it "should flushProjectToMongoAndDelete in doc updater", (done)->
@deleter.archiveProject @project_id, => @deleter.deleteProject @project_id, =>
@documentUpdaterHandler.flushProjectToMongoAndDelete.calledWith(@project_id).should.equal true @documentUpdaterHandler.flushProjectToMongoAndDelete.calledWith(@project_id).should.equal true
done() done()
it "should remove the project", (done)-> it "should removeProjectFromAllTags", (done)->
@deleter.deleteProject @project_id, =>
@TagsHandler.removeProjectFromAllTags.calledWith("member-id-1", @project_id).should.equal true
@TagsHandler.removeProjectFromAllTags.calledWith("member-id-2", @project_id).should.equal true
done()
it "should remove the project from Mongo", (done) ->
@deleter.deleteProject @project_id, =>
@Project.remove.calledWith({
_id: @project_id
}).should.equal true
done()
describe "archiveProject", ->
beforeEach ->
@Project.update.callsArgWith(2)
it "should update the project", (done)->
@deleter.archiveProject @project_id, => @deleter.archiveProject @project_id, =>
@Project.update.calledWith({ @Project.update.calledWith({
_id:@project_id _id:@project_id
@ -116,12 +118,6 @@ describe 'ProjectDeleter', ->
}).should.equal true }).should.equal true
done() done()
it "should removeProjectFromAllTags", (done)->
@deleter.archiveProject @project_id, =>
@TagsHandler.removeProjectFromAllTags.calledWith("member-id-1", @project_id).should.equal true
@TagsHandler.removeProjectFromAllTags.calledWith("member-id-2", @project_id).should.equal true
done()
describe "restoreProject", -> describe "restoreProject", ->
beforeEach -> beforeEach ->
@Project.update.callsArgWith(2) @Project.update.callsArgWith(2)