2021-01-13 09:27:23 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe TopicViewDetailsSerializer do
|
2021-01-13 09:27:23 -05:00
|
|
|
describe "#allowed_users" do
|
|
|
|
it "add the current user to the allowed user's list even if they are an allowed group member" do
|
|
|
|
participant = Fabricate(:user)
|
|
|
|
another_participant = Fabricate(:user)
|
|
|
|
|
|
|
|
participant_group = Fabricate(:group)
|
|
|
|
participant_group.add(participant)
|
|
|
|
participant_group.add(another_participant)
|
|
|
|
|
|
|
|
pm =
|
|
|
|
Fabricate(
|
|
|
|
:private_message_topic,
|
|
|
|
topic_allowed_users: [
|
|
|
|
Fabricate.build(:topic_allowed_user, user: participant),
|
|
|
|
Fabricate.build(:topic_allowed_user, user: another_participant),
|
|
|
|
],
|
|
|
|
topic_allowed_groups: [Fabricate.build(:topic_allowed_group, group: participant_group)],
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2021-01-13 09:27:23 -05:00
|
|
|
serializer =
|
|
|
|
described_class.new(TopicView.new(pm, participant), scope: Guardian.new(participant))
|
|
|
|
allowed_users = serializer.as_json.dig(:topic_view_details, :allowed_users).map { |u| u[:id] }
|
|
|
|
|
|
|
|
expect(allowed_users).to contain_exactly(participant.id)
|
|
|
|
end
|
|
|
|
end
|
2022-03-31 21:03:39 -04:00
|
|
|
|
|
|
|
describe "#can_permanently_delete" do
|
|
|
|
let(:post) do
|
|
|
|
Fabricate(:post).tap { |post| PostDestroyer.new(Discourse.system_user, post).destroy }
|
|
|
|
end
|
|
|
|
|
|
|
|
before { SiteSetting.can_permanently_delete = true }
|
|
|
|
|
|
|
|
it "is true for admins" do
|
2024-03-25 23:41:12 -04:00
|
|
|
admin = Fabricate(:admin)
|
2022-03-31 21:03:39 -04:00
|
|
|
|
|
|
|
serializer = described_class.new(TopicView.new(post.topic, admin), scope: Guardian.new(admin))
|
|
|
|
expect(serializer.as_json.dig(:topic_view_details, :can_permanently_delete)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not present for moderators" do
|
|
|
|
moderator = Fabricate(:moderator)
|
|
|
|
|
|
|
|
serializer =
|
|
|
|
described_class.new(TopicView.new(post.topic, moderator), scope: Guardian.new(moderator))
|
|
|
|
expect(serializer.as_json.dig(:topic_view_details, :can_permanently_delete)).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2021-01-13 09:27:23 -05:00
|
|
|
end
|