Преглед изворни кода

Merge branch 'user-csv' of git://github.com/heukirne/web-sharelatex into heukirne-user-csv

Henry Oswald пре 11 година
родитељ
комит
d3f6c0c614

+ 16 - 0
services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee

@@ -85,3 +85,19 @@ module.exports =
 			title: "Sucessfully joined group"
 			title: "Sucessfully joined group"
 			licenceName:licence.name	
 			licenceName:licence.name	
 
 
+	exportGroupCsv: (req, res)->
+		user_id = req.session.user._id
+		logger.log user_id: user_id, "exporting group csv"
+		SubscriptionLocator.getUsersSubscription user_id, (err, subscription)->
+			if !subscription.groupPlan
+				return res.redirect("/")
+			SubscriptionGroupHandler.getPopulatedListOfMembers user_id, (err, users)->
+				groupCsv = ""
+				for user in users
+					groupCsv += user.email + "\n"
+				res.header(
+					"Content-Disposition",
+					"attachment; filename=Group.csv"
+				)
+				res.contentType('text/csv')
+				res.send(groupCsv)

+ 1 - 0
services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee

@@ -22,6 +22,7 @@ module.exports =
 
 
 		app.get '/subscription/group',  AuthenticationController.requireLogin(), SubscriptionGroupController.renderSubscriptionGroupAdminPage
 		app.get '/subscription/group',  AuthenticationController.requireLogin(), SubscriptionGroupController.renderSubscriptionGroupAdminPage
 		app.post '/subscription/group/user', AuthenticationController.requireLogin(),  SubscriptionGroupController.addUserToGroup
 		app.post '/subscription/group/user', AuthenticationController.requireLogin(),  SubscriptionGroupController.addUserToGroup
+		app.get '/subscription/group/export',  AuthenticationController.requireLogin(), SubscriptionGroupController.exportGroupCsv
 		app.del '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup
 		app.del '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup
 
 
 		app.get '/user/subscription/:subscription_id/group/invited', AuthenticationController.requireLogin(), SubscriptionGroupController.renderGroupInvitePage
 		app.get '/user/subscription/:subscription_id/group/invited', AuthenticationController.requireLogin(), SubscriptionGroupController.renderGroupInvitePage

+ 3 - 1
services/web/app/views/subscriptions/group_admin.jade

@@ -73,8 +73,10 @@ block content
 												ng-model="inputs.emails",
 												ng-model="inputs.emails",
 												on-enter="addMembers()"
 												on-enter="addMembers()"
 											)
 											)
-										.col-xs-6
+										.col-xs-4
 											button.btn.btn-primary(ng-click="addMembers()") #{translate("add")}
 											button.btn.btn-primary(ng-click="addMembers()") #{translate("add")}
+										.col-xs-2
+											a(href="/subscription/group/export") Export CSV
 
 
 	script(type="text/javascript").
 	script(type="text/javascript").
 		window.users = !{JSON.stringify(users)};
 		window.users = !{JSON.stringify(users)};

+ 31 - 6
services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee

@@ -3,12 +3,12 @@ should = require('chai').should()
 sinon = require 'sinon'
 sinon = require 'sinon'
 assert = require("chai").assert
 assert = require("chai").assert
 modulePath = "../../../../app/js/Features/Subscription/SubscriptionGroupController"
 modulePath = "../../../../app/js/Features/Subscription/SubscriptionGroupController"
-
+MockResponse = require "../helpers/MockResponse"
 
 
 describe "Subscription Group Controller", ->
 describe "Subscription Group Controller", ->
 
 
 	beforeEach ->
 	beforeEach ->
-		@user = {_id:"!@312431"}
+		@user = {_id:"!@312431",email:"user@email.com"}
 		@subscription = {}
 		@subscription = {}
 		@GroupHandler = 
 		@GroupHandler = 
 			addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
 			addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
@@ -16,7 +16,7 @@ describe "Subscription Group Controller", ->
 			isUserPartOfGroup: sinon.stub()
 			isUserPartOfGroup: sinon.stub()
 			sendVerificationEmail:sinon.stub()
 			sendVerificationEmail:sinon.stub()
 			processGroupVerification:sinon.stub()
 			processGroupVerification:sinon.stub()
-
+			getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
 		@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
 		@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
 
 
 		@SubscriptionDomainHandler = 
 		@SubscriptionDomainHandler = 
@@ -78,7 +78,7 @@ describe "Subscription Group Controller", ->
 
 
 	describe "renderSubscriptionGroupAdminPage", ->	
 	describe "renderSubscriptionGroupAdminPage", ->	
 		it "should redirect you if you don't have a group account", (done)->
 		it "should redirect you if you don't have a group account", (done)->
-			@subscription.group = false
+			@subscription.groupPlan = false
 
 
 			res =
 			res =
 				redirect : (path)=>
 				redirect : (path)=>
@@ -86,7 +86,6 @@ describe "Subscription Group Controller", ->
 					done()
 					done()
 			@Controller.renderSubscriptionGroupAdminPage @req, res
 			@Controller.renderSubscriptionGroupAdminPage @req, res
 
 
-
 	describe "renderGroupInvitePage", ->
 	describe "renderGroupInvitePage", ->
 		describe "with a valid licence", ->
 		describe "with a valid licence", ->
 			beforeEach ->
 			beforeEach ->
@@ -166,4 +165,30 @@ describe "Subscription Group Controller", ->
 			it "should send a 500", (done)->
 			it "should send a 500", (done)->
 				@Controller.completeJoin @req, {}
 				@Controller.completeJoin @req, {}
 				@ErrorsController.notFound.called.should.equal true
 				@ErrorsController.notFound.called.should.equal true
-				done()
+				done()
+	describe "exportGroupCsv", ->	
+
+		beforeEach ->
+			@subscription.groupPlan = true
+			@res = new MockResponse()
+			@res.contentType = sinon.stub()
+			@res.header = sinon.stub()
+			@res.send = sinon.stub()
+			@Controller.exportGroupCsv @req, @res
+
+		it "should set the correct content type on the request", ->
+			@res.contentType
+				.calledWith("text/csv")
+				.should.equal true
+
+		it "should name the exported csv file", ->
+			@res.header
+				.calledWith(
+					"Content-Disposition",
+					"attachment; filename=Group.csv")
+				.should.equal true
+
+		it "should export the correct csv", ->
+			@res.send
+				.calledWith("user@email.com\n")
+				.should.equal true