Show token-access projects on the dashboard

This commit is contained in:
Shane Kilkelly 2017-10-05 13:20:06 +01:00
parent e4e558c0e6
commit b8d90a1a99
5 changed files with 38 additions and 14 deletions

View file

@ -135,7 +135,7 @@ module.exports = ProjectController =
notifications: (cb)->
NotificationsHandler.getUserNotifications user_id, cb
projects: (cb)->
ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref', cb
ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref tokens', cb
hasSubscription: (cb)->
LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb
user: (cb) ->
@ -146,16 +146,13 @@ module.exports = ProjectController =
return next(err)
logger.log results:results, user_id:user_id, "rendering project list"
tags = results.tags[0]
notifications = require("underscore").map results.notifications, (notification)->
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
return notification
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2]
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2], results.projects[3], results.projects[4]
user = results.user
ProjectController._injectProjectOwners projects, (error, projects) ->
return next(error) if error?
viewModel = {
title:'your_projects'
priority_title: true
@ -309,19 +306,33 @@ module.exports = ProjectController =
maxDocLength: Settings.max_doc_length
timer.done()
_buildProjectList: (ownedProjects, sharedProjects, readOnlyProjects)->
_buildProjectList: (ownedProjects, readAndWriteProjects, readOnlyProjects, tokenReadAndWriteProjects, tokenReadOnlyProjects)->
projects = []
for project in ownedProjects
projects.push ProjectController._buildProjectViewModel(project, "owner")
for project in sharedProjects
# Invite-access
for project in readAndWriteProjects
projects.push ProjectController._buildProjectViewModel(project, "readWrite")
for project in readOnlyProjects
projects.push ProjectController._buildProjectViewModel(project, "readOnly")
# Token-access
for project in tokenReadAndWriteProjects
projects.push ProjectController._buildProjectViewModel(project, "tokenReadAndWrite")
for project in tokenReadOnlyProjects
projects.push ProjectController._buildProjectViewModel(project, "tokenReadOnly")
return projects
_buildProjectViewModel: (project, accessLevel) ->
{
tokens =
readOnly: ''
readAndWrite: ''
if project.tokens?
if accessLevel in ['tokenReadAndWrite', 'owner']
tokens.readAndWrite = project.tokens.readAndWrite
if accessLevel in ['tokenReadOnly', 'owner']
tokens.readOnly = project.tokens.readOnly
model = {
id: project._id
name: project.name
lastUpdated: project.lastUpdated
@ -329,7 +340,9 @@ module.exports = ProjectController =
accessLevel: accessLevel
archived: !!project.archived
owner_ref: project.owner_ref
tokens: tokens
}
return model
_injectProjectOwners: (projects, callback = (error, projects) ->) ->
users = {}

View file

@ -50,14 +50,14 @@ module.exports = ProjectGetter =
return callback(err)
callback(null, project?[0])
findAllUsersProjects: (user_id, fields, callback = (error, ownedProjects, readAndWriteProjects, readOnlyProjects) ->) ->
findAllUsersProjects: (user_id, fields, callback = (error, ownedProjects, readAndWriteProjects, readOnlyProjects, tokenReadAndWrite, tokenReadOnly) ->) ->
CollaboratorsHandler = require "../Collaborators/CollaboratorsHandler"
Project.find {owner_ref: user_id}, fields, (error, ownedProjects) ->
return callback(error) if error?
CollaboratorsHandler.getProjectsUserIsMemberOf user_id, fields, (error, projects) ->
return callback(error) if error?
# TODO: Add token projects too
callback null, ownedProjects, projects.readAndWrite, projects.readOnly
callback null, ownedProjects, projects.readAndWrite, projects.readOnly, projects.tokenReadAndWrite, projects.tokenReadOnly
[

View file

@ -150,7 +150,7 @@
)
span
a.projectName(
href="/project/{{project.id}}"
href="{{projectLink(project)}}"
stop-propagation="click"
) {{project.name}}
span(

View file

@ -454,6 +454,15 @@ define [
$scope.updateVisibleProjects()
App.controller "ProjectListItemController", ($scope) ->
$scope.projectLink = (project) ->
if project.accessLevel == 'tokenReadAndWrite'
"/#{project.tokens.readAndWrite}"
else if project.accessLevel == 'tokenReadOnly'
"/read/#{project.tokens.readOnly}"
else
"/project/#{project.id}"
$scope.ownerName = () ->
if $scope.project.accessLevel == "owner"
return "You"
@ -464,4 +473,4 @@ define [
$scope.$watch "project.selected", (value) ->
if value?
$scope.updateSelectedProjects()
$scope.updateSelectedProjects()

View file

@ -221,6 +221,8 @@ describe "ProjectController", ->
@projects = [{lastUpdated:1, _id:1, owner_ref: "user-1"}, {lastUpdated:2, _id:2, owner_ref: "user-2"}]
@collabertions = [{lastUpdated:5, _id:5, owner_ref: "user-1"}]
@readOnly = [{lastUpdated:3, _id:3, owner_ref: "user-1"}]
@tokenReadAndWrite = [{lastUpdated:5, _id:6, owner_ref: "user-4"}]
@tokenReadOnly = [{lastUpdated:4, _id:7, owner_ref: "user-5"}]
@users =
'user-1':
@ -234,7 +236,7 @@ describe "ProjectController", ->
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly)
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly, @tokenReadAndWrite, @tokenReadOnly)
it "should render the project/list page", (done)->
@res.render = (pageName, opts)=>
@ -250,7 +252,7 @@ describe "ProjectController", ->
it "should send the projects", (done)->
@res.render = (pageName, opts)=>
opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length)
opts.projects.length.should.equal (@projects.length + @collabertions.length + @readOnly.length + @tokenReadAndWrite.length + @tokenReadOnly.length)
done()
@ProjectController.projectListPage @req, @res