Skip to content

A platform for community discussion. Free, open, simple.

FIX: allow event creators to manage invitees (#38966)

Régis Hanol26e689ff8cce
diff --git a/plugins/discourse-calendar/plugin.rb b/plugins/discourse-calendar/plugin.rb
index a8ad9fa2d5a..ab9218b9591 100644
--- a/plugins/discourse-calendar/plugin.rb
+++ b/plugins/discourse-calendar/plugin.rb
@@ -197,7 +197,7 @@ after_initialize do
end
add_to_class(:guardian, :can_act_on_invitee?) do |invitee|
- user && (user.staff? || user.id == invitee.user_id)
+ user && (user.id == invitee.user_id || can_act_on_discourse_post_event?(invitee.event))
end
add_to_class(:guardian, :can_create_discourse_post_event?) do
diff --git a/plugins/discourse-calendar/spec/services/discourse_post_event/destroy_invitee_spec.rb b/plugins/discourse-calendar/spec/services/discourse_post_event/destroy_invitee_spec.rb
index 9b9b8d22850..115cb971e22 100644
--- a/plugins/discourse-calendar/spec/services/discourse_post_event/destroy_invitee_spec.rb
+++ b/plugins/discourse-calendar/spec/services/discourse_post_event/destroy_invitee_spec.rb
@@ -124,5 +124,31 @@ RSpec.describe(DiscoursePostEvent::DestroyInvitee) do
expect { result }.to change { DiscoursePostEvent::Invitee.count }.by(-1)
end
end
+
+ context "when event creator destroys another user's invitee" do
+ fab!(:event_creator) { Fabricate(:user, refresh_auto_groups: true) }
+ fab!(:creator_topic) { Fabricate(:topic, user: event_creator) }
+ fab!(:creator_post) { Fabricate(:post, user: event_creator, topic: creator_topic) }
+ fab!(:creator_event) { Fabricate(:event, post: creator_post) }
+ fab!(:creator_event_invitee) do
+ creator_event.create_invitees(
+ [{ user_id: invitee_user.id, status: DiscoursePostEvent::Invitee.statuses[:going] }],
+ )
+ creator_event.invitees.find_by(user_id: invitee_user.id)
+ end
+
+ let(:params) { { post_id: creator_event.id, id: creator_event_invitee.id } }
+ let(:dependencies) { { guardian: event_creator.guardian } }
+
+ before do
+ SiteSetting.discourse_post_event_allowed_on_groups = Group::AUTO_GROUPS[:trust_level_0].to_s
+ end
+
+ it { is_expected.to run_successfully }
+
+ it "destroys the invitee" do
+ expect { result }.to change { DiscoursePostEvent::Invitee.count }.by(-1)
+ end
+ end
end
end
diff --git a/plugins/discourse-calendar/spec/services/discourse_post_event/update_invitee_spec.rb b/plugins/discourse-calendar/spec/services/discourse_post_event/update_invitee_spec.rb
index ffc1a1df3a9..a5a2a52d1f7 100644
--- a/plugins/discourse-calendar/spec/services/discourse_post_event/update_invitee_spec.rb
+++ b/plugins/discourse-calendar/spec/services/discourse_post_event/update_invitee_spec.rb
@@ -135,6 +135,36 @@ RSpec.describe(DiscoursePostEvent::UpdateInvitee) do
it { is_expected.to fail_a_policy(:has_capacity) }
end
+ context "when event creator updates another user's invitee" do
+ fab!(:event_creator) { Fabricate(:user, refresh_auto_groups: true) }
+ fab!(:creator_topic) { Fabricate(:topic, user: event_creator) }
+ fab!(:creator_post) { Fabricate(:post, user: event_creator, topic: creator_topic) }
+ fab!(:creator_event) { Fabricate(:event, post: creator_post) }
+ fab!(:creator_event_invitee) do
+ creator_event.create_invitees(
+ [{ user_id: invitee_user.id, status: DiscoursePostEvent::Invitee.statuses[:going] }],
+ )
+ creator_event.invitees.find_by(user_id: invitee_user.id)
+ end
+
+ let(:params) do
+ { event_id: creator_event.id, invitee_id: creator_event_invitee.id, status: "not_going" }
+ end
+ let(:dependencies) { { guardian: event_creator.guardian } }
+
+ before do
+ SiteSetting.discourse_post_event_allowed_on_groups = Group::AUTO_GROUPS[:trust_level_0].to_s
+ end
+
+ it { is_expected.to run_successfully }
+
+ it "updates the invitee status" do
+ expect { result }.to change { creator_event_invitee.reload.status }.from(
+ DiscoursePostEvent::Invitee.statuses[:going],
+ ).to(DiscoursePostEvent::Invitee.statuses[:not_going])
+ end
+ end
+
context "when everything is valid" do
it { is_expected.to run_successfully }