mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Show error if invite to topic is invalid (#15959)
This can happen if the topic to which a user is invited is in a private category and the user was not invited to one of the groups that can see that specific category. This used to be a warning and this commit makes it an error.
This commit is contained in:
@@ -429,27 +429,4 @@ describe Invite do
|
||||
expect(invite.invalidated_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#warnings' do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:invite) { Fabricate(:invite) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:secured_category) do
|
||||
secured_category = Fabricate(:category)
|
||||
secured_category.permissions = { group.name => :full }
|
||||
secured_category.save!
|
||||
secured_category
|
||||
end
|
||||
|
||||
it 'does not return any warnings for simple invites' do
|
||||
expect(invite.warnings(admin.guardian)).to be_blank
|
||||
end
|
||||
|
||||
it 'returns a warning if topic is private' do
|
||||
topic = Fabricate(:topic, category: secured_category)
|
||||
TopicInvite.create!(topic: topic, invite: invite)
|
||||
|
||||
expect(invite.warnings(admin.guardian)).to contain_exactly(I18n.t("invite.requires_groups", groups: group.name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -203,6 +203,35 @@ describe InvitesController do
|
||||
post '/invites.json', params: { email: 'test@example.com', topic_id: -9999 }
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
context 'topic is private' do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
fab!(:secured_category) do |category|
|
||||
category = Fabricate(:category)
|
||||
category.permissions = { group.name => :full }
|
||||
category.save!
|
||||
category
|
||||
end
|
||||
|
||||
fab!(:topic) { Fabricate(:topic, category: secured_category) }
|
||||
|
||||
it 'does not work and returns a list of required groups' do
|
||||
sign_in(admin)
|
||||
|
||||
post '/invites.json', params: { email: 'test@example.com', topic_id: topic.id }
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.parsed_body["errors"]).to contain_exactly(I18n.t("invite.requires_groups", groups: group.name))
|
||||
end
|
||||
|
||||
it 'does not work if user cannot edit groups' do
|
||||
group.add(user)
|
||||
sign_in(user)
|
||||
|
||||
post '/invites.json', params: { email: 'test@example.com', topic_id: topic.id }
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'invite to group' do
|
||||
|
||||
Reference in New Issue
Block a user