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>
This commit is contained in:
Neil Lalonde 2020-04-07 11:58:49 -04:00 committed by GitHub
parent 4f42bb1fd2
commit e8fad7a69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,4 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality);

View File

@ -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

View File

@ -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