Send accessLevel info to client

This commit is contained in:
James Allen 2014-06-16 12:47:39 +01:00
parent 63525a8bef
commit 9c5f63817e
7 changed files with 23 additions and 115 deletions

View file

@ -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
}
}
_buildProjectViewModel = (project, accessLevel) ->
{
id: project._id
name: project.name
lastUpdated: project.lastUpdated
publicAccessLevel: project.publicAccesLevel
accessLevel: accessLevel
}

View file

@ -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

View file

@ -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)->

View file

@ -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

View file

@ -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')
)

View file

@ -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"

View file

@ -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