mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
fix(invites): bogus validation errors
This commit is contained in:
@@ -1,152 +0,0 @@
|
||||
<template lang="pug">
|
||||
b-modal#invite-modal(:title="$t('inviteFriends')", size='lg')
|
||||
.modal-body
|
||||
p.alert.alert-info(v-html="$t('inviteAlertInfo')")
|
||||
.form-horizontal
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
th {{ $t('userId') }}
|
||||
tbody
|
||||
tr(v-for='user in invitees')
|
||||
td
|
||||
input.form-control(type='text', v-model='user.uuid')
|
||||
tr
|
||||
td
|
||||
button.btn.btn-primary.pull-right(@click='addUuid()')
|
||||
i.glyphicon.glyphicon-plus
|
||||
| +
|
||||
tr
|
||||
td
|
||||
.col-6.col-offset-6
|
||||
button.btn.btn-primary.btn-block(@click='inviteNewUsers("uuid")') {{sendInviteText}}
|
||||
hr
|
||||
p.alert.alert-info {{ $t('inviteByEmail') }}
|
||||
.form-horizontal
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
th {{ $t('name') }}
|
||||
th {{ $t('email') }}
|
||||
tbody
|
||||
tr(v-for='email in emails')
|
||||
td
|
||||
input.form-control(type='text', v-model='email.name')
|
||||
td
|
||||
input.form-control(type='email', v-model='email.email')
|
||||
tr
|
||||
td(colspan=2)
|
||||
button.btn.btn-primary.pull-right(@click='addEmail()')
|
||||
i.glyphicon.glyphicon-plus
|
||||
| +
|
||||
tr
|
||||
td.form-group(colspan=2)
|
||||
label.col-sm-1.control-label {{ $t('byColon') }}
|
||||
.col-sm-5
|
||||
input.form-control(type='text', v-model='inviter')
|
||||
.col-sm-6
|
||||
button.btn.btn-primary.btn-block(@click='inviteNewUsers("email")') {{sendInviteText}}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'client/libs/store';
|
||||
|
||||
import filter from 'lodash/filter';
|
||||
import map from 'lodash/map';
|
||||
import notifications from 'client/mixins/notifications';
|
||||
|
||||
export default {
|
||||
mixins: [notifications],
|
||||
props: ['group'],
|
||||
data () {
|
||||
return {
|
||||
invitees: [],
|
||||
emails: [],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState({user: 'user.data'}),
|
||||
inviter () {
|
||||
return this.user.profile.name;
|
||||
},
|
||||
sendInviteText () {
|
||||
return 'Send Invites';
|
||||
// if (!this.group) return 'Send Invites';
|
||||
// return this.group.sendInviteText;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
addUuid () {
|
||||
this.invitees.push({uuid: ''});
|
||||
},
|
||||
addEmail () {
|
||||
this.emails.push({name: '', email: ''});
|
||||
},
|
||||
inviteNewUsers (inviteMethod) {
|
||||
if (!this.group._id) {
|
||||
if (!this.group.name) this.group.name = this.$t('possessiveParty', {name: this.user.profile.name});
|
||||
|
||||
// @TODO: Add dispatch
|
||||
// return Groups.Group.create(this.group)
|
||||
// .then(function(response) {
|
||||
// this.group = response.data.data;
|
||||
// _inviteByMethod(inviteMethod);
|
||||
// });
|
||||
}
|
||||
|
||||
this.inviteByMethod(inviteMethod);
|
||||
},
|
||||
async inviteByMethod (inviteMethod) {
|
||||
let invitationDetails;
|
||||
|
||||
if (inviteMethod === 'email') {
|
||||
let emails = this.getEmails();
|
||||
invitationDetails = { inviter: this.inviter, emails };
|
||||
} else if (inviteMethod === 'uuid') {
|
||||
let uuids = this.getOnlyUuids();
|
||||
invitationDetails = { uuids };
|
||||
} else {
|
||||
return alert('Invalid invite method.');
|
||||
}
|
||||
|
||||
await this.$store.dispatch('guilds:invite', {
|
||||
invitationDetails,
|
||||
groupId: this.group._id,
|
||||
});
|
||||
|
||||
let invitesSent = invitationDetails.emails || invitationDetails.uuids;
|
||||
let invitationString = invitesSent.length > 1 ? 'invitationsSent' : 'invitationSent';
|
||||
|
||||
this.text(this.$t(invitationString));
|
||||
|
||||
this.invitees = [];
|
||||
this.emails = [];
|
||||
|
||||
// @TODO: This function didn't make it over this.resetInvitees();
|
||||
|
||||
// @TODO: Sync group invites?
|
||||
// if (this.group.type === 'party') {
|
||||
// this.$router.push('//party');
|
||||
// } else {
|
||||
// this.$router.push(`/groups/guilds/${this.group._id}`);
|
||||
// }
|
||||
this.$root.$emit('bv::hide::modal', 'invite-modal');
|
||||
// @TODO: error?
|
||||
// _resetInvitees();
|
||||
},
|
||||
getOnlyUuids () {
|
||||
let uuids = map(this.invitees, 'uuid');
|
||||
let filteredUuids = filter(uuids, (id) => {
|
||||
return id !== '';
|
||||
});
|
||||
return filteredUuids;
|
||||
},
|
||||
getEmails () {
|
||||
let emails = filter(this.emails, (obj) => {
|
||||
return obj.email !== '';
|
||||
});
|
||||
return emails;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -164,6 +164,7 @@ export async function invite (store, payload) {
|
||||
let response = await axios.post(`/api/v4/groups/${payload.groupId}/invite`, {
|
||||
uuids: payload.invitationDetails.uuids,
|
||||
emails: payload.invitationDetails.emails,
|
||||
usernames: payload.invitationDetails.usernames,
|
||||
});
|
||||
|
||||
// @TODO: find guild and add invites
|
||||
|
||||
@@ -229,7 +229,7 @@
|
||||
"memberCannotRemoveYourself": "You cannot remove yourself!",
|
||||
"groupMemberNotFound": "User not found among group's members",
|
||||
"mustBeGroupMember": "Must be member of the group.",
|
||||
"canOnlyInviteEmailUuid": "Can only invite using uuids or emails.",
|
||||
"canOnlyInviteEmailUuid": "Can only invite using user IDs, emails, or usernames.",
|
||||
"inviteMissingEmail": "Missing email address in invite.",
|
||||
"inviteMissingUuid": "Missing user id in invite",
|
||||
"inviteMustNotBeEmpty": "Invite must not be empty.",
|
||||
@@ -245,6 +245,7 @@
|
||||
"userHasNoLocalRegistration": "User does not have a local registration (username, email, password).",
|
||||
"uuidsMustBeAnArray": "User ID invites must be an array.",
|
||||
"emailsMustBeAnArray": "Email address invites must be an array.",
|
||||
"usernamesMustBeAnArray": "Username invites must be an array.",
|
||||
"canOnlyInviteMaxInvites": "You can only invite \"<%= maxInvites %>\" at a time",
|
||||
"partyExceedsMembersLimit": "Party size is limited to <%= maxMembersParty %> members",
|
||||
"onlyCreatorOrAdminCanDeleteChat": "Not authorized to delete this message!",
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = function errorHandler (err, req, res, next) { // eslint-disable
|
||||
// Otherwise try to identify the type of error (mongoose validation, mongodb unique, ...)
|
||||
// If we can't identify it, respond with a generic 500 error
|
||||
let responseErr = err instanceof CustomError ? err : null;
|
||||
console.log(err)
|
||||
|
||||
// Handle errors created with 'http-errors' or similar that have a status/statusCode property
|
||||
if (err.statusCode && typeof err.statusCode === 'number') {
|
||||
responseErr = new CustomError();
|
||||
|
||||
@@ -350,7 +350,7 @@ schema.statics.toJSONCleanChat = async function groupToJSONCleanChat (group, use
|
||||
return toJSON;
|
||||
};
|
||||
|
||||
function getIniviteError (uuids, emails, usernames) {
|
||||
function getInviteError (uuids, emails, usernames) {
|
||||
const uuidsIsArray = Array.isArray(uuids);
|
||||
const emailsIsArray = Array.isArray(emails);
|
||||
const usernamesIsArray = Array.isArray(usernames);
|
||||
@@ -366,16 +366,12 @@ function getIniviteError (uuids, emails, usernames) {
|
||||
errorString = 'uuidsMustBeAnArray';
|
||||
} else if (emails && !emailsIsArray) {
|
||||
errorString = 'emailsMustBeAnArray';
|
||||
} else if (!emails && emptyUuids) {
|
||||
errorString = 'inviteMissingUuid';
|
||||
} else if (!uuids && emptyEmails) {
|
||||
errorString = 'inviteMissingEmail';
|
||||
} else if (emptyEmails && emptyUuids) {
|
||||
} else if (usernames && !usernamesIsArray) {
|
||||
errorString = 'usernamesMustBeAnArray';
|
||||
} else if (emptyEmails && emptyUuids && emptyUsernames) {
|
||||
errorString = 'inviteMustNotBeEmpty';
|
||||
}
|
||||
|
||||
if (usernames && emptyUsernames) errorString = 'usernamesMustNotBeEmpty';
|
||||
|
||||
return errorString;
|
||||
}
|
||||
|
||||
@@ -407,8 +403,7 @@ schema.statics.validateInvitations = async function getInvitationError (invites,
|
||||
emails,
|
||||
usernames,
|
||||
} = invites;
|
||||
|
||||
const errorString = getIniviteError(uuids, emails, usernames);
|
||||
const errorString = getInviteError(uuids, emails, usernames);
|
||||
if (errorString) throw new BadRequest(res.t(errorString));
|
||||
|
||||
const totalInvites = getInviteCount(uuids, emails);
|
||||
|
||||
Reference in New Issue
Block a user