DEV: changes so plugins can customize invites UI (#9365)

DEV: changes so plugins can customize invites UI (#9365)

  • DEV: changes so plugins can customize invites UI

Co-Authored-By: Robin Ward robin.ward@gmail.com

diff --git a/app/assets/javascripts/discourse/controllers/share-and-invite.js b/app/assets/javascripts/discourse/controllers/share-and-invite.js
new file mode 100644
index 0000000..06110e0
--- /dev/null
+++ b/app/assets/javascripts/discourse/controllers/share-and-invite.js
@@ -0,0 +1,4 @@
+import Controller from "@ember/controller";
+import ModalFunctionality from "discourse/mixins/modal-functionality";
+
+export default Controller.extend(ModalFunctionality);
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 81eedda..b3acc1f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -317,8 +317,12 @@ class UsersController < ApplicationController
       filter_sql = '(LOWER(invites.email) LIKE :filter) or (LOWER(users.username) LIKE :filter)' if show_emails
       invites = invites.where(filter_sql, filter: "%#{params[:search].downcase}%")
     end
-    render_json_dump invites: serialize_data(invites.to_a, InviteSerializer, show_emails: show_emails),
-                     can_see_invite_details: guardian.can_see_invite_details?(inviter)
+
+    render json: MultiJson.dump(InvitedSerializer.new(
+      OpenStruct.new(invite_list: invites.to_a, show_emails: show_emails, inviter: inviter),
+      scope: guardian,
+      root: false
+    ))
   end
 
   def invited_count
diff --git a/app/serializers/invited_serializer.rb b/app/serializers/invited_serializer.rb
new file mode 100644
index 0000000..c0b07fa
--- /dev/null
+++ b/app/serializers/invited_serializer.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class InvitedSerializer < ApplicationSerializer
+  attributes :invites, :can_see_invite_details
+
+  def invites
+    ActiveModel::ArraySerializer.new(
+      object.invite_list,
+      scope: scope,
+      root: false,
+      show_emails: object.show_emails
+    ).as_json
+  end
+
+  def can_see_invite_details
+    scope.can_see_invite_details?(object.inviter)
+  end
+
+  def read_attribute_for_serialization(attr)
+    object.respond_to?(attr) ? object.public_send(attr) : public_send(attr)
+  end
+end

GitHub sha: e8fad7a6

This commit appears in #9365 which was merged by nlalonde.