Skip to content

Commit

Permalink
FEATURE: trigger user profile create and update event (#6958)
Browse files Browse the repository at this point in the history
Adds `user_profile_created` DiscourseEvent on profile creation and `user_profile_updated` on profile update
  • Loading branch information
mrfinch authored and SamSaffron committed Feb 14, 2019
1 parent b651605 commit ed6f4df
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/user_profile.rb
Expand Up @@ -8,6 +8,8 @@ class UserProfile < ActiveRecord::Base
validates :user, presence: true
before_save :cook
after_save :trigger_badges
after_commit :trigger_profile_created_event, on: :create
after_commit :trigger_profile_updated_event, on: :update

validates :profile_background, upload_url: true, if: :profile_background_changed?
validates :card_background, upload_url: true, if: :card_background_changed?
Expand Down Expand Up @@ -106,6 +108,14 @@ def self.import_url_for_user(background_url, user, options = nil)
tempfile.close! if tempfile && tempfile.respond_to?(:close!)
end

def trigger_profile_created_event
DiscourseEvent.trigger(:user_profile_created, self)
end

def trigger_profile_updated_event
DiscourseEvent.trigger(:user_profile_updated, self)
end

protected

def trigger_badges
Expand Down

0 comments on commit ed6f4df

Please sign in to comment.