From b8d90a1a99bd2da749043f5905987467a72cbead Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 5 Oct 2017 13:20:06 +0100 Subject: [PATCH] Show token-access projects on the dashboard --- .../Features/Project/ProjectController.coffee | 29 ++++++++++++++----- .../Features/Project/ProjectGetter.coffee | 4 +-- .../app/views/project/list/project-list.pug | 2 +- .../main/project-list/project-list.coffee | 11 ++++++- .../Project/ProjectControllerTests.coffee | 6 ++-- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 4feef49028..7765bad0dc 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -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 = {} diff --git a/services/web/app/coffee/Features/Project/ProjectGetter.coffee b/services/web/app/coffee/Features/Project/ProjectGetter.coffee index 4e354495a5..3c00d09ae6 100644 --- a/services/web/app/coffee/Features/Project/ProjectGetter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectGetter.coffee @@ -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 [ diff --git a/services/web/app/views/project/list/project-list.pug b/services/web/app/views/project/list/project-list.pug index 629c3dc62d..a9d322b384 100644 --- a/services/web/app/views/project/list/project-list.pug +++ b/services/web/app/views/project/list/project-list.pug @@ -150,7 +150,7 @@ ) span a.projectName( - href="/project/{{project.id}}" + href="{{projectLink(project)}}" stop-propagation="click" ) {{project.name}} span( diff --git a/services/web/public/coffee/main/project-list/project-list.coffee b/services/web/public/coffee/main/project-list/project-list.coffee index cafbd7c81b..64fe9a93ab 100644 --- a/services/web/public/coffee/main/project-list/project-list.coffee +++ b/services/web/public/coffee/main/project-list/project-list.coffee @@ -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() \ No newline at end of file + $scope.updateSelectedProjects() diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index cb0d16ed99..14f27ead68 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -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