group manager can invite members into the group from any restricted topic

This commit is contained in:
Jason W. May
2015-03-02 11:25:25 -08:00
parent 35c58c1b00
commit 0f36774246
8 changed files with 132 additions and 7 deletions

View File

@ -56,6 +56,21 @@ class Invite < ActiveRecord::Base
end
def add_groups_for_topic(topic)
if topic.category
(topic.category.groups - groups).each { |group| group.add(user) }
end
end
def self.extend_permissions(topic, user, invited_by)
if topic.private_message?
topic.grant_permission_to_user(user.email)
elsif topic.category && topic.category.groups.any?
if Guardian.new(invited_by).can_invite_to?(topic)
(topic.category.groups - user.groups).each { |group| group.add(user) }
end
end
end
# Create an invite for a user, supplying an optional topic
#
# Return the previously existing invite if already exists. Returns nil if the invite can't be created.
@ -64,7 +79,7 @@ class Invite < ActiveRecord::Base
user = User.find_by(email: lower_email)
if user
topic.grant_permission_to_user(lower_email) if topic && topic.private_message?
extend_permissions(topic, user, invited_by) if topic
return nil
end
@ -93,6 +108,11 @@ class Invite < ActiveRecord::Base
group_ids.each do |group_id|
invite.invited_groups.create!(group_id: group_id)
end
else
if topic && topic.category # && Guardian.new(invited_by).can_invite_to?(topic)
group_ids = topic.category.groups.pluck(:id) - invite.invited_groups.pluck(:group_id)
group_ids.each { |group_id| invite.invited_groups.create!(group_id: group_id) }
end
end
Jobs.enqueue(:invite_email, invite_id: invite.id)