Skip to content

Commit 6c955ab

Browse files
committed
Merge remote-tracking branch 'origin/stable' into pkgr
2 parents 2fd2a17 + 56b79ff commit 6c955ab

5 files changed

Lines changed: 77 additions & 37 deletions

File tree

.travis.yml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ env:
55
- DISCOURSE_HOSTNAME=www.example.com
66
- RUBY_GC_MALLOC_LIMIT=50000000
77
matrix:
8-
- "RAILS_MASTER=0 QUNIT_RUN=0"
9-
- "RAILS_MASTER=1 QUNIT_RUN=0"
10-
- "RAILS_MASTER=0 QUNIT_RUN=1"
11-
- "RAILS_MASTER=1 QUNIT_RUN=1"
8+
- "RAILS_MASTER=0 QUNIT_RUN=0 RUN_LINT=0"
9+
- "RAILS_MASTER=0 QUNIT_RUN=1 RUN_LINT=0"
10+
- "RAILS_MASTER=0 QUNIT_RUN=0 RUN_LINT=1"
1211

1312
addons:
1413
postgresql: 9.5
@@ -20,14 +19,11 @@ addons:
2019
- jhead
2120

2221
matrix:
23-
allow_failures:
24-
- env: "RAILS_MASTER=1 QUNIT_RUN=0"
25-
- env: "RAILS_MASTER=1 QUNIT_RUN=1"
2622
fast_finish: true
2723

2824
rvm:
29-
- 2.4.1
30-
- 2.3.3
25+
- 2.4.2
26+
- 2.3.4
3127

3228
services:
3329
- redis-server
@@ -46,20 +42,32 @@ before_install:
4642
- git clone --depth=1 https://github.com/discourse/discourse-spoiler-alert.git plugins/discourse-spoiler-alert
4743
- git clone --depth=1 https://github.com/discourse/discourse-cakeday.git plugins/discourse-cakeday
4844
- git clone --depth=1 https://github.com/discourse/discourse-canned-replies.git plugins/discourse-canned-replies
49-
- git clone --depth=1 https://github.com/discourse/discourse-slack-official.git plugins/discourse-slack-official
50-
- yarn global add eslint@3 babel-eslint
51-
- eslint app/assets/javascripts
52-
- eslint --ext .es6 app/assets/javascripts
53-
- eslint --ext .es6 test/javascripts
54-
- eslint --ext .es6 plugins/**/assets/javascripts
55-
- eslint test/javascripts
56-
57-
before_script:
58-
- bundle exec rake db:create db:migrate
45+
- git clone --depth=1 https://github.com/discourse/discourse-chat-integration.git plugins/discourse-chat-integration
46+
- git clone --depth=1 https://github.com/discourse/discourse-assign.git plugins/discourse-assign
47+
- export PATH=$HOME/.yarn/bin:$PATH
5948

6049
install:
6150
- bash -c "if [ '$RAILS_MASTER' == '1' ]; then bundle update --retry=3 --jobs=3 arel rails seed-fu; fi"
6251
- bash -c "if [ '$RAILS_MASTER' == '0' ]; then bundle install --without development --deployment --retry=3 --jobs=3; fi"
52+
- bash -c "if [ '$RUN_LINT' == '1' ]; then yarn global add eslint babel-eslint; fi"
6353

6454
script:
65-
- bash -c "if [ '$QUNIT_RUN' == '0' ]; then bundle exec rspec && bundle exec rake plugin:spec; else bundle exec rake qunit:test['200000']; fi"
55+
- |
56+
bash -c "
57+
if [ '$RUN_LINT' == '1' ]; then
58+
bundle exec rubocop --parallel && \
59+
eslint --ext .es6 app/assets/javascripts && \
60+
eslint --ext .es6 test/javascripts && \
61+
eslint --ext .es6 plugins/**/assets/javascripts && \
62+
eslint --ext .es6 plugins/**/test/javascripts && \
63+
eslint app/assets/javascripts test/javascripts
64+
else
65+
bundle exec rake db:create db:migrate
66+
67+
if [ '$QUNIT_RUN' == '1' ]; then
68+
LOAD_PLUGINS=1 bundle exec rake qunit:test['400000']
69+
else
70+
bundle exec rspec && bundle exec rake plugin:spec
71+
fi
72+
fi
73+
"

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def invite_group
471471
topic = Topic.find_by(id: params[:topic_id])
472472

473473
if topic.private_message?
474-
guardian.ensure_can_send_private_message!(group)
474+
guardian.ensure_can_invite_group_to_private_message!(group, topic)
475475
topic.invite_group(current_user, group)
476476
render_json_dump BasicGroupSerializer.new(group, scope: guardian, root: 'group')
477477
else

lib/guardian.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ def can_see_private_messages?(user_id)
269269
is_admin? || (authenticated? && @user.id == user_id)
270270
end
271271

272+
def can_invite_group_to_private_message?(group, topic)
273+
can_see_topic?(topic) &&
274+
can_send_private_message?(group)
275+
end
276+
272277
def can_send_private_message?(target)
273278
(target.is_a?(Group) || target.is_a?(User)) &&
274279
# User is authenticated

spec/controllers/topics_controller_spec.rb

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,31 +1011,57 @@ def topics_controller_show_gen_perm_tests(expected, ctx)
10111011
end
10121012

10131013
describe 'invite_group' do
1014-
let :admins do
1015-
Group[:admins]
1016-
end
1014+
let(:admins) { Group[:admins] }
1015+
let(:pm) { Fabricate(:private_message_topic) }
10171016

1018-
let! :admin do
1019-
log_in :admin
1017+
def invite_group(topic, expected_status)
1018+
xhr :post, :invite_group, topic_id: topic.id, group: admins.name
1019+
expect(response.status).to eq(expected_status)
10201020
end
10211021

10221022
before do
1023-
admins.alias_level = Group::ALIAS_LEVELS[:everyone]
1024-
admins.save!
1023+
admins.update!(alias_level: Group::ALIAS_LEVELS[:everyone])
10251024
end
10261025

1027-
it "disallows inviting a group to a topic" do
1028-
topic = Fabricate(:topic)
1029-
xhr :post, :invite_group, topic_id: topic.id, group: 'admins'
1030-
expect(response.status).to eq(422)
1026+
describe 'as an anon user' do
1027+
it 'should be forbidden' do
1028+
invite_group(pm, 403)
1029+
end
10311030
end
10321031

1033-
it "allows inviting a group to a PM" do
1034-
topic = Fabricate(:private_message_topic)
1035-
xhr :post, :invite_group, topic_id: topic.id, group: 'admins'
1032+
describe 'as a normal user' do
1033+
let!(:user) { log_in }
10361034

1037-
expect(response.status).to eq(200)
1038-
expect(topic.allowed_groups.first.id).to eq(admins.id)
1035+
describe 'when user does not have permission to view the topic' do
1036+
it 'should be forbidden' do
1037+
invite_group(pm, 403)
1038+
end
1039+
end
1040+
1041+
describe 'when user has permission to view the topic' do
1042+
before do
1043+
pm.allowed_users << user
1044+
end
1045+
1046+
it 'should allow user to invite group to topic' do
1047+
invite_group(pm, 200)
1048+
expect(pm.allowed_groups.first.id).to eq(admins.id)
1049+
end
1050+
end
1051+
end
1052+
1053+
describe 'as an admin user' do
1054+
let!(:admin) { log_in(:admin) }
1055+
1056+
it "disallows inviting a group to a topic" do
1057+
topic = Fabricate(:topic)
1058+
invite_group(topic, 422)
1059+
end
1060+
1061+
it "allows inviting a group to a PM" do
1062+
invite_group(pm, 200)
1063+
expect(pm.allowed_groups.first.id).to eq(admins.id)
1064+
end
10391065
end
10401066
end
10411067

spec/models/invite_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
let(:inviter) { group_private_topic.user }
142142

143143
before do
144+
group.add_owner(inviter)
144145
@invite = group_private_topic.invite_by_email(inviter, iceking)
145146
end
146147

0 commit comments

Comments
 (0)