0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 02:51:10 +08:00
discourse/lib/guardian/invite_guardian.rb
Keegan George abe5700838
FEATURE: Allow inviting new users directly as admins (#41748)
**Previously**, getting a second admin onto a site took many steps:
create an invite, wait for the person to sign up, find their profile,
grant admin, and confirm via email.

**In this update**, a redesigned invite modal (gated behind the
`enable_admin_invites` upcoming change) lets admins invite someone as an
admin by email in one step. The invitee becomes a moderator on signup
and an admin once the inviter confirms via the existing admin
confirmation email. The admin onboarding panel's "Invite collaborators"
step now opens this flow with the admin option preselected.

| Invite members | Advanced options | Email delivery |
| --- | --- | --- |
|
![invite-members.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-members.png)
|
![invite-members-advanced.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-members-advanced.png)
|
![invite-members-email.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-members-email.png)
|

| Invite admins | Advanced options | Invite sent |
| --- | --- | --- |
|
![invite-admins.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-admins.png)
|
![invite-admins-advanced.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-admins-advanced.png)
|
![admin-invite-sent.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/admin-invite-sent.png)
|

| Link created | Email invitation sent | Onboarding panel |
| --- | --- | --- |
|
![invite-created.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invite-created.png)
|
![invitation-sent.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/invitation-sent.png)
|
![onboarding-banner.png](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/onboarding-banner.png)
|
2026-07-16 14:59:24 -07:00

68 lines
1.8 KiB
Ruby
Vendored

# frozen_string_literal: true
module InviteGuardian
def can_see_invite_details?(user)
is_staff? || is_me?(user)
end
def can_see_invite_emails?(user)
is_staff? || is_me?(user)
end
def can_create_admin_invite?
is_admin? && @user.upcoming_change_enabled?(:enable_invite_modal_with_roles)
end
def can_invite_to_forum?(groups = nil)
return false if !authenticated?
return false if !@user.in_any_groups?(SiteSetting.invite_allowed_groups_map)
return false if !SiteSetting.max_invites_per_day.to_i.positive? && !is_staff?
groups.blank? || groups.all? { |g| can_edit_group?(g) }
end
def can_invite_to?(object, groups = nil)
return false if !authenticated?
return false if !object.is_a?(Topic) || !can_see?(object)
return false if groups.present?
if object.is_a?(Topic)
if object.private_message?
return true if is_admin?
return false if !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
return false if object.reached_recipients_limit? && !is_staff?
end
if (category = object.category) && category.read_restricted
return category.groups&.where(automatic: false)&.any? { |g| can_edit_group?(g) }
end
end
true
end
def can_invite_via_email?(object)
return false if !can_invite_to_forum?
return false if !can_invite_to?(object)
(SiteSetting.enable_local_logins || SiteSetting.enable_discourse_connect) &&
(!SiteSetting.must_approve_users? || is_staff?)
end
def can_bulk_invite_to_forum?
is_admin?
end
def can_resend_all_invites?
is_staff?
end
def can_destroy_all_invites?(user)
is_staff? && (is_admin? || is_me?(user))
end
def can_destroy_invite?(invite)
invite && (is_admin? || is_me?(invite.invited_by))
end
end