forked from opf/openproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail_handler_spec.rb
More file actions
1585 lines (1286 loc) · 50.1 KB
/
Copy pathmail_handler_spec.rb
File metadata and controls
1585 lines (1286 loc) · 50.1 KB
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
require "spec_helper"
RSpec.describe IncomingEmails::MailHandler do # rubocop:disable RSpec/SpecFilePathFormat
# we need these run first so the anonymous and system users are created and
# there is a default work package priority to save any work packages
shared_let(:anno_user) { User.anonymous }
shared_let(:system_user) { User.system }
shared_let(:priority_low) { create(:priority_low, name: "Low", is_default: true) }
shared_let(:project) { create(:valid_project, identifier: "onlinestore", name: "OnlineStore", public: false) }
before do
allow(UserMailer)
.to receive(:incoming_email_error)
.and_return instance_double(ActionMailer::MessageDelivery, deliver_later: nil)
end
after do
User.current = nil
allow(Setting).to receive(:default_language).and_return("en")
end
shared_context "for wp_on_given_project" do
let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_on_given_project.eml", **submit_options)
end
end
shared_context "for wp_on_given_project_case_insensitive" do
let(:permissions) { %i[add_work_packages assign_versions] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let(:submit_options) { { allow_override: "version" } }
subject do
submit_email("wp_on_given_project_case_insensitive.eml", **submit_options)
end
end
shared_context "for wp on given project group assignment" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:group) do
create(:group,
lastname: "A-Team",
member_with_permissions: { project => [:work_package_assigned] })
end
let(:submit_options) { {} }
subject do
submit_email("wp_on_given_project_group_assignment.eml", **submit_options)
end
end
shared_context "with a reply to a wp mention with quotes above" do
let(:permissions) { %i[edit_work_packages view_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
member_with_permissions: { project => permissions })
end
let!(:work_package) do
create(:work_package,
id: 2,
project:) do |wp|
wp.journals.last.update_column(:id, 891223)
end
end
subject do
submit_email("wp_reply_with_quoted_reply_above.eml")
end
end
shared_context "with wp create with cc" do
let(:permissions) { %i[add_work_packages view_work_packages add_work_package_watchers] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:cc_user) do
create(:user,
mail: "dlopper@somenet.foo",
firstname: "D",
lastname: "Lopper",
member_with_permissions: { project => permissions })
end
let(:submit_options) { { issue: { project: project.identifier } } }
subject do
submit_email("ticket_with_cc.eml", **submit_options)
end
end
shared_context "with a reply to a wp mention" do
let(:permissions) { %i[add_work_package_comments view_work_packages] }
let!(:user) do
create(:user,
mail: "j.doe@openproject.org",
member_with_permissions: { project => permissions })
end
let!(:work_package) do
create(:work_package,
subject: "Some subject of the bug",
id: 39733,
project:) do |wp|
wp.journals.last.update_column(:id, 99999999)
end
end
subject do
submit_email("wp_mention_reply.eml")
end
end
shared_context "with a reply to a wp mention with attributes" do
let(:permissions) { %i[add_work_package_comments view_work_packages edit_work_packages work_package_assigned] }
let(:role) do
create(:project_role, permissions:)
end
let!(:user) do
create(:user,
mail: "j.doe@openproject.org",
member_with_roles: { project => role })
end
let!(:work_package) do
create(:work_package,
subject: "Some subject of the bug",
id: 39733,
project:,
status: original_status) do |wp|
wp.journals.last.update_column(:id, 99999999)
end
end
let!(:original_status) do
create(:default_status)
end
let!(:resolved_status) do
create(:status,
name: "Resolved") do |status|
create(:workflow,
old_status: original_status,
new_status: status,
role:,
type: work_package.type)
end
end
let!(:other_user) do
create(:user,
mail: "jsmith@somenet.foo",
member_with_roles: { project => [role] })
end
let!(:float_cf) do
create(:float_wp_custom_field,
name: "float field") do |cf|
project.work_package_custom_fields << cf
work_package.type.custom_fields << cf
end
end
subject do
submit_email("wp_mention_reply_with_attributes.eml")
end
end
shared_context "with a reply to a message" do
let(:permissions) { %i[view_messages add_messages] }
let!(:user) do
create(:user,
mail: "j.doe@openproject.org",
member_with_permissions: { project => permissions })
end
let!(:message) do
create(:message,
id: 70917,
forum: create(:forum, project:)) do |wp|
wp.journals.last.update_column(:id, 99999999)
end
end
subject do
submit_email("message_reply.eml")
end
end
shared_context "with a new work package with attributes" do
let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:feature_type) do
create(:type,
name: "Feature request") do |type|
project.types << type
end
end
let!(:stock_category) do
project.categories.create(name: "Stock management")
end
let!(:urgent_priority) do
create(:priority_urgent)
end
let!(:high_priority) do
create(:priority_high)
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_attributes.eml", **submit_options)
end
end
shared_context "with a new work package with attributes with additional spaces" do
let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] }
let(:role) do
create(:project_role, permissions:)
end
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:feature_type) do
create(:type,
name: "Feature request") do |type|
project.types << type
end
end
let!(:stock_category) do
project.categories.create(name: "Stock management")
end
let!(:urgent_priority) do
create(:priority_urgent)
end
let!(:high_priority) do
create(:priority_high)
end
let!(:version) { create(:version, name: "alpha", project:) }
let!(:original_status) do
create(:default_status)
end
let!(:resolved_status) do
create(:status,
name: "Resolved") do |status|
create(:workflow,
old_status: original_status,
new_status: status,
role:,
type: feature_type)
end
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_spaces_between_attribute_and_separator.eml", **submit_options)
end
end
shared_context "with a new work package with attributes in japanese" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:japanese_type) do
create(:type,
name: "開発") do |type|
project.types << type
end
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_attributes_japanese.eml", **submit_options)
end
end
shared_context "with a new work package with attachment" do
# The work package is created first and only then the attachment is added.
let(:permissions) { %i[add_work_packages add_work_package_attachments] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_attachment.eml", **submit_options)
end
end
shared_context "with a new work package with attachment in apple format" do
# The work package is created first and only then the attachment is added.
let(:permissions) { %i[add_work_packages add_work_package_attachments] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_attachment_apple.eml", **submit_options)
end
end
shared_context "with a new work package with a custom field" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let!(:custom_field) do
create(:string_wp_custom_field, name: "Searchable field") do |cf|
project.work_package_custom_fields << cf
project.types.first.custom_fields << cf
end
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_custom_field.eml", **submit_options)
end
end
shared_context "with a new work package with invalid attributes" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_invalid_attributes.eml", **submit_options)
end
end
shared_context "with a new work package with localized attributes" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
language: "de",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
let!(:feature_type) do
create(:type,
name: "Feature request") do |type|
project.types << type
end
end
let!(:stock_category) do
project.categories.create(name: "Stock management")
end
let!(:urgent_priority) do
create(:priority_urgent)
end
subject do
submit_email("wp_with_localized_attributes.eml", **submit_options)
end
end
shared_context "with a new work package with iso 8859 1 subject" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
language: "de",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_iso_8859_1_subject.eml", **submit_options)
end
end
shared_context "with a new work package with long subject" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
language: "de",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_long_subject.eml", **submit_options)
end
end
shared_context "with a new work package with html only description" do
let(:permissions) { %i[add_work_packages] }
let!(:user) do
create(:user,
mail: "JSmith@somenet.foo",
firstname: "John",
lastname: "Smith",
language: "de",
member_with_permissions: { project => permissions })
end
let(:submit_options) { {} }
subject do
submit_email("wp_with_html_only_description.eml", **submit_options)
end
end
shared_context "with a new work package with the sender fullname in utf-8" do
let(:submit_options) { {} }
before do
ProjectRole.non_member.update_attribute :permissions, [:add_work_packages]
project.update_attribute :public, true
end
subject do
submit_email("wp_with_utf8_fullname_of_sender.eml", **submit_options)
end
end
describe "#receive" do
shared_examples_for "work package created" do
it "creates the work package" do
expect(subject)
.to be_a(WorkPackage)
expect(subject)
.to be_persisted
end
end
shared_examples_for "journal created" do
it "creates the journal" do
expect(subject)
.to be_a(Journal)
expect(subject)
.to be_persisted
end
end
context "when sending a mail not as a reply" do
context "for a given project" do
let(:type) { project.types.first }
let!(:status) { create(:status, name: "Resolved", workflow_for_type: type) }
let!(:version) { create(:version, name: "alpha", project:) }
include_context "for wp_on_given_project" do
let(:submit_options) { { allow_override: "version" } }
end
it_behaves_like "work package created"
it "sets the referenced project" do
expect(subject.project)
.to eql(project)
end
it "sets the first type in the project" do
expect(subject.type)
.to eql(type)
end
it "sets the subject" do
expect(subject.subject)
.to eql("New ticket on a given project")
end
it "sets the sender as the author" do
expect(subject.author)
.to eql(user)
end
it "set the description" do
expect(subject.description)
.to include("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.")
end
it "sets the start date" do
expect(subject.start_date.to_s)
.to eql("2010-01-01")
end
it "sets the due date" do
expect(subject.due_date.to_s)
.to eql("2010-12-31")
end
it "sets the accountable" do
expect(subject.responsible)
.to eql(user)
end
it "sets the assignee" do
expect(subject.assigned_to)
.to eql(user)
end
it "sets the status" do
expect(subject.status)
.to eql(status)
end
it "sets the version" do
expect(subject.version)
.to eql(version)
end
it "sets the estimated_hours" do
expect(subject.estimated_hours)
.to be(2.5)
end
it "sets the done_ratio" do
expect(subject.done_ratio)
.to be(30)
end
it "removes keywords" do
expect(subject.description)
.not_to match(/^Project:/i)
expect(subject.description)
.not_to match(/^Status:/i)
expect(subject.description)
.not_to match(/^Start Date:/i)
end
it "sends notifications to watching users" do
# User gets all updates
user = create(:user,
member_with_permissions: { project => %i(view_work_packages) },
notification_settings: [build(:notification_setting, all: true)])
expect do
perform_enqueued_jobs do
subject
end
end.to change(Notification.where(recipient: user), :count).by(1)
end
it "does not send an error reply email" do
subject # send mail
expect(UserMailer).not_to have_received(:incoming_email_error)
end
end
context "for a given project with a default type" do
let(:default_type) do
create(:type, is_default: true) do |t|
project.types << t
end
end
include_context "for wp_on_given_project" do
let(:submit_options) { { issue: { type: default_type.name } } }
end
it_behaves_like "work package created"
it "sets the default type" do
expect(subject.type.name)
.to eql(default_type.name)
end
end
context "for a given project with a locked user" do
let!(:status) { create(:status, name: "Resolved") }
before do
user.locked!
end
include_context "for wp_on_given_project"
it "does not create the work package" do
expect { subject }
.not_to change(WorkPackage, :count)
end
end
context "for a given project with group assignment" do
include_context "for wp on given project group assignment"
it_behaves_like "work package created"
it "sets the accountable to the group" do
expect(subject.responsible)
.to eql(group)
end
it "sets the assignee to the group" do
expect(subject.assigned_to)
.to eql(group)
end
end
context "for an email by unknown user" do
context "with unknown_user: 'create'" do
it "adds a work_package by create user on public project" do
ProjectRole.non_member.update_attribute :permissions, [:add_work_packages]
project.update_attribute :public, true
expect do
work_package = submit_email("ticket_by_unknown_user.eml", issue: { project: "onlinestore" }, unknown_user: "create")
work_package_created(work_package)
expect(work_package.author).to be_active
expect(work_package.author.mail).to eq("john.doe@somenet.foo")
expect(work_package.author.firstname).to eq("John")
expect(work_package.author.lastname).to eq("Doe")
# account information
perform_enqueued_jobs
email = ActionMailer::Base.deliveries.first
expect(email).not_to be_nil
expect(email.subject).to eq(I18n.t("mail_subject_register", value: Setting.app_title))
login = email.body.encoded.match(/\* Username: (\S+)\s?$/)[1]
password = email.body.encoded.match(/\* Password: (\S+)\s?$/)[1]
# Can't log in here since randomly assigned password must be changed
found_user = User.find_by(login:)
expect(work_package.author).to eq(found_user)
expect(found_user).to be_check_password(password)
end.to change(User, :count).by(1)
end
end
context "with unknown_user: 'create' and an utf8 encoded fullname" do
include_context "with a new work package with the sender fullname in utf-8"
let(:submit_options) { { issue: { project: "onlinestore" }, unknown_user: "create" } }
it_behaves_like "work package created"
it "adds the user with decoded fullname" do
expect do
expect(subject.author).to be_active
expect(subject.author.mail).to eq("foo@example.org")
expect(subject.author.firstname).to eq((+"\xc3\x84\xc3\xa4").force_encoding("UTF-8"))
expect(subject.author.lastname).to eq((+"\xc3\x96\xc3\xb6").force_encoding("UTF-8"))
end.to change(User, :count).by(1)
end
end
context "with unknown_user: nil (default)" do
let(:results) { [] }
before do
results << submit_email(
"ticket_by_unknown_user.eml",
issue: { project: project.identifier },
unknown_user: nil
)
end
it "ignores the email" do
expect(results).to eq [nil]
end
it "does not respond with an error email" do
expect(UserMailer).not_to have_received(:incoming_email_error)
end
end
context "with unknown_user: 'accept' and permission check present" do
let(:expected) do
"MailHandler: work_package could not be created by Anonymous due to " \
'#["Type was attempted to be written but is not writable.", ' \
'"Project was attempted to be written but is not writable.", ' \
'"Subject was attempted to be written but is not writable.", ' \
'"Description was attempted to be written but is not writable.", ' \
'"may not be accessed."]'
end
let(:permission) { nil }
subject(:work_package) do
submit_email(
"ticket_by_unknown_user.eml",
issue: { project: project.identifier },
unknown_user: "accept"
)
end
before do
allow(Rails.logger).to receive(:error).with(expected)
ProjectRole.anonymous.add_permission!(permission) if permission
end
context "with anonymous lacking permissions" do
before do
work_package
end
it "rejects the email, and does not save the work package" do
expect(work_package).to be_new_record
expect(work_package.errors).not_to be_empty
end
it "logs the error" do
expect(Rails.logger).to have_received(:error).with(expected)
end
context "with report_incoming_email_errors true (default)" do
it "responds with an error email" do
expect(UserMailer).to have_received(:incoming_email_error) do |user, mail, logs|
expect(user).to eq anno_user
expect(mail[:subject]).to eq "Ticket by unknown user"
expect(logs).to eq [expected.sub(/^MailHandler/, "error")]
end
end
end
context "with report_incoming_email_errors false", with_settings: { report_incoming_email_errors: false } do
it "does not respond with an error email" do
expect(UserMailer).not_to have_received(:incoming_email_error)
end
end
end
context "with anonymous having permissions in a public project" do
let(:permission) { :add_work_packages }
before do
project.update_attribute(:public, true)
end
it_behaves_like "work package created"
it "sets the author to anonymous" do
expect(work_package.author)
.to eql User.anonymous
end
it "creates no user" do
expect { work_package }
.not_to change(User, :count)
end
end
context "with anonymous having permissions in a private project" do
let(:permission) { :add_work_packages }
before do
project.update_attribute(:public, false)
end
it "creates no work package" do
expect { work_package }
.not_to change(WorkPackage, :count)
end
it "creates no user" do
expect { work_package }
.not_to change(User, :count)
end
end
end
context "for unknown_user: 'accept' and no_permission_check" do
subject(:work_package) do
submit_email "ticket_by_unknown_user.eml",
issue: { project: project.identifier },
unknown_user: "accept",
no_permission_check: 1
end
it_behaves_like "work package created"
it "sets the author to anonymous" do
expect(work_package.author).to eq(User.anonymous)
end
end
context "for unknown_user: 'accept' and without from header" do
subject(:work_package) do
ProjectRole.anonymous.add_permission!(:add_work_packages)
submit_email "wp_without_from_header.eml",
issue: { project: project.identifier },
unknown_user: "accept"
end
it "creates no work package" do
expect { work_package }
.not_to change(WorkPackage, :count)
end
end
context "for unknown_user: 'accept' and without permission checks and without from header" do
subject(:work_package) do
submit_email "wp_without_from_header.eml",
issue: { project: project.identifier },
unknown_user: "accept",
no_permission_check: 1
end
it_behaves_like "work package created"
it "sets the author to anonymous" do
expect(work_package.author).to eq(User.anonymous)
end
end
end
context "for email from emission address", with_settings: { mail_from: "openproject@example.net" } do
before do
ProjectRole.non_member.add_permission!(:add_work_packages)
end
subject do
project.update(public: true)
submit_email("ticket_from_emission_address.eml",
issue: { project: project.identifier },
unknown_user: "create")
end
it "returns false" do
expect(subject).to be_falsey
end
it "does not create the user" do
expect { subject }
.not_to(change(User, :count))
end
it "does not create the work_package" do
expect { subject }
.not_to(change(WorkPackage, :count))
end
it "does not result in an error email response" do
subject # send email
expect(UserMailer).not_to have_received(:incoming_email_error)
end
end
context "for wp with status" do
let(:type) { project.types.first }
let!(:status) { create(:status, name: "Resolved", workflow_for_type: type) }
# This email contains: 'Project: onlinestore' and 'Status: Resolved'
include_context "for wp_on_given_project"
it_behaves_like "work package created"
it "assigns the status to the created work package" do
expect(subject.status)
.to eql(status)
end
end
context "for wp with status case insensitive" do
let(:type) { project.types.first }
let!(:status) { create(:status, name: "Resolved", workflow_for_type: type) }
let!(:version) { create(:version, name: "alpha", project:) }
# This email contains: 'Project: onlinestore' and 'Status: resolved'
include_context "for wp_on_given_project_case_insensitive"
it_behaves_like "work package created"
it "assigns the status to the created work package" do
expect(subject.status).to eq(status)
expect(subject.version).to eq(version)
expect(subject.priority).to eq priority_low
end
end
context "for wp with cc" do
include_context "with wp create with cc"
it_behaves_like "work package created"
it "assigns cc and author as watcher" do
expect(subject.watcher_users)
.to contain_exactly(user, cc_user)
end
end
context "for a wp overriding attributes" do
include_context "with a new work package with attributes"
let(:submit_options) { { allow_override: "type,category,priority" } }
it_behaves_like "work package created"
it "sets the provided attributes" do
expect(subject.project)
.to eql project
expect(subject.type)
.to eql feature_type
expect(subject.category)
.to eql stock_category
expect(subject.priority)
.to eql urgent_priority
end
end
context "for a wp overriding attributes partially" do
include_context "with a new work package with attributes"
let(:submit_options) { { issue: { priority: "High" }, allow_override: ["type"] } }
it_behaves_like "work package created"
it "sets the provided attributes only to the extend allowed and uses default" do