-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathCFPAdmin.scala
928 lines (779 loc) · 45.4 KB
/
CFPAdmin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
package controllers
import com.sksamuel.elastic4s.requests.searches.{SearchHit, SearchResponse}
import library._
import library.search.ElasticSearch
import models.Review._
import models._
import org.apache.commons.io.FileUtils
import play.api.data.Forms._
import play.api.data._
import play.api.data.validation.Constraints._
import play.api.i18n.Messages
import play.api.mvc.{Action, AnyContent}
import java.io.{File, FileOutputStream, OutputStreamWriter, PrintWriter}
/**
* The backoffice controller for the CFP technical committee.
*
* Author: @nmartignole
* Created: 11/11/2013 09:09 in Thalys, heading to Devoxx2013
*/
object CFPAdmin extends SecureCFPController {
val messageForm: Form[String] = Form("msg" -> nonEmptyText(maxLength = 1000))
val voteForm: Form[Int] = Form("vote" -> number(min = 0, max = 10))
val delayedReviewForm: Form[String] = Form("delayedReviewReason" -> text(maxLength = 1000))
val editSpeakerForm = Form(
tuple(
"uuid" -> text.verifying(nonEmpty, maxLength(50)),
"firstName" -> text.verifying(nonEmpty, maxLength(30)),
"lastName" -> text.verifying(nonEmpty, maxLength(30))
)
)
val speakerForm = play.api.data.Form(mapping(
"uuid" -> optional(text),
"email" -> (email verifying nonEmpty),
"lastName" -> text,
"bio2" -> nonEmptyText(maxLength = 1200),
"lang2" -> optional(text),
"twitter2" -> optional(text),
"avatarUrl2" -> optional(text),
"company2" -> optional(text),
"blog2" -> optional(text),
"firstName" -> text,
"acceptTermsConditions" -> boolean,
"qualifications2" -> nonEmptyText(maxLength = 750)
)(Speaker.createOrEditSpeaker)(Speaker.unapplyFormEdit))
def index(page: Int,
pageReview: Int,
sort: Option[String],
ascdesc: Option[String],
track: Option[String]): Action[AnyContent] = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
val sorter = ProposalUtil.proposalSorter(sort)
val orderer = ProposalUtil.proposalOrder(ascdesc)
val delayedReviews = Review.allProposalIdsHavingDelayedReviewsForUser(uuid)
val (totalToReviewFiltered, allNotReviewed) = Review.allProposalsNotReviewed(uuid, pageReview, 25, track, delayedReviews)
val totalReviewed = Review.totalNumberOfReviewedProposals(uuid)
val totalVoted = Review.totalProposalsVotedForUser(uuid)
val allProposalsForReview = ProposalUtil.sortProposals(allNotReviewed, sorter, orderer)
val twentyEvents = Event.loadEvents(20, page)
val etag = allProposalsForReview.hashCode() + "_" + twentyEvents.hashCode()
val totalToReview = Review.countProposalNotReviewed(uuid)
val totalDelayedReviews = delayedReviews.size
track.map {
trackValue: String =>
Ok(views.html.CFPAdmin.cfpAdminIndex(request.webuser, twentyEvents, allProposalsForReview, Event.totalEvents(), page, sort, ascdesc, Some(trackValue), totalReviewed, totalVoted, totalToReview, totalDelayedReviews, pageReview, totalToReviewFiltered))
.withHeaders("ETag" -> etag)
}.getOrElse {
Ok(views.html.CFPAdmin.cfpAdminIndex(request.webuser, twentyEvents, allProposalsForReview, Event.totalEvents(), page, sort, ascdesc, None, totalReviewed, totalVoted, totalToReview, totalDelayedReviews, pageReview, totalToReviewFiltered))
.withHeaders("ETag" -> etag)
}
}
private def renderShowProposal(userId: String, proposal: Proposal, msgToSpeakerForm: Form[String], msgInternalForm: Form[String], voteForm: Form[Int])(implicit request: SecuredRequest[play.api.mvc.AnyContent]) = {
val speakerDiscussion = Comment.allSpeakerComments(proposal.id)
val internalDiscussion = Comment.allInternalComments(proposal.id)
val maybeMyVote = Review.lastVoteByUserForOneProposal(userId, proposal.id)
val maybeMyPreviousVote = if (maybeMyVote.isEmpty) Review.previouslyResettedVote(userId, proposal.id) else None
val proposalsByAuths = allProposalByProposal(proposal)
val userWatchPref = ProposalUserWatchPreference.proposalUserWatchPreference(proposal.id, userId)
val maybeDelayedReviewReason = Review.proposalDelayedReviewReason(userId, proposal.id)
val proposalLastVisit = Proposal.userProposalLastVisits(userId).get(proposal.id)
views.html.CFPAdmin.showProposal(proposal, proposalsByAuths, speakerDiscussion, internalDiscussion, msgToSpeakerForm, msgInternalForm, voteForm, maybeMyVote, maybeMyPreviousVote, userId, userWatchPref, maybeDelayedReviewReason, proposalLastVisit)
}
def openForReview(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) => Ok(renderShowProposal(uuid, proposal, messageForm, messageForm, voteForm))
case None => NotFound("Proposal not found").as("text/html")
}
}
def allProposalByProposal(proposal: Proposal): Map[String, Map[String, models.Proposal]] = {
val authorIds: List[String] = proposal.mainSpeaker :: proposal.secondarySpeaker.toList ::: proposal.otherSpeakers
authorIds.map {
case id => id -> Proposal.allProposalsByAuthor(id)
}.toMap
}
def showVotesForProposal(proposalId: String) = SecuredAction(IsMemberOf("cfp")).async {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
import scala.concurrent.ExecutionContext.Implicits.global
val uuid = request.webuser.uuid
scala.concurrent.Future {
Proposal.findById(proposalId) match {
case Some(proposal) =>
val currentAverageScore = Review.averageScore(proposalId)
val countVotesCast = Review.totalVoteCastFor(proposalId)
// votes exprimes (sans les votes a zero)
val countVotes = Review.totalVoteFor(proposalId)
val allVotes = Review.allVotesFor(proposalId)
val proposalIdsWithDelayedReview = Review.allProposalIdsHavingDelayedReviewsForUser(uuid)
val currentProposalReviewHasBeenDelayed = proposalIdsWithDelayedReview.contains(proposal.id)
val delayedReviewsCount = proposalIdsWithDelayedReview.size
// The next proposal I should review
val allNotReviewed = Review.allProposalsNotReviewed(uuid).filterNot(p => proposalIdsWithDelayedReview.contains(p.id))
val (sameTrackAndFormats, otherTracksOrFormats) = allNotReviewed.partition(p => p.track.id == proposal.track.id && p.talkType.id == proposal.talkType.id)
val (sameTracks, otherTracks) = allNotReviewed.partition(_.track.id == proposal.track.id)
val (sameTalkType, otherTalksType) = allNotReviewed.partition(_.talkType.id == proposal.talkType.id)
// Note: not appending otherTracksOrFormats here, as we want to show the button in the
// template only if there are some remaining talks to be reviewed for same track & talkType
val nextToBeReviewedSameTrackAndFormat = (sameTrackAndFormats.sortBy(_.track.id)).headOption
val nextToBeReviewedSameTrack = (sameTracks.sortBy(_.talkType.id) ++ otherTracks).headOption
val nextToBeReviewedSameFormat = (sameTalkType.sortBy(_.track.id) ++ otherTalksType).headOption
// The Reviewer leaderboard, remove if the user did not vote for any talks and sort by number of talks reviewed
val bestReviewers: List[ReviewerStats] = Review.allReviewersAndStatsWithOneReviewAtLeast()
// Find the current authenticated user (with uuid), the user that is before, and the one that is after
val listOfReviewers: List[List[(ReviewerStats)]] = bestReviewers
.sliding(3) // This iterate the list 3 by 3
.filter(subList => subList.exists(_.uuid == uuid)) // we are only interested if the element 1 is our uuid.
.toList // else since it's an iterator... we won't be able to apply methods
// So now, listOfReviewers should have 3 elements :
// Element 1 =>
// (mike, 1, 20)
// (bob, 1, 100)
// (nic, 1, 200)
// Element 2 =>
// (bob, 1, 100)
// (nic, 1, 200)
// (theBoss, 1, 300)
// Element 3 =>
// (nic, 1, 200)
// (theBoss, 1, 300)
// (theKing, 1, 500)
// We take the 2 first element (or the only element if we're first or second in the list of reviewers order by nb of reviews)
// Because this list might be empty we use headOption
val maybeTwoFirstTuples = listOfReviewers.take(2)
val meAndMyFollowers: Option[List[(ReviewerStats)]] = maybeTwoFirstTuples.size match {
case 1 => maybeTwoFirstTuples.headOption
case _ => maybeTwoFirstTuples.drop(1).headOption
}
// If Golden Ticket is active
val averageScoreGT = if (ConferenceDescriptor.isGoldenTicketActive) ReviewByGoldenTicket.averageScore(proposalId) else 0
val countVotesCastGT: Option[Long] = if (ConferenceDescriptor.isGoldenTicketActive) Option(ReviewByGoldenTicket.totalVoteCastFor(proposalId)) else None
Ok(views.html.CFPAdmin.showVotesForProposal(uuid, proposal, currentAverageScore, countVotesCast, countVotes, allVotes, nextToBeReviewedSameTrackAndFormat, nextToBeReviewedSameTrack, nextToBeReviewedSameFormat, currentProposalReviewHasBeenDelayed, delayedReviewsCount, averageScoreGT, countVotesCastGT, meAndMyFollowers))
case None => NotFound("Proposal not found").as("text/html")
}
}
}
def sendMessageToSpeaker(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
messageForm.bindFromRequest.fold(
hasErrors => BadRequest(renderShowProposal(uuid, proposal, hasErrors, messageForm, voteForm)),
validMsg => {
Comment.saveCommentForSpeaker(proposal.id, uuid, validMsg) // Save here so that it appears immediatly
Proposal.markVisited(uuid, proposalId)
ZapActor.actor ! SendMessageToSpeaker(uuid, proposal, validMsg)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> "Message sent to speaker.")
}
)
case None => NotFound("Proposal not found").as("text/html")
}
}
// Post an internal message that is visible only for program committe
def postInternalMessage(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
messageForm.bindFromRequest.fold(
hasErrors => BadRequest(renderShowProposal(uuid, proposal, messageForm, hasErrors, voteForm)),
validMsg => {
Comment.saveInternalComment(proposal.id, uuid, validMsg) // Save here so that it appears immediatly
Proposal.markVisited(uuid, proposalId)
ZapActor.actor ! SendMessageInternal(uuid, proposal, validMsg)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> "Message sent to program committee.")
}
)
case None => NotFound("Proposal not found").as("text/html")
}
}
def watchProposal(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId).map {
proposal: Proposal =>
Watcher.addProposalWatcher(proposal.id, uuid, false)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> "Started watching proposal")
}.getOrElse(NotFound("Proposal not found"))
}
def delayReview(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
delayedReviewForm.bindFromRequest.fold(
hasErrors => BadRequest(renderShowProposal(uuid, proposal, hasErrors, messageForm, voteForm)),
validMsg => {
Review.markProposalReviewAsDelayed(uuid, proposal.id, validMsg)
Redirect(routes.CFPAdmin.showVotesForProposal(proposalId)).flashing("vote" -> "OK, review delayed for this proposal")
}
)
case None => NotFound("Proposal not found")
}
}
def removeProposalDelayedReview(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
Review.removeProposalDelayedReview(uuid, proposalId)
Redirect(routes.CFPAdmin.delayedReviews()).flashing("success" -> "OK, delayed review removed")
case None => NotFound("Proposal not found")
}
}
def unwatchProposal(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId).map {
proposal: Proposal =>
Watcher.removeProposalWatcher(proposal.id, uuid)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> "Started unwatching proposal")
}.getOrElse(NotFound("Proposal not found"))
}
def voteForProposal(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
voteForm.bindFromRequest.fold(
hasErrors => BadRequest(renderShowProposal(uuid, proposal, messageForm, messageForm, hasErrors)),
validVote => {
Review.voteForProposal(proposalId, uuid, validVote)
Proposal.markVisited(uuid, proposalId)
Redirect(routes.CFPAdmin.showVotesForProposal(proposalId)).flashing("vote" -> "Ok, vote submitted")
}
)
case None => NotFound("Proposal not found").as("text/html")
}
}
def clearVoteForProposal(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.findById(proposalId) match {
case Some(proposal) =>
Review.removeVoteForProposal(proposalId, uuid)
Redirect(routes.CFPAdmin.showVotesForProposal(proposalId)).flashing("vote" -> "Removed your vote")
case None => NotFound("Proposal not found").as("text/html")
}
}
def allMyWatchedProposals(talkType: String, selectedTrack: Option[String], onlyProposalHavingEvents: Boolean) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposalIdsByProposalType = Proposal.allProposalIDsByProposalType()
(proposalIdsByProposalType.get(talkType), ConferenceDescriptor.ConferenceProposalTypes.ALL.find(_.id == talkType)) match {
case (Some(proposalIDsForType), Some(proposalType)) =>
val uuid = request.webuser.uuid
val proposalIdsByTrackForCurrentProposalType = Proposal.allProposalIdsByTrackForType(proposalType)
val watcherEventsByProposalId = Event.loadProposalsWatcherEvents(uuid)
val displayedEventMessagesByProposalId = watcherEventsByProposalId
.mapValues(ProposalEvent.generateAggregatedEventLabelsFor(_))
.filter { entry => entry._2.nonEmpty }
val watchedProposals = Watcher.userWatchedProposals(uuid)
.filter(watcher => !onlyProposalHavingEvents || displayedEventMessagesByProposalId.contains(watcher.proposalId))
.sortBy(-_.startedWatchingAt.getMillis)
val watchedProposalIds = watchedProposals.map(_.proposalId).toSet
val proposalLastVisits = Proposal.userProposalLastVisits(uuid)
val watchedProposalMatchingTypeAndTrack = watchedProposals
.filter(watcher => proposalIDsForType.contains(watcher.proposalId)
&& selectedTrack.map { track => proposalIdsByTrackForCurrentProposalType.get(track).map(_.contains(watcher.proposalId)).getOrElse(false) }.getOrElse(true)
).sortBy(watcher => -proposalLastVisits.get(watcher.proposalId).getOrElse(watcher.startedWatchingAt.toDateTime).getMillis)
val proposalsById = Proposal.loadAndParseProposals(watchedProposalMatchingTypeAndTrack.map(_.proposalId).toSet, proposalType)
val watchedProposalsCountsByProposalType = proposalIdsByProposalType.mapValues { proposalIdsForType =>
proposalIdsForType.intersect(watchedProposalIds).size
}
val watchedProposalsCountByTrackForCurrentProposalType = proposalIdsByTrackForCurrentProposalType.mapValues { proposalIdsForTrack =>
proposalIdsForTrack.intersect(watchedProposalIds).size
}
val allMyVotesIncludingAbstentions = Review.allVotesFromUserForProposalsRegardlessProposalStatus(uuid, watchedProposalIds)
.filter { entry => entry._2.nonEmpty }
.mapValues(_.get)
Ok(views.html.CFPAdmin.allMyWatchedProposals(watchedProposalMatchingTypeAndTrack, proposalsById, talkType, selectedTrack, onlyProposalHavingEvents, watchedProposalsCountsByProposalType, watchedProposalsCountByTrackForCurrentProposalType, allMyVotesIncludingAbstentions, displayedEventMessagesByProposalId, proposalLastVisits))
case _ => BadRequest("Invalid proposal type")
}
}
def markProposalAsVisited(proposalId: String) = SecuredAction(IsMemberOf("cfp")) { implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val deletedEventsCount = Proposal.markVisited(request.webuser.uuid, proposalId)
Ok(s"Deleted ${deletedEventsCount} events")
}
def allMyVotes(talkType: String, selectedTrack: Option[String]) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
ConferenceDescriptor.ConferenceProposalTypes.ALL.find(_.id == talkType).map {
pType =>
val uuid = request.webuser.uuid
val allMyVotesIncludingAbstentions = Review.allVotesFromUser(uuid)
val allProposalIDsWhereIVoted = allMyVotesIncludingAbstentions.map(_._1)
val allProposalsMatchingCriteriaWhereIVoted = Proposal.loadAndParseProposals(allProposalIDsWhereIVoted)
.filter(p => p._2.talkType == pType && selectedTrack.map(p._2.track.id == _).getOrElse(true))
val allProposalsIdsMatchingCriteriaWhereIVoted = allProposalsMatchingCriteriaWhereIVoted.keySet
val allMyVotesIncludingAbstentionsMatchingCriteria = allMyVotesIncludingAbstentions.filter {
proposalIdAndVotes => allProposalsIdsMatchingCriteriaWhereIVoted.contains(proposalIdAndVotes._1)
}
val sortedAllMyVotesIncludingAbstentionsMatchingCriteria = allMyVotesIncludingAbstentionsMatchingCriteria.toList.sortBy(_._2).reverse
val sortedAllMyVotesExcludingAbstentionsMatchingCriteria = sortedAllMyVotesIncludingAbstentionsMatchingCriteria.filter(_._2 != 0)
val allScoresForProposals: Map[String, Double] = allProposalsIdsMatchingCriteriaWhereIVoted.map {
pid: String => (pid, Review.averageScore(pid))
}.toMap
val proposalsNotReviewedByType = Review.allProposalsNotReviewed(uuid).groupBy(_.talkType.id)
val proposalNotReviewedCountByType = proposalsNotReviewedByType.mapValues(_.size)
val proposalsNotReviewedForCurrentType = proposalsNotReviewedByType.get(pType.id).getOrElse(List())
val proposalNotReviewedCountForCurrentTypeByTrack = proposalsNotReviewedForCurrentType.groupBy(_.track.id).mapValues(_.size)
val proposalsMatchingCriteriaNotReviewed = proposalsNotReviewedForCurrentType.filter(p => selectedTrack.map(p.track.id == _).getOrElse(true))
val firstProposalNotReviewedAndMatchingCriteria = proposalsMatchingCriteriaNotReviewed.headOption
val delayedReviewsCount = Review.countDelayedReviews(uuid)
Ok(views.html.CFPAdmin.allMyVotes(sortedAllMyVotesIncludingAbstentionsMatchingCriteria, sortedAllMyVotesExcludingAbstentionsMatchingCriteria, allProposalsMatchingCriteriaWhereIVoted, talkType, selectedTrack, allScoresForProposals, proposalNotReviewedCountByType, proposalNotReviewedCountForCurrentTypeByTrack, firstProposalNotReviewedAndMatchingCriteria, delayedReviewsCount))
}.getOrElse {
BadRequest("Invalid proposal type")
}
}
def delayedReviews() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
val delayedReviewReasonByProposalId = Review.delayedReviewsReasons(uuid)
val delayedProposals = Proposal.loadAndParseProposals(delayedReviewReasonByProposalId.keySet)
.values.toList
.sortBy(p => s"${p.talkType}__${p.track}")
Ok(views.html.CFPAdmin.delayedReviews(delayedProposals, delayedReviewReasonByProposalId))
}
def advancedSearch(q: Option[String] = None, p: Option[Int] = None) = SecuredAction(IsMemberOf("cfp")).async {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
import play.api.libs.concurrent.Execution.Implicits.defaultContext
ElasticSearch.doAdvancedSearch(ElasticSearch.indexNames, q, p).map {
case r if r.isRight =>
val searchResponse: SearchResponse = r.right.get
val total: Long = searchResponse.totalHits
val hitContents: Array[SearchHit] = searchResponse.hits.hits
val results = hitContents.map {
searchHit =>
val index = searchHit.index
val source = searchHit.sourceAsMap
index match {
case "proposals" =>
val id: String = source("id").toString
val title: String = source("title").toString
val talkType = Messages(source("talkType").toString)
val propState = source("state").toString
val mainSpeaker: String = source("mainSpeaker").toString
s"<p class='searchProposalResult'><i class='fas fa-folder-open'></i> Proposal $id <a href='${routes.CFPAdmin.openForReview(id)}'>$title</a> <strong>$talkType</strong> - [$propState] - by $mainSpeaker</p>"
case "speakers" =>
val uuid: String = source("uuid").toString
val name: String = source("name").toString
val firstName: String = source("firstName").toString
val company = source.get("company").filterNot(_ == null).map(s => s.toString).getOrElse("")
s"<p class='searchSpeakerResult'><i class='fas fa-user'></i> Speaker <a href='${routes.CFPAdmin.showSpeakerAndTalks(uuid)}'>$firstName $name</a> <strong>$company</strong></p>"
case _ => "Unknown format " + index
}
}
Ok(views.html.CFPAdmin.renderSearchResult(total, results, q, p)).as("text/html")
case r if r.isLeft =>
InternalServerError("Search engine error, check the console")
}
}
def allSponsorTalks = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposals = Proposal.allSponsorsTalk()
Ok(views.html.CFPAdmin.allSponsorTalks(proposals))
}
def showSpeakerAndTalks(uuidSpeaker: String) = SecuredAction {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Speaker.findByUUID(uuidSpeaker) match {
case Some(speaker) =>
val proposals = Proposal.allProposalsByAuthor(speaker.uuid)
Ok(views.html.CFPAdmin.showSpeakerAndTalks(speaker, proposals, request.webuser.uuid))
case None => NotFound("Speaker not found")
}
}
def allVotes(confType: String, track: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
play.Logger.of("application.Benchmark").debug(s"******* CFPAdmin allVotes for $confType and $track")
val reviews: Map[String, (Score, TotalVoter, TotalAbst, AverageNote, StandardDev)] = Benchmark.measure(
() => Review.allVotes(), "gathering all votes"
)
val allMyVotes = Benchmark.measure(() => Review.allPrecomputedVotesFromUser(request.webuser.uuid), "gathering current user's votes")
val totalApproved = Benchmark.measure(
() => ApprovedProposal.countApproved(confType), "count approved talks"
)
val allProposals = Benchmark.measure(() => Proposal.loadAndParseProposals(reviews.keySet), "load and parse proposals")
val listOfProposals = Benchmark.measure(() => reviews.flatMap {
case (proposalId, scoreAndVotes) =>
val maybeProposal = allProposals.get(proposalId)
maybeProposal match {
case None => play.Logger.of("CFPAdmin").error(s"Unable to load proposal id $proposalId")
None
case Some(p) =>
val goldenTicketScore: Double = ReviewByGoldenTicket.averageScore(p.id)
val gtVoteCast: Long = ReviewByGoldenTicket.totalVoteCastFor(p.id)
val gtAndComiteeScore = library.Stats.average(
List(
if (gtVoteCast > 0) {
goldenTicketScore
} else {
scoreAndVotes._4.n
},
scoreAndVotes._4.n
)
)
Option(p, scoreAndVotes, goldenTicketScore, gtVoteCast, gtAndComiteeScore, allMyVotes.get(p.id))
}
}, "create list of Proposals")
val tempListToDisplay = Benchmark.measure(() => confType match {
case "all" => listOfProposals
case filterType => listOfProposals.filter(_._1.talkType.id == filterType)
}, "list to display")
val listToDisplay = Benchmark.measure(() => track match {
case "all" => tempListToDisplay
case trackId => tempListToDisplay.filter(_._1.track.id == trackId)
}, "filter by track")
val totalRemaining = Benchmark.measure(() => ApprovedProposal.remainingSlots(confType), "calculate remaining slots")
Ok(views.html.CFPAdmin.allVotes(listToDisplay.toList, totalApproved, totalRemaining, confType, track))
}
def allVotesVersion2(confType: String, page: Int = 0, resultats: Int = 25, sortBy: String = "gt_and_cfp") = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
play.Logger.of("application.Benchmark").debug(s"******* CFPAdmin Version 2 for $confType")
val reviews: Map[String, (Score, TotalVoter, TotalAbst, AverageNote, StandardDev)] = Benchmark.measure(() => Review.allVotes(), "v2 - All votes")
val allProposals = Benchmark.measure(() => {
Proposal.loadAndParseProposals(reviews.keySet, ProposalType.parse(confType))
}, "v2 - Load and parse proposals for " + ProposalType.parse(confType))
val listOfProposals =
Benchmark.measure(() => reviews.flatMap {
case (proposalId, scoreAndVotes) =>
val maybeProposal = allProposals.get(proposalId)
maybeProposal match {
case Some(p) =>
val (gtVoteCast, goldenTicketScore) = ReviewByGoldenTicket.totalVotesAndAverageScoreFor(p.id)
Option(p, scoreAndVotes, goldenTicketScore, gtVoteCast)
case None => // We ignore here cause Review loaded all Proposals.
None
}
}, "v2 - Create list of Proposals")
val totalApproved = ApprovedProposal.countApproved(confType)
val totalRemaining = ApprovedProposal.remainingSlots(confType)
val toSlide = listOfProposals.toList.sortBy {
case (_, voteAndTotalVotes, gtScore, _) if sortBy == "gt_and_cfp" => library.Stats.average(List(gtScore, voteAndTotalVotes._4.n))
case (_, voteAndTotalVotes, _, _) => voteAndTotalVotes._4.n
}.reverse
val sliced = toSlide.slice(page * resultats, (page + 1) * resultats)
Ok(views.html.CFPAdmin.allVotesVersion2(sliced, totalApproved, totalRemaining, confType, page, resultats, sortBy))
}
def removeSponsorTalkFlag(proposalId: String) = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
Proposal.removeSponsorTalkFlag(uuid, proposalId)
Redirect(routes.CFPAdmin.allSponsorTalks()).flashing("success" -> s"Removed sponsor talk on $proposalId")
}
def allProposalsByTrack(track: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposals = Proposal.allSubmitted().filter(_.track.id == track)
Ok(views.html.CFPAdmin.allProposalsByTrack(proposals, track))
}
def allProposalsByType(confType: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposals = Proposal.allSubmitted().filter(_.talkType.id == confType)
Ok(views.html.CFPAdmin.allProposalsByType(proposals, confType))
}
def showProposalsNotReviewedCompareTo(maybeReviewer: Option[String]) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val uuid = request.webuser.uuid
maybeReviewer match {
case None =>
Ok(views.html.CFPAdmin.selectAnotherWebuser(Webuser.allCFPWebusers()))
case Some(otherReviewer) =>
val diffProposalIDs = Review.diffReviewBetween(otherReviewer, uuid)
Ok(views.html.CFPAdmin.showProposalsNotReviewedCompareTo(diffProposalIDs, otherReviewer))
}
}
// Returns all speakers - using AlfIO format
def allSpeakersExport() = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val allSpeakers = ApprovedProposal.allApprovedSpeakers()
val speakersAndProposals: Set[(Speaker, Map[String, Proposal])] = allSpeakers.map(s => (s, Proposal
.allNonArchivedProposalsByAuthor(s.uuid)
.filterNot(t => t._2.state == ProposalState.REJECTED || t._2.state == ProposalState.DECLINED || t._2.state == ProposalState.CANCELLED || t._2.state == ProposalState.DELETED)
)
).filterNot(s => s._2.isEmpty)
val dir = new File("./public/speakers")
FileUtils.forceMkdir(dir)
val conferenceNameSpaces = Messages("CONF.title").replaceAll(" ", "")
val file = new File(dir, s"speakers_${conferenceNameSpaces}.csv")
val writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), true)
writer.println("firstName,lastName,email,lang,reference,company,jobTitle")
speakersAndProposals.foreach {
case (s, proposals) =>
writer.print(s.cleanFirstName)
writer.print(",")
writer.print(s.cleanLastName(removeAccents = false))
writer.print(",")
writer.print(s.email.trim)
writer.print(",")
writer.print(s.lang.getOrElse("en"))
writer.print(",")
writer.print(s.uuid)
writer.print(",")
writer.print(s.company.map(_.replaceAll(",", " ")).getOrElse(""))
writer.print(",")
writer.print("speaker")
writer.println()
}
writer.close()
Ok.sendFile(file, inline = false)
}
def allSpeakers() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Ok(views.html.CFPAdmin.allSpeakersHome())
}
def duplicateSpeakers() = SecuredAction(IsMemberOf("cfp")) {
var uniqueSpeakers = scala.collection.mutable.Set[Speaker]()
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val allApprovedSpeakers = ApprovedProposal.allApprovedSpeakers()
val allRefusedSpeakers = ApprovedProposal.allRefusedSpeakers()
val allSpeakers = allApprovedSpeakers ++ allRefusedSpeakers
val speakersSortedByUUID = allSpeakers.toList
.sortBy(_.uuid)
.groupBy(_.uuid)
.filter(_._2.size == 1)
.flatMap { uuid => uuid._2 }
val uniqueSpeakersSortedByName = speakersSortedByUUID.toList
.sortBy(_.cleanName)
.groupBy(_.cleanName)
.filter(_._2.size != 1)
.flatMap { name => name._2 }
val speakersSortedByEmail = allSpeakers.toList
.sortBy(_.email)
.groupBy(_.email)
.filter(_._2.size != 1)
.flatMap { email => email._2 }
val uniqueSpeakersSortedByEmail = speakersSortedByEmail.toList
.sortBy(_.email)
.groupBy(_.email)
.filter(_._2.size != 1)
.flatMap { email => email._2 }
val combinedList = uniqueSpeakersSortedByName.toList ++ uniqueSpeakersSortedByEmail.toList
Ok(views.html.CFPAdmin.duplicateSpeakers(combinedList))
}
def allDevoxxians() = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val devoxxians = Webuser.allDevoxxians().sortBy(_.email)
Ok(views.html.Backoffice.allDevoxxians(devoxxians))
}
def invalidDevoxxians() = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val devoxxians = Webuser.allDevoxxians().sortBy(_.email)
val duplicateEmails = devoxxians.groupBy(_.email).filter(_._2.size > 1)
val removeNoEmails = duplicateEmails.filterNot(s => s._1 == "no_email_defined")
Ok(views.html.Backoffice.invalidDevoxxians(removeNoEmails.values.flatten.toList))
}
def allSpeakersWithApprovedTalks(filterDeclinedRejected: Boolean) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val allSpeakers = ApprovedProposal.allApprovedSpeakers()
val speakersAndProposals: Set[(Speaker, Map[String, Proposal])] = if (filterDeclinedRejected) {
allSpeakers.map(s => (s, Proposal
.allNonArchivedProposalsByAuthor(s.uuid)
.filterNot(t => t._2.state == ProposalState.REJECTED || t._2.state == ProposalState.DECLINED || t._2.state == ProposalState.CANCELLED || t._2.state == ProposalState.DELETED)
)
).filterNot(s => s._2.isEmpty)
} else {
allSpeakers.map(s => (s, Proposal.allNonArchivedProposalsByAuthor(s.uuid)))
}
val allProposalIDs: Set[Proposal] = speakersAndProposals.flatMap(_._2.values.toSet)
val approvedProposalIDs: Set[String] = ApprovedProposal.filterApproved(allProposalIDs.map(_.id))
Ok(views.html.CFPAdmin.allSpeakers(speakersAndProposals, filterDeclinedRejected, approvedProposalIDs))
}
def allApprovedSpeakersByCompany(showQuickiesAndBof: Boolean) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val speakers = ApprovedProposal.allApprovedSpeakers()
.groupBy(_.company.map(_.toLowerCase.trim).getOrElse("Pas de société"))
.toList
.sortBy(_._2.size)
.reverse
val proposals = speakers.map {
case (company, subSpeakers) =>
val setOfProposals = subSpeakers.toList.flatMap {
s =>
Proposal.allApprovedProposalsByAuthor(s.uuid).values
}.toSet.filterNot { p: Proposal =>
if (showQuickiesAndBof) {
p == null
} else {
p.talkType == ConferenceDescriptor.ConferenceProposalTypes.BOF ||
p.talkType == ConferenceDescriptor.ConferenceProposalTypes.QUICK
}
}
(company, setOfProposals)
}
Ok(views.html.CFPAdmin.allApprovedSpeakersByCompany(speakers, proposals))
}
// All speakers that accepted to present a talk (including BOF and Quickies)
def allSpeakersThatForgetToAccept() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val speakers = ApprovedProposal.allApprovedSpeakers()
val proposals: Set[(Speaker, Iterable[Proposal])] = speakers.map {
speaker =>
(speaker, Proposal.allThatForgetToAccept(speaker.uuid).values)
}.filter(_._2.nonEmpty)
Ok(views.html.CFPAdmin.allSpeakersThatForgetToAccept(proposals))
}
// All speakers with a speaker's badge (it does not include Quickies, BOF and 3rd, 4th speakers)
def allSpeakersWithAcceptedTalksAndBadge() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val speakers = ApprovedProposal.allApprovedSpeakers()
val proposals: List[(Speaker, Iterable[Proposal])] = speakers.toList.map {
speaker =>
val allProposalsForThisSpeaker = Proposal.allApprovedAndAcceptedProposalsByAuthor(speaker.uuid).values
val onIfFirstOrSecondSpeaker = allProposalsForThisSpeaker.filter(p => p.mainSpeaker == speaker.uuid || p.secondarySpeaker.contains(speaker.uuid))
.filter(p => ConferenceDescriptor.ConferenceProposalConfigurations.doesItGivesSpeakerFreeEntrance(p.talkType))
(speaker, onIfFirstOrSecondSpeaker)
}.filter(_._2.nonEmpty).map {
case (speaker, zeProposals) =>
val updated = zeProposals.filter {
proposal =>
Proposal.findProposalState(proposal.id).contains(ProposalState.ACCEPTED)
}
if (updated.size != zeProposals.size) {
play.Logger.debug(s"Removed rejected proposal for speaker ${speaker.cleanName}")
}
(speaker, updated)
}.filter(_._2.nonEmpty)
Ok(views.html.CFPAdmin.allSpeakersWithAcceptedTalksAndBadge(proposals))
}
// All speakers without a speaker's badge
def allSpeakersWithAcceptedTalksAndNoBadge() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposals = ApprovedProposal.allSpeakersWithAcceptedTalksAndNoBadge()
Ok(views.html.CFPAdmin.allSpeakersWithAcceptedTalksAndNoBadge(proposals))
}
// All speakers with a speaker's badge
def allSpeakersWithAcceptedTalks() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val speakers = ApprovedProposal.allApprovedSpeakers()
val proposals: List[(Speaker, Iterable[Proposal])] = speakers.toList.map {
speaker =>
val allProposalsForThisSpeaker = Proposal.allApprovedAndAcceptedProposalsByAuthor(speaker.uuid).values
val onIfFirstOrSecondSpeaker = allProposalsForThisSpeaker.filter(p => p.mainSpeaker == speaker.uuid || p.secondarySpeaker == Some(speaker.uuid))
(speaker, onIfFirstOrSecondSpeaker)
}.filter(_._2.nonEmpty)
Ok(views.html.CFPAdmin.allSpeakersWithAcceptedTalksAndBadge(proposals))
}
def allSpeakersWithRejectedTalks() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val refusedSpeakers = ApprovedProposal.allRefusedSpeakerIDs()
val approvedSpeakers = ApprovedProposal.allApprovedSpeakerIDs()
val diffRejectedSpeakers: Set[String] = refusedSpeakers.diff(approvedSpeakers)
val proposals: List[(Speaker, Iterable[Proposal])] = diffRejectedSpeakers.toList.map {
speakerId =>
val allProposalsForThisSpeaker = Proposal.allRejectedForSpeaker(speakerId)
val onIfFirstOrSecondSpeaker = allProposalsForThisSpeaker.filter(p => p.mainSpeaker == speakerId || p.secondarySpeaker == Some(speakerId))
(Speaker.findByUUID(speakerId).get, onIfFirstOrSecondSpeaker)
}.filter(_._2.nonEmpty)
Ok(views.html.CFPAdmin.allSpeakersWithRejectedProposals(proposals))
}
def allSpeakersWithAcceptedTalksForExport() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val speakers = ApprovedProposal.allApprovedSpeakers()
val proposals: List[(Speaker, Iterable[Proposal])] = speakers.toList.map {
speaker =>
val allProposalsForThisSpeaker = Proposal.allApprovedAndAcceptedProposalsByAuthor(speaker.uuid).values
val onIfFirstOrSecondSpeaker = allProposalsForThisSpeaker.filter(p => p.mainSpeaker == speaker.uuid || p.secondarySpeaker == Some(speaker.uuid))
(speaker, onIfFirstOrSecondSpeaker)
}.filter(_._2.nonEmpty)
Ok(views.html.CFPAdmin.allSpeakersWithAcceptedTalksForExport(proposals))
}
def allWebusers() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val allSpeakers = Webuser.allSpeakers.sortBy(_.cleanName)
Ok(views.html.CFPAdmin.allWebusers(allSpeakers))
}
def allCFPWebusers() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Ok(views.html.CFPAdmin.showCFPUsers(Webuser.allCFPWebusers()))
}
def updateTrackLeaders() = SecuredAction(IsMemberOf("cfp")) {
implicit req: SecuredRequest[play.api.mvc.AnyContent] =>
req.request.body.asFormUrlEncoded.map {
mapsByTrack =>
TrackLeader.updateAllTracks(mapsByTrack)
Redirect(routes.CFPAdmin.allCFPWebusers()).flashing("success" -> "List of track leaders updated")
}.getOrElse {
Redirect(routes.CFPAdmin.allCFPWebusers()).flashing("error" -> "No value received")
}
}
def switchPublicVisibility(uuid: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Webuser.updatePublicVisibility(uuid)
Redirect(routes.CFPAdmin.allCFPWebusers()).flashing("success" -> s"Updated user $uuid")
}
def newOrEditSpeaker(speakerUUID: Option[String]) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
speakerUUID match {
case Some(uuid) =>
Speaker.findByUUID(uuid).map {
speaker: Speaker =>
Ok(views.html.CFPAdmin.newSpeaker(speakerForm.fill(speaker))).flashing("success" -> "You are currently editing an existing speaker")
}.getOrElse {
Ok(views.html.CFPAdmin.newSpeaker(speakerForm)).flashing("error" -> "Speaker not found")
}
case None => Ok(views.html.CFPAdmin.newSpeaker(speakerForm))
}
}
def saveNewSpeaker() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
speakerForm.bindFromRequest.fold(
invalidForm => BadRequest(views.html.CFPAdmin.newSpeaker(invalidForm)).flashing("error" -> "Invalid form, please check and correct errors. "),
validSpeaker => {
Option(validSpeaker.uuid) match {
case Some(existingUUID) =>
play.Logger.of("application.CFPAdmin").debug("Updating existing speaker " + existingUUID)
Webuser.findByUUID(existingUUID).map {
existingWebuser =>
Webuser.updateNames(existingUUID, validSpeaker.firstName.getOrElse("?"), validSpeaker.name.getOrElse("?"))
}.getOrElse {
val newWebuser = Webuser.createSpeaker(validSpeaker.email, validSpeaker.firstName.getOrElse("?"), validSpeaker.name.getOrElse("?"))
val newUUID = Webuser.saveAndValidateWebuser(newWebuser)
play.Logger.warn("Created missing webuser " + newUUID)
}
Speaker.save(validSpeaker)
Event.storeEvent(NewSpeakerEvent(request.webuser.uuid, validSpeaker.uuid, validSpeaker.cleanName))
Redirect(routes.CFPAdmin.showSpeakerAndTalks(existingUUID)).flashing("success" -> "Profile updated")
case None =>
val webuser = Webuser.createSpeaker(validSpeaker.email, validSpeaker.firstName.getOrElse("Firstname"), validSpeaker.name.getOrElse("Lastname"))
Webuser.saveNewWebuserEmailNotValidated(webuser)
val newUUID = Webuser.saveAndValidateWebuser(webuser)
Speaker.save(validSpeaker.copy(uuid = newUUID))
Event.storeEvent(UpdatedSpeakerEvent(request.webuser.uuid, validSpeaker.uuid, validSpeaker.cleanName))
Redirect(routes.CFPAdmin.showSpeakerAndTalks(newUUID)).flashing("success" -> "Profile saved")
}
}
)
}
def setPreferredDay(proposalId: String, day: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Proposal.setPreferredDay(proposalId: String, day: String)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> ("Preferred day set to " + day))
}
def resetPreferredDay(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Proposal.resetPreferredDay(proposalId: String)
Redirect(routes.CFPAdmin.openForReview(proposalId)).flashing("success" -> "No preferences")
}
def showProposalsWithNoVotes() = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val proposals = Review.allProposalsWithNoVotes
Ok(views.html.CFPAdmin.showProposalsWithNoVotes(proposals))
}
def showProposalsByTagId(tagId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
val tag = Tag.findById(tagId)
if (tag.isDefined) {
val proposals = Tags.allProposalsByTagId(tagId)
Ok(views.html.CFPAdmin.showProposalsByTag(tag.get, proposals))
} else {
BadRequest("Invalid tag")
}
}
def history(proposalId: String) = SecuredAction(IsMemberOf("cfp")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Proposal.findById(proposalId).map {
proposal: Proposal =>
Ok(views.html.CFPAdmin.history(proposal))
}.getOrElse(NotFound("Proposal not found"))
}
}