diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 00:09:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 00:09:48 +0300 |
commit | 3007cf75a9bb55bcac18db7df56117677035d7b3 (patch) | |
tree | 67aa54b888aea5dd5ede2ebb63bae7f3147ee2ef /app/assets/javascripts/invite_members | |
parent | cd40e11c5728c995c62e98091aff43b6e4aecabe (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/invite_members')
3 files changed, 22 insertions, 67 deletions
diff --git a/app/assets/javascripts/invite_members/components/invite_members_modal.vue b/app/assets/javascripts/invite_members/components/invite_members_modal.vue index 23225869636..a9aa0e9b760 100644 --- a/app/assets/javascripts/invite_members/components/invite_members_modal.vue +++ b/app/assets/javascripts/invite_members/components/invite_members_modal.vue @@ -193,46 +193,28 @@ export default { this.invalidFeedbackMessage = ''; const [usersToInviteByEmail, usersToAddById] = this.partitionNewUsersToInvite(); - const promises = []; - const baseData = { + + const apiAddByInvite = this.isProject + ? Api.inviteProjectMembers.bind(Api) + : Api.inviteGroupMembers.bind(Api); + + const email = usersToInviteByEmail !== '' ? { email: usersToInviteByEmail } : {}; + const userId = usersToAddById !== '' ? { user_id: usersToAddById } : {}; + + this.trackinviteMembersForTask(); + + apiAddByInvite(this.id, { format: 'json', expires_at: expiresAt, access_level: accessLevel, invite_source: this.source, tasks_to_be_done: this.tasksToBeDoneForPost, tasks_project_id: this.tasksProjectForPost, - }; - - if (usersToInviteByEmail !== '') { - const apiInviteByEmail = this.isProject - ? Api.inviteProjectMembersByEmail.bind(Api) - : Api.inviteGroupMembersByEmail.bind(Api); - - promises.push( - apiInviteByEmail(this.id, { - ...baseData, - email: usersToInviteByEmail, - }), - ); - } - - if (usersToAddById !== '') { - const apiAddByUserId = this.isProject - ? Api.addProjectMembersByUserId.bind(Api) - : Api.addGroupMembersByUserId.bind(Api); - - promises.push( - apiAddByUserId(this.id, { - ...baseData, - user_id: usersToAddById, - }), - ); - } - this.trackinviteMembersForTask(); - - Promise.all(promises) - .then((responses) => { - const message = responseMessageFromSuccess(responses); + ...email, + ...userId, + }) + .then((response) => { + const message = responseMessageFromSuccess(response); if (message) { this.showInvalidFeedbackMessage({ diff --git a/app/assets/javascripts/invite_members/constants.js b/app/assets/javascripts/invite_members/constants.js index cf2ee508184..3cd0bfc0181 100644 --- a/app/assets/javascripts/invite_members/constants.js +++ b/app/assets/javascripts/invite_members/constants.js @@ -1,4 +1,4 @@ -import { __, s__ } from '~/locale'; +import { s__ } from '~/locale'; export const SEARCH_DELAY = 200; @@ -14,9 +14,6 @@ export const GROUP_FILTERS = { DESCENDANT_GROUPS: 'descendant_groups', }; -export const API_MESSAGES = { - EMAIL_ALREADY_INVITED: __('Invite email has already been taken'), -}; export const USERS_FILTER_ALL = 'all'; export const USERS_FILTER_SAML_PROVIDER_ID = 'saml_provider_id'; export const TRIGGER_ELEMENT_BUTTON = 'button'; diff --git a/app/assets/javascripts/invite_members/utils/response_message_parser.js b/app/assets/javascripts/invite_members/utils/response_message_parser.js index 52ec3be3205..db8ac303dc4 100644 --- a/app/assets/javascripts/invite_members/utils/response_message_parser.js +++ b/app/assets/javascripts/invite_members/utils/response_message_parser.js @@ -1,28 +1,15 @@ import { isString } from 'lodash'; -import { API_MESSAGES } from '~/invite_members/constants'; function responseKeyedMessageParsed(keyedMessage) { try { const keys = Object.keys(keyedMessage); const msg = keyedMessage[keys[0]]; - if (msg === API_MESSAGES.EMAIL_ALREADY_INVITED) { - return ''; - } return msg; } catch { return ''; } } -function responseMessageStringForMultiple(message) { - return message.includes(':'); -} -function responseMessageStringFirstPart(message) { - const firstPart = message.split(':')[1]; - const firstMsg = firstPart.split(/ and [\w-]*$/)[0].trim(); - - return firstMsg; -} export function responseMessageFromError(response) { if (!response?.response?.data) { @@ -33,36 +20,25 @@ export function responseMessageFromError(response) { response: { data }, } = response; - return ( - data.error || - data.message?.user?.[0] || - data.message?.access_level?.[0] || - data.message?.error || - data.message || - '' - ); + return data.error || data.message?.error || data.message || ''; } export function responseMessageFromSuccess(response) { - if (!response?.[0]?.data) { + if (!response?.data) { return ''; } - const { data } = response[0]; + const { data } = response; - if (data.message && !data.message.user) { + if (data.message) { const { message } = data; if (isString(message)) { - if (responseMessageStringForMultiple(message)) { - return responseMessageStringFirstPart(message); - } - return message; } return responseKeyedMessageParsed(message); } - return data.message || data.message?.user || data.error || ''; + return data.error || ''; } |