DEV: use group_ids instead of group_names in invite params

DEV: use group_ids instead of group_names in invite params

diff --git a/app/assets/javascripts/discourse/app/components/invite-link-panel.js b/app/assets/javascripts/discourse/app/components/invite-link-panel.js
index a46a707..6856d2d 100644
--- a/app/assets/javascripts/discourse/app/components/invite-link-panel.js
+++ b/app/assets/javascripts/discourse/app/components/invite-link-panel.js
@@ -41,10 +41,6 @@ export default Component.extend({
     return false;
   },
 
-  groupFinder(term) {
-    return Group.findAll({ term, ignore_automatic: true });
-  },
-
   errorMessage: I18n.t("user.invited.invite_link.error"),
 
   reset() {
@@ -67,9 +63,7 @@ export default Component.extend({
       return;
     }
 
-    const groupNames = this.allGroups
-      .filter(g => this.groupIds.includes(g.id))
-      .map(g => g.name);
+    const groupIds = this.groupIds;
     const maxRedemptionAllowed = this.maxRedemptionAllowed;
     const inviteExpiresAt = this.inviteExpiresAt;
     const userInvitedController = this.userInvitedShow;
@@ -78,7 +72,7 @@ export default Component.extend({
 
     return model
       .generateMultipleUseInviteLink(
-        groupNames,
+        groupIds,
         maxRedemptionAllowed,
         inviteExpiresAt
       )
diff --git a/app/assets/javascripts/discourse/app/components/invite-panel.js b/app/assets/javascripts/discourse/app/components/invite-panel.js
index 2ecd413..7f11433 100644
--- a/app/assets/javascripts/discourse/app/components/invite-panel.js
+++ b/app/assets/javascripts/discourse/app/components/invite-panel.js
@@ -310,9 +310,7 @@ export default Component.extend({
         return;
       }
 
-      const groupNames = this.allGroups
-        .filter(g => this.groupIds.includes(g.id))
-        .map(g => g.name);
+      const groupIds = this.groupIds;
       const userInvitedController = this.userInvitedShow;
 
       const model = this.inviteModel;
@@ -347,7 +345,7 @@ export default Component.extend({
         return this.inviteModel
           .createInvite(
             this.emailOrUsername.trim(),
-            groupNames,
+            groupIds,
             this.customMessage
           )
           .then(result => {
@@ -385,7 +383,7 @@ export default Component.extend({
         return;
       }
 
-      const groupNames = this.get("inviteModel.groupNames");
+      const groupIds = this.groupIds;
       const userInvitedController = this.userInvitedShow;
       const model = this.inviteModel;
       model.setProperties({ saving: true, error: false });
@@ -396,7 +394,7 @@ export default Component.extend({
       }
 
       return model
-        .generateInviteLink(this.emailOrUsername.trim(), groupNames, topicId)
+        .generateInviteLink(this.emailOrUsername.trim(), groupIds, topicId)
         .then(result => {
           model.setProperties({
             saving: false,
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index b4a69c3..98b0669 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -493,17 +493,17 @@ const Topic = RestModel.extend({
     });
   },
 
-  createInvite(user, group_names, custom_message) {
+  createInvite(user, group_ids, custom_message) {
     return ajax(`/t/${this.id}/invite`, {
       type: "POST",
-      data: { user, group_names, custom_message }
+      data: { user, group_ids, custom_message }
     });
   },
 
-  generateInviteLink(email, groupNames, topicId) {
+  generateInviteLink(email, group_ids, topic_id) {
     return ajax("/invites/link", {
       type: "POST",
-      data: { email, group_names: groupNames, topic_id: topicId }
+      data: { email, group_ids, topic_id }
     });
   },
 
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index f4482fa..eb59335 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -668,28 +668,28 @@ const User = RestModel.extend({
     );
   },
 
-  createInvite(email, group_names, custom_message) {
+  createInvite(email, group_ids, custom_message) {
     return ajax("/invites", {
       type: "POST",
-      data: { email, group_names, custom_message }
+      data: { email, group_ids, custom_message }
     });
   },
 
-  generateInviteLink(email, group_names, topic_id) {
+  generateInviteLink(email, group_ids, topic_id) {
     return ajax("/invites/link", {
       type: "POST",
-      data: { email, group_names, topic_id }
+      data: { email, group_ids, topic_id }
     });
   },
 
   generateMultipleUseInviteLink(
-    group_names,
+    group_ids,
     max_redemptions_allowed,
     expires_at
   ) {
     return ajax("/invites/link", {
       type: "POST",
-      data: { group_names, max_redemptions_allowed, expires_at }
+      data: { group_ids, max_redemptions_allowed, expires_at }
     });
   },
 
diff --git a/app/models/group.rb b/app/models/group.rb
index 34a91cb..7bbc04e 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -537,7 +537,7 @@ class Group < ActiveRecord::Base
 
   def self.lookup_groups(group_ids: [], group_names: [])
     if group_ids.present?
-      group_ids = group_ids.split(",")
+      group_ids = group_ids.split(",") if group_ids.is_a?(String)
       group_ids.map!(&:to_i)
       groups = Group.where(id: group_ids) if group_ids.present?
     end
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index 16b79fd..5f9a002 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -107,7 +107,7 @@ describe InvitesController do
       it "allows admins to invite to groups" do
         group = Fabricate(:group)
         sign_in(admin)
-        post "/invites.json", params: { email: email, group_names: group.name }
+        post "/invites.json", params: { email: email, group_ids: [group.id] }
         expect(response.status).to eq(200)
         expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
       end
@@ -118,7 +118,7 @@ describe InvitesController do
         user.update!(trust_level: TrustLevel[2])
         group.add_owner(user)
 
-        post "/invites.json", params: { email: email, group_names: group.name }
+        post "/invites.json", params: { email: email, group_ids: [group.id] }
 
         expect(response.status).to eq(200)
         expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
@@ -198,7 +198,7 @@ describe InvitesController do
           sign_in(admin)
 
           post "/invites/link.json", params: {
-            email: email, group_names: group.name
+            email: email, group_ids: [group.id]
           }
 
           expect(response.status).to eq(200)
@@ -245,7 +245,7 @@ describe InvitesController do
 
           post "/invites/link.json", params: {
             max_redemptions_allowed: 5,
-            group_names: group.name
+            group_ids: [group.id]
           }
 
           expect(response.status).to eq(200)

GitHub sha: ba57dc57