From 9c5f63817ec1411a7142087c386cb3749bf45f84 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 16 Jun 2014 12:47:39 +0100 Subject: [PATCH] Send accessLevel info to client --- .../Features/Project/ProjectController.coffee | 40 +++++++--------- .../Features/Project/ProjectDeleter.coffee | 6 --- services/web/app/coffee/models/Project.coffee | 6 +-- services/web/app/coffee/router.coffee | 1 - services/web/app/views/project/archived.jade | 48 ------------------- .../Project/ProjectControllerTests.coffee | 21 +------- .../coffee/Project/ProjectDeleterTests.coffee | 16 ------- 7 files changed, 23 insertions(+), 115 deletions(-) delete mode 100644 services/web/app/views/project/archived.jade diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 0ba87f641d..d99d307b59 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -92,7 +92,7 @@ module.exports = tags: (cb)-> TagsHandler.getAllTags user_id, cb projects: (cb)-> - Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel', cb + Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived', cb }, (err, results)-> if err? logger.err err:err, "error getting data for project list page" @@ -102,14 +102,6 @@ module.exports = res.render 'project/list', viewModel timer.done() - archivedProjects: (req, res, next)-> - user_id = req.session.user._id - projectDeleter.findArchivedProjects user_id, 'name lastUpdated publicAccesLevel', (error, projects) -> - return next(error) if error? - logger.log projects: projects, user_id:user_id, "rendering archived project list" - viewModel = _buildListViewModel projects, [], [], [], {} - res.render 'project/archived', viewModel - loadEditor: (req, res, next)-> timer = new metrics.Timer("load-editor") if !Settings.editorIsOpen @@ -203,19 +195,14 @@ defaultSettingsForAnonymousUser = (user_id)-> dropbox: false trackChanges: false -_buildListViewModel = (projects, collabertions, readOnlyProjects, tags, tagsGroupedByProject)-> - for project in projects - project.accessLevel = "owner" - for project in collabertions - project.accessLevel = "readWrite" +_buildListViewModel = (ownedProjects, sharedProjects, readOnlyProjects, tags, tagsGroupedByProject)-> + projects = [] + for project in ownedProjects + projects.push _buildProjectViewModel(project, "owner") + for project in sharedProjects + projects.push _buildProjectViewModel(project, "readWrite") for project in readOnlyProjects - project.accessLevel = "readOnly" - projects = projects.concat(collabertions).concat(readOnlyProjects) - projects = projects.map (project)-> - project.tags = tagsGroupedByProject[project._id] || [] - return project - tags = _.sortBy tags, (tag)-> - -tag.project_ids.length + projects.push _buildProjectViewModel(project, "readOnly") return { title:'Your Projects' @@ -223,4 +210,13 @@ _buildListViewModel = (projects, collabertions, readOnlyProjects, tags, tagsGrou projects: JSON.stringify(projects) tags: JSON.stringify(tags) projectTabActive: true - } \ No newline at end of file + } + +_buildProjectViewModel = (project, accessLevel) -> + { + id: project._id + name: project.name + lastUpdated: project.lastUpdated + publicAccessLevel: project.publicAccesLevel + accessLevel: accessLevel + } diff --git a/services/web/app/coffee/Features/Project/ProjectDeleter.coffee b/services/web/app/coffee/Features/Project/ProjectDeleter.coffee index f9974261cd..dfe7592fb3 100644 --- a/services/web/app/coffee/Features/Project/ProjectDeleter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectDeleter.coffee @@ -56,9 +56,3 @@ module.exports = ProjectDeleter = restoreProject: (project_id, callback = (error) ->) -> Project.update {_id:project_id}, { $unset: { archived: true }}, callback - - findArchivedProjects: (owner_id, fields, callback = (error, projects) ->) -> - Project.find { - owner_ref: owner_id - archived: true - }, fields, callback diff --git a/services/web/app/coffee/models/Project.coffee b/services/web/app/coffee/models/Project.coffee index da9677b04d..25bafe81ac 100644 --- a/services/web/app/coffee/models/Project.coffee +++ b/services/web/app/coffee/models/Project.coffee @@ -57,9 +57,9 @@ ProjectSchema.statics.findPopulatedById = (project_id, callback)-> callback(null, projects[0]) ProjectSchema.statics.findAllUsersProjects = (user_id, requiredFields, callback)-> - this.find {owner_ref:user_id, archived: { $exists: false }}, requiredFields, (err, projects)=> - this.find {collaberator_refs:user_id, archived: { $exists: false }}, requiredFields, (err, collabertions)=> - this.find {readOnly_refs:user_id, archived: { $exists: false }}, requiredFields, (err, readOnlyProjects)=> + this.find {owner_ref:user_id}, requiredFields, (err, projects)=> + this.find {collaberator_refs:user_id}, requiredFields, (err, collabertions)=> + this.find {readOnly_refs:user_id}, requiredFields, (err, readOnlyProjects)=> callback(err, projects, collabertions, readOnlyProjects) sanitizeTypeOfElement = (elementType)-> diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 00768b095f..672da18224 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -94,7 +94,6 @@ module.exports = class Router app.get '/user/:user_id/personal_info', httpAuth, UserInfoController.getPersonalInfo app.get '/project', AuthenticationController.requireLogin(), ProjectController.projectListPage - app.get '/project/archived', AuthenticationController.requireLogin(), ProjectController.archivedProjects app.post '/project/new', AuthenticationController.requireLogin(), ProjectController.newProject app.get '/project/new/template', TemplatesMiddlewear.saveTemplateDataInSession, AuthenticationController.requireLogin(), TemplatesController.createProjectFromZipTemplate diff --git a/services/web/app/views/project/archived.jade b/services/web/app/views/project/archived.jade deleted file mode 100644 index 4c3e5e8394..0000000000 --- a/services/web/app/views/project/archived.jade +++ /dev/null @@ -1,48 +0,0 @@ -extends ../layout - -block content - mixin projectList(projects) - -each project in projects - - project_id = project._id.toString() - .project_entry(id=project_id) - .project-actions - a.btn(href='/project/'+project_id+'/restore', data-csrf=csrfToken, data-id=project_id).restoreProject Restore - | - a.btn.btn-danger(href='/project/'+project_id+'?forever=true', data-csrf=csrfToken, data-name=project.name, data-id=project_id).deleteProject Delete Forever - .projectName #{project.name} - - include ../general/sidebar - - .content-with-navigation-sidebar - .box#projectListArea - .row-fluid - .span12 - .page-header - h1 Archived Projects - - if (projects.length > 0) - .row-fluid - .span12 - ul#projectList - mixin projectList(projects) - - - - else - .row-fluid - .span12 You don't have any archived projects - - include ../general/small-footer - - - locals.supressDefaultJs = true - - script - window.requirejs = { - "paths" : { - "moment": "libs/moment" - } - }; - script( - data-main=jsPath+'list.js?fingerprint='+fingerprint(jsPath + 'list.js'), - baseurl=jsPath, - src=jsPath+'libs/require.js?fingerprint='+fingerprint(jsPath + 'libs/require.js') - ) - diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index 34df344e86..1ac388ed80 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -140,33 +140,16 @@ describe "ProjectController", -> it "should send the tags", (done)-> @res.render = (pageName, opts)=> - opts.tags.length.should.equal @tags.length + JSON.parse(opts.tags).length.should.equal @tags.length done() @ProjectController.projectListPage @req, @res it "should send the projects", (done)-> @res.render = (pageName, opts)=> - opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length) + JSON.parse(opts.projects).length.should.equal (@projects.length + @collabertions.length + @readOnly.length) done() @ProjectController.projectListPage @req, @res - describe "archivedProjects", -> - beforeEach -> - @projects = [{lastUpdated:1, _id:1}, {lastUpdated:2, _id:2}] - @ProjectDeleter.findArchivedProjects.callsArgWith(2, null, @projects) - - it "should render the project/archived page", (done)-> - @res.render = (pageName, opts)=> - pageName.should.equal "project/archived" - done() - @ProjectController.archivedProjects @req, @res - - it "should send the projects", (done)-> - @res.render = (pageName, opts)=> - opts.projects.length.should.equal (@projects.length) - done() - @ProjectController.archivedProjects @req, @res - describe "renameProject", -> beforeEach -> @newProjectName = "my supper great new project" diff --git a/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee index 77c37c7f14..978a14f024 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee @@ -113,19 +113,3 @@ describe 'Project deleter', -> }).should.equal true done() - describe "findArchivedProjects", -> - beforeEach -> - @projects = ["mock-project"] - @owner_id = "mock-owner-id" - @callback = sinon.stub() - @Project.find = sinon.stub().callsArgWith(2, null, @projects) - @deleter.findArchivedProjects @owner_id, @fields = "name lastModified", @callback - - it "should find the archived projects for the owner", -> - @Project.find - .calledWith(owner_ref: @owner_id, archived: true, @fields) - .should.equal true - - it "should return the projects", -> - @callback.calledWith(null, @projects).should.equal true -