0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/app/serializers/invite_serializer.rb
Keegan George 983b7f6dee
FEATURE: Allow inviting staff as admins or moderators (#41880)
**Previously**, the staff invite modal only offered a single "Admins"
tab that could invite people as admins.

**In this update**, the tab is renamed to "Staff" and an "Invite as"
choice lets you send the invitation as either an admin or a moderator.

| Before | After |
| --- | --- |
|
![before](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/before-1z1m4y.png)
|
![after](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/after-gwu25s.png)
|
2026-07-21 14:05:21 -07:00

114 lines
2.3 KiB
Ruby
Vendored

# frozen_string_literal: true
class InviteSerializer < ApplicationSerializer
attributes :id,
:invite_key,
:link,
:description,
:email,
:domain,
:emailed,
:can_delete_invite,
:max_redemptions_allowed,
:redemption_count,
:custom_message,
:created_at,
:updated_at,
:expires_at,
:expired,
:grants_admin,
:grants_moderator
has_many :topics, embed: :object, serializer: BasicTopicSerializer
has_many :groups, embed: :object, serializer: BasicGroupSerializer
def include_invite_key?
can_see_invite_details?
end
def include_link?
can_see_invite_details?
end
def include_description?
can_see_invite_details?
end
def include_email?
options[:show_emails] && !object.redeemed? && can_see_invite_emails?
end
def include_domain?
can_see_invite_details?
end
def include_emailed?
email.present? && can_see_invite_details?
end
def emailed
object.emailed_status != Invite.emailed_status_types[:not_required]
end
def can_delete_invite
scope.can_destroy_invite?(object)
end
def include_custom_message?
email.present? && can_see_invite_details?
end
def include_max_redemptions_allowed?
email.blank? && can_see_invite_details?
end
def include_redemption_count?
email.blank? && can_see_invite_details?
end
def include_topics?
can_see_invite_details?
end
def topics
object.topics.select { |topic| scope.can_see?(topic) }
end
def include_groups?
can_see_invite_details?
end
def expired
object.expired?
end
def grants_admin
object.admin?
end
def include_grants_admin?
can_see_invite_details?
end
def grants_moderator
object.moderator?
end
def include_grants_moderator?
can_see_invite_details?
end
private
def can_see_invite_details?
return @can_see_invite_details if defined?(@can_see_invite_details)
@can_see_invite_details = scope.can_see_invite_details?(object.invited_by)
end
def can_see_invite_emails?
return @can_see_invite_emails if defined?(@can_see_invite_emails)
@can_see_invite_emails = scope.can_see_invite_emails?(object.invited_by)
end
end