DEV: use group_ids instead of group_names in invite params

This commit is contained in:
Arpit Jalan 2020-07-13 17:36:49 +05:30
parent eb73048b0f
commit ba57dc57cc
6 changed files with 21 additions and 29 deletions

View File

@ -41,10 +41,6 @@ export default Component.extend({
return false; return false;
}, },
groupFinder(term) {
return Group.findAll({ term, ignore_automatic: true });
},
errorMessage: I18n.t("user.invited.invite_link.error"), errorMessage: I18n.t("user.invited.invite_link.error"),
reset() { reset() {
@ -67,9 +63,7 @@ export default Component.extend({
return; return;
} }
const groupNames = this.allGroups const groupIds = this.groupIds;
.filter(g => this.groupIds.includes(g.id))
.map(g => g.name);
const maxRedemptionAllowed = this.maxRedemptionAllowed; const maxRedemptionAllowed = this.maxRedemptionAllowed;
const inviteExpiresAt = this.inviteExpiresAt; const inviteExpiresAt = this.inviteExpiresAt;
const userInvitedController = this.userInvitedShow; const userInvitedController = this.userInvitedShow;
@ -78,7 +72,7 @@ export default Component.extend({
return model return model
.generateMultipleUseInviteLink( .generateMultipleUseInviteLink(
groupNames, groupIds,
maxRedemptionAllowed, maxRedemptionAllowed,
inviteExpiresAt inviteExpiresAt
) )

View File

@ -310,9 +310,7 @@ export default Component.extend({
return; return;
} }
const groupNames = this.allGroups const groupIds = this.groupIds;
.filter(g => this.groupIds.includes(g.id))
.map(g => g.name);
const userInvitedController = this.userInvitedShow; const userInvitedController = this.userInvitedShow;
const model = this.inviteModel; const model = this.inviteModel;
@ -347,7 +345,7 @@ export default Component.extend({
return this.inviteModel return this.inviteModel
.createInvite( .createInvite(
this.emailOrUsername.trim(), this.emailOrUsername.trim(),
groupNames, groupIds,
this.customMessage this.customMessage
) )
.then(result => { .then(result => {
@ -385,7 +383,7 @@ export default Component.extend({
return; return;
} }
const groupNames = this.get("inviteModel.groupNames"); const groupIds = this.groupIds;
const userInvitedController = this.userInvitedShow; const userInvitedController = this.userInvitedShow;
const model = this.inviteModel; const model = this.inviteModel;
model.setProperties({ saving: true, error: false }); model.setProperties({ saving: true, error: false });
@ -396,7 +394,7 @@ export default Component.extend({
} }
return model return model
.generateInviteLink(this.emailOrUsername.trim(), groupNames, topicId) .generateInviteLink(this.emailOrUsername.trim(), groupIds, topicId)
.then(result => { .then(result => {
model.setProperties({ model.setProperties({
saving: false, saving: false,

View File

@ -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`, { return ajax(`/t/${this.id}/invite`, {
type: "POST", 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", { return ajax("/invites/link", {
type: "POST", type: "POST",
data: { email, group_names: groupNames, topic_id: topicId } data: { email, group_ids, topic_id }
}); });
}, },

View File

@ -668,28 +668,28 @@ const User = RestModel.extend({
); );
}, },
createInvite(email, group_names, custom_message) { createInvite(email, group_ids, custom_message) {
return ajax("/invites", { return ajax("/invites", {
type: "POST", 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", { return ajax("/invites/link", {
type: "POST", type: "POST",
data: { email, group_names, topic_id } data: { email, group_ids, topic_id }
}); });
}, },
generateMultipleUseInviteLink( generateMultipleUseInviteLink(
group_names, group_ids,
max_redemptions_allowed, max_redemptions_allowed,
expires_at expires_at
) { ) {
return ajax("/invites/link", { return ajax("/invites/link", {
type: "POST", type: "POST",
data: { group_names, max_redemptions_allowed, expires_at } data: { group_ids, max_redemptions_allowed, expires_at }
}); });
}, },

View File

@ -537,7 +537,7 @@ class Group < ActiveRecord::Base
def self.lookup_groups(group_ids: [], group_names: []) def self.lookup_groups(group_ids: [], group_names: [])
if group_ids.present? 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) group_ids.map!(&:to_i)
groups = Group.where(id: group_ids) if group_ids.present? groups = Group.where(id: group_ids) if group_ids.present?
end end

View File

@ -107,7 +107,7 @@ describe InvitesController do
it "allows admins to invite to groups" do it "allows admins to invite to groups" do
group = Fabricate(:group) group = Fabricate(:group)
sign_in(admin) 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(response.status).to eq(200)
expect(Invite.find_by(email: email).invited_groups.count).to eq(1) expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
end end
@ -118,7 +118,7 @@ describe InvitesController do
user.update!(trust_level: TrustLevel[2]) user.update!(trust_level: TrustLevel[2])
group.add_owner(user) 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(response.status).to eq(200)
expect(Invite.find_by(email: email).invited_groups.count).to eq(1) expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
@ -198,7 +198,7 @@ describe InvitesController do
sign_in(admin) sign_in(admin)
post "/invites/link.json", params: { post "/invites/link.json", params: {
email: email, group_names: group.name email: email, group_ids: [group.id]
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)
@ -245,7 +245,7 @@ describe InvitesController do
post "/invites/link.json", params: { post "/invites/link.json", params: {
max_redemptions_allowed: 5, max_redemptions_allowed: 5,
group_names: group.name group_ids: [group.id]
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)