Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Oct 6, 2024
1 parent 421d6be commit b140989
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion app/controllers/discourse_events/event_topic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def connect
if category_id
category = Category.find_by(id: category_id)
raise Discourse::InvalidParameters.new(:category_id) unless category.present?
topic_opts[:category_id] = category_id
topic_opts[:category] = category_id
end

client = params[:client]
Expand Down
3 changes: 2 additions & 1 deletion assets/javascripts/discourse/components/modal/add-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { action } from "@ember/object";
import I18n from "I18n";

export default class AddEvent extends Component {
@tracked bufferedEvent = this.args.model.event;
@tracked bufferedEvent = this.model.event;
title = I18n.t("add_event.modal_title");
valid = true;

@action
clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,44 @@
{{i18n "admin.events.event.connect.create_topic"}}
</label>
</div>
<div class="control-group">
<label>{{i18n "admin.events.event.connect.client"}}</label>
<EventsSubscriptionSelector
@value={{this.client}}
@feature="source"
@attribute="client"
@onChange={{action (mut this.client)}}
@allowedValues={{allowedClientValues}}
class="connection-client"
options={{hash none="admin.events.connection.client.select"}}
/>
</div>
<div class="control-group">
<label>{{i18n "admin.events.event.connect.category"}}</label>
<EventsCategoryChooser
@value={{this.category_id}}
class="connect-category"
@client={{this.client}}
onChange={{action (mut this.category_id)}}
@options={{hash disabled=this.topicId}}
/>
</div>
<div class="control-group">
<label>{{i18n "admin.events.event.connect.user"}}</label>
<UserChooser
@value={{this.username}}
@onChange={{action (mut this.username)}}
class="connect-user"
@options={{hash
maximum=1
excludeCurrentUser=false
disabled=this.topicId
}}
/>
</div>

{{#if this.createTopic}}
<div class="control-group">
<label>{{i18n "admin.events.event.connect.client"}}</label>
<EventsSubscriptionSelector
@value={{this.client}}
@feature="source"
@attribute="client"
@onChange={{action (mut this.client)}}
@allowedValues={{allowedClientValues}}
class="connection-client"
options={{hash none="admin.events.connection.client.select"}}
/>
</div>
<div class="control-group">
<label>{{i18n "admin.events.event.connect.category"}}</label>
<EventsCategoryChooser
@value={{this.category_id}}
class="connect-category"
@client={{this.client}}
onChange={{action (mut this.category_id)}}
@options={{hash disabled=this.topicId}}
/>
</div>
<div class="control-group">
<label>{{i18n "admin.events.event.connect.user"}}</label>
<UserChooser
@value={{this.username}}
@onChange={{action (mut this.username)}}
class="connect-user"
@options={{hash
maximum=1
excludeCurrentUser=false
disabled=this.topicId
}}
/>
</div>
{{/if}}
</:body>
<:footer>
<DButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default Component.extend({

Event.connectTopic(opts)
.then((result) => {
if (result.success) {
if (result?.success) {
this.model.onConnectTopic();
this.closeModal();
} else {
Expand Down
4 changes: 4 additions & 0 deletions assets/stylesheets/common/events-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ $pavilion_primary: #3c1c8c;
}

.events-connect-topic-modal {
.select-kit.combo-box.category-chooser {
width: 100%;
}

.control-group {
margin-bottom: 1em;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def change
end

add_index :discourse_events_event_registrations,
%i[email],
%i[event_id email],
unique: true,
name: :idx_events_event_registration_emails
name: :idx_events_event_registration_event_emails
end
end
2 changes: 1 addition & 1 deletion lib/discourse_events/import_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def import(opts = {})
end
result
end
EventRegistration.upsert_all(registrations, unique_by: %i[email])
EventRegistration.upsert_all(registrations, unique_by: %i[event_id email])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_events/publish_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def update_event
uid: registration.uid,
email: registration.email,
name: registration.name,
status: DiscourseEvents::EventRegistration.statuses[registration.status].to_s,
status: registration.status,
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_events/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def omnievent_opts(type, data, opts)
end

def event_hash(type, data)
raise ArgumentError.new "No event data" unless data.is_a?(EventData)
raise ArgumentError.new "No event data" unless data.is_a?(Event)
event = data.event_hash(type, provider.provider_type)
raise ArgumentError.new "Invalid event data" unless event.valid?
event
Expand Down
13 changes: 12 additions & 1 deletion lib/discourse_events/publisher/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ def metadata
end

def associated_data
{ registrations: registrations }
{
registrations:
(registrations || []).map do |registration|
{
uid: registration.uid,
email: registration.email,
name: registration.name,
status: registration.status,
}
end,
}
end

def create_params
Expand Down Expand Up @@ -98,6 +108,7 @@ def update_event_hash(provider_type)
provider: provider_type,
data: data.compact,
metadata: metadata.compact,
associated_data: associated_data.compact,
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_events/subscription_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SubscriptionManager
omnievent_icalendar: "0.1.0.pre7",
omnievent_api: "0.1.0.pre5",
omnievent_outlook: "0.1.0.pre7",
omnievent_google: "0.1.0.pre5",
omnievent_google: "0.1.0.pre6",
},
}

Expand Down
3 changes: 2 additions & 1 deletion lib/discourse_events/syncer/discourse_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def update_client_registrations(topic, event)
if confirmed_user_ids.any?
event_going = topic.event_going || []

if !topic.event_going_max || list.length <= topic.event_going_max
if !topic.event_going_max || event_going.length <= topic.event_going_max
confirmed_user_ids.each do |user_id|
event_going << user_id unless event_going.include?(user_id)
end
end

topic.custom_fields["event_rsvp"] = true
topic.custom_fields["event_going"] = event_going
topic.save_custom_fields(true)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/discourse_events/syncer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# rubocop:disable Discourse/Plugins/NoMonkeyPatching
DiscourseEvents::Syncer.class_eval do
def create_client_topic(event)
create_post(event).topic
def create_client_topic(event, topic_opts = {})
create_post(event, topic_opts).topic
end

def update_client_topic(topic, event, add_raw: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@
}
expect(response.status).to eq(200)
expect(response.parsed_body["success"]).to eq("OK")
expect(DiscourseEvents::EventTopic.exists?(event_id: event.id)).to eq(true)

event_topic = DiscourseEvents::EventTopic.find_by(event_id: event.id)
expect(event_topic).to be_present
expect(event_topic.topic.title).to eq(event.name)
expect(event_topic.topic.category.id).to eq(category.id)
end
end
end
Expand Down

0 comments on commit b140989

Please sign in to comment.