1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00

Add username to user

This commit is contained in:
Maksim Eltyshev 2020-04-03 00:35:25 +05:00
parent 1320c697db
commit ce1e1f741d
143 changed files with 1051 additions and 420 deletions

View file

@ -51,6 +51,18 @@ export const clearCurrentUserPasswordUpdateError = () => ({
payload: {},
});
export const updateCurrentUserUsername = (data) => ({
type: EntryActionTypes.CURRENT_USER_USERNAME_UPDATE,
payload: {
data,
},
});
export const clearCurrentUserUsernameUpdateError = () => ({
type: EntryActionTypes.CURRENT_USER_USERNAME_UPDATE_ERROR_CLEAR,
payload: {},
});
export const uploadCurrentUserAvatar = (file) => ({
type: EntryActionTypes.CURRENT_USER_AVATAR_UPLOAD,
payload: {

View file

@ -36,6 +36,13 @@ export const clearUserPasswordUpdateError = (id) => ({
},
});
export const clearUserUsernameUpdateError = (id) => ({
type: ActionTypes.USER_USERNAME_UPDATE_ERROR_CLEAR,
payload: {
id,
},
});
export const deleteUser = (id) => ({
type: ActionTypes.USER_DELETE,
payload: {
@ -202,6 +209,30 @@ export const updateUserPasswordFailed = (id, error) => ({
},
});
export const updateUserUsernameRequested = (id, data) => ({
type: ActionTypes.USER_USERNAME_UPDATE_REQUESTED,
payload: {
id,
data,
},
});
export const updateUserUsernameSucceeded = (id, username) => ({
type: ActionTypes.USER_USERNAME_UPDATE_SUCCEEDED,
payload: {
id,
username,
},
});
export const updateUserUsernameFailed = (id, error) => ({
type: ActionTypes.USER_USERNAME_UPDATE_FAILED,
payload: {
id,
error,
},
});
export const uploadUserAvatarRequested = (id) => ({
type: ActionTypes.USER_AVATAR_UPLOAD_REQUESTED,
payload: {

View file

@ -16,6 +16,9 @@ const updateUserEmail = (id, data, headers) => socket.patch(`/users/${id}/email`
const updateUserPassword = (id, data, headers) =>
socket.patch(`/users/${id}/password`, data, headers);
const updateUserUsername = (id, data, headers) =>
socket.patch(`/users/${id}/username`, data, headers);
const uploadUserAvatar = (id, file, headers) =>
http.post(
`/users/${id}/upload-avatar`,
@ -34,6 +37,7 @@ export default {
updateUser,
updateUserEmail,
updateUserPassword,
updateUserUsername,
uploadUserAvatar,
deleteUser,
};

View file

@ -8,6 +8,7 @@ import { withPopup } from '../../lib/popup';
import { Input, Popup } from '../../lib/custom-ui';
import { useForm } from '../../hooks';
import { isUsername } from '../../utils/validator';
import styles from './AddUserPopup.module.css';
@ -16,17 +17,23 @@ const createMessage = (error) => {
return error;
}
if (error.message === 'User is already exist') {
switch (error.message) {
case 'Email already in use':
return {
type: 'error',
content: 'common.userIsAlreadyExist',
content: 'common.emailAlreadyInUse',
};
}
case 'Username already in use':
return {
type: 'error',
content: 'common.usernameAlreadyInUse',
};
default:
return {
type: 'warning',
content: 'common.unknownError',
};
}
};
const AddUserPopup = React.memo(
@ -38,6 +45,7 @@ const AddUserPopup = React.memo(
email: '',
password: '',
name: '',
username: '',
...defaultData,
}));
@ -46,12 +54,14 @@ const AddUserPopup = React.memo(
const emailField = useRef(null);
const passwordField = useRef(null);
const nameField = useRef(null);
const usernameField = useRef(null);
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
email: data.email.trim(),
name: data.name.trim(),
username: data.username.trim() || null,
};
if (!isEmail(cleanData.email)) {
@ -69,6 +79,11 @@ const AddUserPopup = React.memo(
return;
}
if (cleanData.username && !isUsername(cleanData.username)) {
usernameField.current.select();
return;
}
onCreate(cleanData);
}, [onCreate, data]);
@ -78,10 +93,20 @@ const AddUserPopup = React.memo(
useEffect(() => {
if (wasSubmitting && !isSubmitting) {
if (!error) {
onClose();
} else if (error.message === 'User is already exist') {
if (error) {
switch (error.message) {
case 'Email already in use':
emailField.current.select();
break;
case 'Username already in use':
usernameField.current.select();
break;
default:
}
} else {
onClose();
}
}
}, [isSubmitting, wasSubmitting, error, onClose]);
@ -136,6 +161,22 @@ const AddUserPopup = React.memo(
className={styles.field}
onChange={handleFieldChange}
/>
<div className={styles.text}>
{t('common.username')} (
{t('common.optional', {
context: 'inline',
})}
)
</div>
<Input
fluid
ref={usernameField}
name="username"
value={data.username}
readOnly={isSubmitting}
className={styles.field}
onChange={handleFieldChange}
/>
<Button
positive
content={t('action.addUser')}

View file

@ -18,6 +18,8 @@ const Header = React.memo(
onNotificationDelete,
onUserUpdate,
onUserAvatarUpload,
onUserUsernameUpdate,
onUserUsernameUpdateMessageDismiss,
onUserEmailUpdate,
onUserEmailUpdateMessageDismiss,
onUserPasswordUpdate,
@ -46,12 +48,16 @@ const Header = React.memo(
<UserPopup
email={user.email}
name={user.name}
username={user.username}
avatar={user.avatar}
isAvatarUploading={user.isAvatarUploading}
usernameUpdateForm={user.usernameUpdateForm}
emailUpdateForm={user.emailUpdateForm}
passwordUpdateForm={user.passwordUpdateForm}
onUpdate={onUserUpdate}
onAvatarUpload={onUserAvatarUpload}
onUsernameUpdate={onUserUsernameUpdate}
onUsernameUpdateMessageDismiss={onUserUsernameUpdateMessageDismiss}
onEmailUpdate={onUserEmailUpdate}
onEmailUpdateMessageDismiss={onUserEmailUpdateMessageDismiss}
onPasswordUpdate={onUserPasswordUpdate}
@ -76,6 +82,8 @@ Header.propTypes = {
onNotificationDelete: PropTypes.func.isRequired,
onUserUpdate: PropTypes.func.isRequired,
onUserAvatarUpload: PropTypes.func.isRequired,
onUserUsernameUpdate: PropTypes.func.isRequired,
onUserUsernameUpdateMessageDismiss: PropTypes.func.isRequired,
onUserEmailUpdate: PropTypes.func.isRequired,
onUserEmailUpdateMessageDismiss: PropTypes.func.isRequired,
onUserPasswordUpdate: PropTypes.func.isRequired,

View file

@ -8,6 +8,7 @@ import { useDidUpdate, usePrevious, useToggle } from '../../lib/hooks';
import { Input } from '../../lib/custom-ui';
import { useForm } from '../../hooks';
import { isUsername } from '../../utils/validator';
import styles from './Login.module.css';
@ -17,12 +18,12 @@ const createMessage = (error) => {
}
switch (error.message) {
case 'Email does not exist':
case 'Invalid email or username':
return {
type: 'error',
content: 'common.emailDoesNotExist',
content: 'common.invalidEmailOrUsername',
};
case 'Password is not valid':
case 'Invalid password':
return {
type: 'error',
content: 'common.invalidPassword',
@ -51,7 +52,7 @@ const Login = React.memo(
const wasSubmitting = usePrevious(isSubmitting);
const [data, handleFieldChange, setData] = useForm(() => ({
email: '',
emailOrUsername: '',
password: '',
...defaultData,
}));
@ -59,17 +60,17 @@ const Login = React.memo(
const message = useMemo(() => createMessage(error), [error]);
const [focusPasswordFieldState, focusPasswordField] = useToggle();
const emailField = useRef(null);
const emailOrUsernameField = useRef(null);
const passwordField = useRef(null);
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
email: data.email.trim(),
emailOrUsername: data.emailOrUsername.trim(),
};
if (!isEmail(cleanData.email)) {
emailField.current.select();
if (!isEmail(cleanData.emailOrUsername) && !isUsername(cleanData.emailOrUsername)) {
emailOrUsernameField.current.select();
return;
}
@ -82,17 +83,17 @@ const Login = React.memo(
}, [onAuthenticate, data]);
useEffect(() => {
emailField.current.select();
emailOrUsernameField.current.select();
}, []);
useEffect(() => {
if (wasSubmitting && !isSubmitting && error) {
switch (error.message) {
case 'Email does not exist':
emailField.current.select();
case 'Invalid email or username':
emailOrUsernameField.current.select();
break;
case 'Password is not valid':
case 'Invalid password':
setData((prevData) => ({
...prevData,
password: '',
@ -136,12 +137,12 @@ const Login = React.memo(
)}
<Form size="large" onSubmit={handleSubmit}>
<div className={styles.inputWrapper}>
<div className={styles.inputLabel}>{t('common.email')}</div>
<div className={styles.inputLabel}>{t('common.emailOrUsername')}</div>
<Input
fluid
ref={emailField}
name="email"
value={data.email}
ref={emailOrUsernameField}
name="emailOrUsername"
value={data.emailOrUsername}
readOnly={isSubmitting}
className={styles.input}
onChange={handleFieldChange}

View file

@ -16,12 +16,12 @@ const createMessage = (error) => {
}
switch (error.message) {
case 'User is already exist':
case 'Email already in use':
return {
type: 'error',
content: 'common.userIsAlreadyExist',
content: 'common.emailAlreadyInUse',
};
case 'Current password is not valid':
case 'Invalid current password':
return {
type: 'error',
content: 'common.invalidCurrentPassword',
@ -83,11 +83,11 @@ const EditEmailStep = React.memo(
if (wasSubmitting && !isSubmitting) {
if (error) {
switch (error.message) {
case 'User is already exist':
case 'Email already in use':
emailField.current.select();
break;
case 'Current password is not valid':
case 'Invalid current password':
setData((prevData) => ({
...prevData,
currentPassword: '',

View file

@ -15,7 +15,7 @@ const createMessage = (error) => {
}
switch (error.message) {
case 'Current password is not valid':
case 'Invalid current password':
return {
type: 'error',
content: 'common.invalidCurrentPassword',
@ -67,7 +67,7 @@ const EditPasswordStep = React.memo(
if (wasSubmitting && !isSubmitting) {
if (!error) {
onClose();
} else if (error.message === 'Current password is not valid') {
} else if (error.message === 'Invalid current password') {
setData((prevData) => ({
...prevData,
currentPassword: '',

View file

@ -0,0 +1,182 @@
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { Button, Form, Message } from 'semantic-ui-react';
import { useDidUpdate, usePrevious, useToggle } from '../../lib/hooks';
import { Input, Popup } from '../../lib/custom-ui';
import { useForm } from '../../hooks';
import { isUsername } from '../../utils/validator';
import styles from './EditUsernameStep.module.css';
const createMessage = (error) => {
if (!error) {
return error;
}
switch (error.message) {
case 'Username already in use':
return {
type: 'error',
content: 'common.usernameAlreadyInUse',
};
case 'Invalid current password':
return {
type: 'error',
content: 'common.invalidCurrentPassword',
};
default:
return {
type: 'warning',
content: 'common.unknownError',
};
}
};
const EditUsernameStep = React.memo(
({ defaultData, username, isSubmitting, error, onUpdate, onMessageDismiss, onBack, onClose }) => {
const [t] = useTranslation();
const wasSubmitting = usePrevious(isSubmitting);
const [data, handleFieldChange, setData] = useForm({
username: '',
currentPassword: '',
...defaultData,
});
const message = useMemo(() => createMessage(error), [error]);
const [focusCurrentPasswordFieldState, focusCurrentPasswordField] = useToggle();
const usernameField = useRef(null);
const currentPasswordField = useRef(null);
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
username: data.username.trim() || null,
};
if (cleanData.username && !isUsername(cleanData.username)) {
usernameField.current.select();
return;
}
if (cleanData.username === username) {
onClose();
return;
}
if (!cleanData.currentPassword) {
currentPasswordField.current.focus();
return;
}
onUpdate(cleanData);
}, [username, onUpdate, onClose, data]);
useEffect(() => {
usernameField.current.select();
}, []);
useEffect(() => {
if (wasSubmitting && !isSubmitting) {
if (error) {
switch (error.message) {
case 'Username already in use':
usernameField.current.select();
break;
case 'Invalid current password':
setData((prevData) => ({
...prevData,
currentPassword: '',
}));
focusCurrentPasswordField();
break;
default:
}
} else {
onClose();
}
}
}, [isSubmitting, wasSubmitting, error, onClose, setData, focusCurrentPasswordField]);
useDidUpdate(() => {
currentPasswordField.current.focus();
}, [focusCurrentPasswordFieldState]);
return (
<>
<Popup.Header onBack={onBack}>
{t('common.editUsername', {
context: 'title',
})}
</Popup.Header>
<Popup.Content>
{message && (
<Message
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
[message.type]: true,
}}
visible
content={t(message.content)}
onDismiss={onMessageDismiss}
/>
)}
<Form onSubmit={handleSubmit}>
<div className={styles.text}>{t('common.newUsername')}</div>
<Input
fluid
ref={usernameField}
name="username"
value={data.username}
placeholder={username}
className={styles.field}
onChange={handleFieldChange}
/>
{data.username.trim() !== (username || '') && (
<>
<div className={styles.text}>{t('common.currentPassword')}</div>
<Input.Password
fluid
ref={currentPasswordField}
name="currentPassword"
value={data.currentPassword}
className={styles.field}
onChange={handleFieldChange}
/>
</>
)}
<Button
positive
content={t('action.save')}
loading={isSubmitting}
disabled={isSubmitting}
/>
</Form>
</Popup.Content>
</>
);
},
);
EditUsernameStep.propTypes = {
defaultData: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
username: PropTypes.string,
isSubmitting: PropTypes.bool.isRequired,
error: PropTypes.object, // eslint-disable-line react/forbid-prop-types
onUpdate: PropTypes.func.isRequired,
onMessageDismiss: PropTypes.func.isRequired,
onBack: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
};
EditUsernameStep.defaultProps = {
username: undefined,
error: undefined,
};
export default EditUsernameStep;

View file

@ -0,0 +1,10 @@
.field {
margin-bottom: 8px;
}
.text {
color: #444444;
font-size: 12px;
font-weight: bold;
padding-bottom: 6px;
}

View file

@ -7,6 +7,7 @@ import { Popup } from '../../lib/custom-ui';
import { useSteps } from '../../hooks';
import EditNameStep from './EditNameStep';
import EditUsernameStep from './EditUsernameStep';
import EditAvatarStep from './EditAvatarStep';
import EditEmailStep from './EditEmailStep';
import EditPasswordStep from './EditPasswordStep';
@ -15,6 +16,7 @@ import styles from './UserPopup.module.css';
const StepTypes = {
EDIT_NAME: 'EDIT_NAME',
EDIT_USERNAME: 'EDIT_USERNAME',
EDIT_AVATAR: 'EDIT_AVATAR',
EDIT_EMAIL: 'EDIT_EMAIL',
EDIT_PASSWORD: 'EDIT_PASSWORD',
@ -24,12 +26,16 @@ const UserStep = React.memo(
({
email,
name,
username,
avatar,
isAvatarUploading,
usernameUpdateForm,
emailUpdateForm,
passwordUpdateForm,
onUpdate,
onAvatarUpload,
onUsernameUpdate,
onUsernameUpdateMessageDismiss,
onEmailUpdate,
onEmailUpdateMessageDismiss,
onPasswordUpdate,
@ -48,6 +54,10 @@ const UserStep = React.memo(
openStep(StepTypes.EDIT_AVATAR);
}, [openStep]);
const handleUsernameEditClick = useCallback(() => {
openStep(StepTypes.EDIT_USERNAME);
}, [openStep]);
const handleEmailEditClick = useCallback(() => {
openStep(StepTypes.EDIT_EMAIL);
}, [openStep]);
@ -93,6 +103,19 @@ const UserStep = React.memo(
onBack={handleBack}
/>
);
case StepTypes.EDIT_USERNAME:
return (
<EditUsernameStep
defaultData={usernameUpdateForm.data}
username={username}
isSubmitting={usernameUpdateForm.isSubmitting}
error={usernameUpdateForm.error}
onUpdate={onUsernameUpdate}
onMessageDismiss={onUsernameUpdateMessageDismiss}
onBack={handleBack}
onClose={onClose}
/>
);
case StepTypes.EDIT_EMAIL:
return (
<EditEmailStep
@ -124,7 +147,11 @@ const UserStep = React.memo(
return (
<>
<Popup.Header>{name}</Popup.Header>
<Popup.Header>
{t('common.userActions', {
context: 'title',
})}
</Popup.Header>
<Popup.Content>
<Menu secondary vertical className={styles.menu}>
<Menu.Item className={styles.menuItem} onClick={handleNameEditClick}>
@ -137,6 +164,11 @@ const UserStep = React.memo(
context: 'title',
})}
</Menu.Item>
<Menu.Item className={styles.menuItem} onClick={handleUsernameEditClick}>
{t('action.editUsername', {
context: 'title',
})}
</Menu.Item>
<Menu.Item className={styles.menuItem} onClick={handleEmailEditClick}>
{t('action.editEmail', {
context: 'title',
@ -162,14 +194,18 @@ const UserStep = React.memo(
UserStep.propTypes = {
email: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
username: PropTypes.string,
avatar: PropTypes.string,
isAvatarUploading: PropTypes.bool.isRequired,
/* eslint-disable react/forbid-prop-types */
usernameUpdateForm: PropTypes.object.isRequired,
emailUpdateForm: PropTypes.object.isRequired,
passwordUpdateForm: PropTypes.object.isRequired,
/* eslint-enable react/forbid-prop-types */
onUpdate: PropTypes.func.isRequired,
onAvatarUpload: PropTypes.func.isRequired,
onUsernameUpdate: PropTypes.func.isRequired,
onUsernameUpdateMessageDismiss: PropTypes.func.isRequired,
onEmailUpdate: PropTypes.func.isRequired,
onEmailUpdateMessageDismiss: PropTypes.func.isRequired,
onPasswordUpdate: PropTypes.func.isRequired,
@ -179,6 +215,7 @@ UserStep.propTypes = {
};
UserStep.defaultProps = {
username: undefined,
avatar: undefined,
};

View file

@ -7,7 +7,7 @@ import DeletePopup from '../DeletePopup';
import styles from './Item.module.css';
const Item = React.memo(({ name, email, isAdmin, onUpdate, onDelete }) => {
const Item = React.memo(({ name, username, email, isAdmin, onUpdate, onDelete }) => {
const [t] = useTranslation();
const handleIsAdminChange = useCallback(() => {
@ -19,6 +19,7 @@ const Item = React.memo(({ name, email, isAdmin, onUpdate, onDelete }) => {
return (
<Table.Row>
<Table.Cell>{name}</Table.Cell>
<Table.Cell>{username || '-'}</Table.Cell>
<Table.Cell>{email}</Table.Cell>
<Table.Cell collapsing>
<Radio toggle checked={isAdmin} onChange={handleIsAdminChange} />
@ -41,10 +42,15 @@ const Item = React.memo(({ name, email, isAdmin, onUpdate, onDelete }) => {
Item.propTypes = {
name: PropTypes.string.isRequired,
username: PropTypes.string,
email: PropTypes.string.isRequired,
isAdmin: PropTypes.bool.isRequired,
onUpdate: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
};
Item.defaultProps = {
username: undefined,
};
export default Item;

View file

@ -34,8 +34,9 @@ const UsersModal = React.memo(({ items, onUpdate, onDelete, onClose }) => {
<Table basic="very">
<Table.Header>
<Table.Row>
<Table.HeaderCell>{t('common.name')}</Table.HeaderCell>
<Table.HeaderCell>{t('common.email')}</Table.HeaderCell>
<Table.HeaderCell width={4}>{t('common.name')}</Table.HeaderCell>
<Table.HeaderCell width={4}>{t('common.username')}</Table.HeaderCell>
<Table.HeaderCell width={4}>{t('common.email')}</Table.HeaderCell>
<Table.HeaderCell>{t('common.administrator')}</Table.HeaderCell>
<Table.HeaderCell />
</Table.Row>
@ -45,6 +46,7 @@ const UsersModal = React.memo(({ items, onUpdate, onDelete, onClose }) => {
<Item
key={item.id}
name={item.name}
username={item.username}
email={item.email}
isAdmin={item.isAdmin}
onUpdate={(data) => handleUpdate(item.id, data)}

View file

@ -34,6 +34,7 @@ export default {
USER_UPDATE: 'USER_UPDATE',
USER_EMAIL_UPDATE_ERROR_CLEAR: 'USER_EMAIL_UPDATE_ERROR_CLEAR',
USER_PASSWORD_UPDATE_ERROR_CLEAR: 'USER_PASSWORD_UPDATE_ERROR_CLEAR',
USER_USERNAME_UPDATE_ERROR_CLEAR: 'USER_USERNAME_UPDATE_ERROR_CLEAR',
USER_DELETE: 'USER_DELETE',
USER_TO_CARD_ADD: 'USER_TO_CARD_ADD',
USER_FROM_CARD_REMOVE: 'USER_FROM_CARD_REMOVE',
@ -56,6 +57,9 @@ export default {
USER_PASSWORD_UPDATE_REQUESTED: 'USER_PASSWORD_UPDATE_REQUESTED',
USER_PASSWORD_UPDATE_SUCCEEDED: 'USER_PASSWORD_UPDATE_SUCCEEDED',
USER_PASSWORD_UPDATE_FAILED: 'USER_PASSWORD_UPDATE_FAILED',
USER_USERNAME_UPDATE_REQUESTED: 'USER_USERNAME_UPDATE_REQUESTED',
USER_USERNAME_UPDATE_SUCCEEDED: 'USER_USERNAME_UPDATE_SUCCEEDED',
USER_USERNAME_UPDATE_FAILED: 'USER_USERNAME_UPDATE_FAILED',
USER_AVATAR_UPLOAD_REQUESTED: 'USER_AVATAR_UPLOAD_REQUESTED',
USER_AVATAR_UPLOAD_SUCCEEDED: 'USER_AVATAR_UPLOAD_SUCCEEDED',
USER_AVATAR_UPLOAD_FAILED: 'USER_AVATAR_UPLOAD_FAILED',

View file

@ -24,6 +24,8 @@ export default {
CURRENT_USER_EMAIL_UPDATE_ERROR_CLEAR: `${PREFIX}/CURRENT_USER_EMAIL_UPDATE_ERROR_CLEAR`,
CURRENT_USER_PASSWORD_UPDATE: `${PREFIX}/CURRENT_USER_PASSWORD_UPDATE`,
CURRENT_USER_PASSWORD_UPDATE_ERROR_CLEAR: `${PREFIX}/CURRENT_USER_PASSWORD_UPDATE_ERROR_CLEAR`,
CURRENT_USER_USERNAME_UPDATE: `${PREFIX}/CURRENT_USER_USERNAME_UPDATE`,
CURRENT_USER_USERNAME_UPDATE_ERROR_CLEAR: `${PREFIX}/CURRENT_USER_USERNAME_UPDATE_ERROR_CLEAR`,
CURRENT_USER_AVATAR_UPLOAD: `${PREFIX}/CURRENT_USER_AVATAR_UPLOAD`,
USER_DELETE: `${PREFIX}/USER_DELETE`,
USER_TO_CARD_ADD: `${PREFIX}/USER_TO_CARD_ADD`,

View file

@ -5,12 +5,14 @@ import { currentUserSelector, notificationsForCurrentUserSelector } from '../sel
import {
clearCurrentUserEmailUpdateError,
clearCurrentUserPasswordUpdateError,
clearCurrentUserUsernameUpdateError,
deleteNotification,
logout,
openUsersModal,
updateCurrentUser,
updateCurrentUserEmail,
updateCurrentUserPassword,
updateCurrentUserUsername,
uploadCurrentUserAvatar,
} from '../actions/entry';
import Header from '../components/Header';
@ -33,6 +35,8 @@ const mapDispatchToProps = (dispatch) =>
onNotificationDelete: deleteNotification,
onUserUpdate: updateCurrentUser,
onUserAvatarUpload: uploadCurrentUserAvatar,
onUserUsernameUpdate: updateCurrentUserUsername,
onUserUsernameUpdateMessageDismiss: clearCurrentUserUsernameUpdateError,
onUserEmailUpdate: updateCurrentUserEmail,
onUserEmailUpdateMessageDismiss: clearCurrentUserEmailUpdateError,
onUserPasswordUpdate: updateCurrentUserPassword,

View file

@ -58,6 +58,9 @@ export default {
editPassword_title: 'Edit Password',
editProject_title: 'Edit Project',
editTimer_title: 'Edit Timer',
editUsername_title: 'Edit Username',
email: 'E-mail',
emailAlreadyInUse: 'E-mail already in use',
enterCardTitle: 'Enter card title...',
enterDescription: 'Enter description...',
enterListTitle: 'Enter list title...',
@ -74,10 +77,12 @@ export default {
name: 'Name',
newEmail: 'New e-mail',
newPassword: 'New password',
newUsername: 'New username',
noConnectionToServer: 'No connection to server',
notifications: 'Notifications',
noUnreadNotifications: 'No unread notifications',
openBoard_title: 'Open Board',
optional_inline: 'optional',
projectNotFound_title: 'Project Not Found',
refreshPageToLoadLastDataAndReceiveUpdates:
'<0>Refresh the page</0> to load last data<br />and receive updates',
@ -88,12 +93,14 @@ export default {
time: 'Time',
timer: 'Timer',
title: 'Title',
userActions_title: 'User Actions',
userAddedThisCardToList: '<0>{{user}}</0><1> added this card to {{list}}</1>',
userIsAlreadyExist: 'User is already exist',
userLeftNewCommentToCard: '{{user}} left a new comment «{{comment}}» to <2>{{card}}</2>',
userMovedCardFromListToList: '{{user}} moved <2>{{card}}</2> from {{fromList}} to {{toList}}',
userMovedThisCardFromListToList:
'<0>{{user}}</0><1> moved this card from {{fromList}} to {{toList}}</1>',
username: 'Username',
usernameAlreadyInUse: 'Username already in use',
users: 'Users',
writeComment: 'Write a comment...',
},
@ -137,6 +144,7 @@ export default {
editTask_title: 'Edit Task',
editTimer_title: 'Edit Timer',
editTitle_title: 'Edit Title',
editUsername_title: 'Edit Username',
logOut_title: 'Log Out',
remove: 'Remove',
removeFromProject: 'Remove from project',

View file

@ -1,8 +1,8 @@
export default {
translation: {
common: {
email: 'E-mail',
emailDoesNotExist: 'E-mail does not exist',
emailOrUsername: 'E-mail or username',
invalidEmailOrUsername: 'Invalid e-mail or username',
invalidPassword: 'Invalid password',
logInToPlanka: 'Log in to Planka',
noInternetConnection: 'No internet connection',

View file

@ -62,6 +62,9 @@ export default {
editPassword: 'Изменение пароля',
editProject: 'Изменение проекта',
editTimer: 'Изменение таймера',
editUsername: 'Изменение имени пользователя',
email: 'E-mail',
emailAlreadyInUse: 'E-mail уже занят',
enterCardTitle: 'Введите заголовок для этой карточки...',
enterDescription: 'Введите описание...',
enterListTitle: 'Введите заголовок списка...',
@ -78,10 +81,12 @@ export default {
name: 'Имя',
newEmail: 'Новый e-mail',
newPassword: 'Новый пароль',
newUsername: 'Новое имя пользователя',
noConnectionToServer: 'Нет соединения с сервером',
notifications: 'Уведомления',
noUnreadNotifications: 'Уведомлений нет',
openBoard: 'Откройте доску',
optional_inline: 'необязательно',
projectNotFound: 'Доска не найдена',
refreshPageToLoadLastDataAndReceiveUpdates:
'<0>Обновите страницу</0>, чтобы загрузить<br />актуальные данные и получать обновления',
@ -92,13 +97,15 @@ export default {
time: 'Время',
timer: 'Таймер',
title: 'Название',
userActions_title: 'Действия с пользователем',
userAddedThisCardToList: '<0>{{user}}</0><1> добавил(а) эту карточку в {{list}}</1>',
userIsAlreadyExist: 'Пользователь уже существует',
userLeftNewCommentToCard: '{{user}} оставил(а) комментарий «{{comment}}» к <2>{{card}}</2>',
userMovedCardFromListToList:
'{{user}} переместил(а) <2>{{card}}</2> из {{fromList}} в {{toList}}',
userMovedThisCardFromListToList:
'<0>{{user}}</0><1> переместил(а) эту карточку из {{fromList}} в {{toList}}</1>',
username: 'Имя пользователя',
usernameAlreadyInUse: 'Имя пользователя уже занято',
users: 'Пользователи',
writeComment: 'Напишите комментарий...',
},
@ -138,6 +145,7 @@ export default {
editTask: 'Изменить задачу',
editTimer: 'Изменить таймер',
editTitle: 'Изменить название',
editUsername_title: 'Изменить имя пользователя',
logOut: 'Выйти',
remove: 'Убрать',
removeFromProject: 'Удалить из проекта',

View file

@ -1,8 +1,8 @@
export default {
translation: {
common: {
email: 'E-mail',
emailDoesNotExist: 'Неверный e-mail',
emailOrUsername: 'E-mail или имя пользователя',
invalidEmailOrUsername: 'Неверный e-mail или имя пользователя',
invalidPassword: 'Неверный пароль',
logInToPlanka: 'Вход в Planka',
noInternetConnection: 'Нет соединения',

View file

@ -20,6 +20,15 @@ const DEFAULT_PASSWORD_UPDATE_FORM = {
error: null,
};
const DEFAULT_USERNAME_UPDATE_FORM = {
data: {
username: '',
currentPassword: '',
},
isSubmitting: false,
error: null,
};
export default class extends Model {
static modelName = 'User';
@ -41,6 +50,9 @@ export default class extends Model {
passwordUpdateForm: attr({
getDefault: () => DEFAULT_PASSWORD_UPDATE_FORM,
}),
usernameUpdateForm: attr({
getDefault: () => DEFAULT_USERNAME_UPDATE_FORM,
}),
};
static reducer({ type, payload }, User) {
@ -92,6 +104,18 @@ export default class extends Model {
break;
}
case ActionTypes.USER_USERNAME_UPDATE_ERROR_CLEAR: {
const userModel = User.withId(payload.id);
userModel.update({
usernameUpdateForm: {
...userModel.usernameUpdateForm,
error: null,
},
});
break;
}
case ActionTypes.USER_DELETE:
User.withId(payload.id).deleteWithRelated();
@ -167,6 +191,40 @@ export default class extends Model {
break;
}
case ActionTypes.USER_USERNAME_UPDATE_REQUESTED: {
const userModel = User.withId(payload.id);
userModel.update({
usernameUpdateForm: {
...userModel.usernameUpdateForm,
data: payload.data,
isSubmitting: true,
},
});
break;
}
case ActionTypes.USER_USERNAME_UPDATE_SUCCEEDED: {
User.withId(payload.id).update({
username: payload.username,
usernameUpdateForm: DEFAULT_USERNAME_UPDATE_FORM,
});
break;
}
case ActionTypes.USER_USERNAME_UPDATE_FAILED: {
const userModel = User.withId(payload.id);
userModel.update({
usernameUpdateForm: {
...userModel.usernameUpdateForm,
isSubmitting: false,
error: payload.error,
},
});
break;
}
case ActionTypes.USER_AVATAR_UPLOAD_REQUESTED:
User.withId(payload.id).update({
isAvatarUploading: true,

View file

@ -2,7 +2,7 @@ import ActionTypes from '../../constants/ActionTypes';
const initialState = {
data: {
email: '',
emailOrUsername: '',
password: '',
},
isSubmitting: false,

View file

@ -4,6 +4,7 @@ const initialState = {
data: {
email: '',
name: '',
username: '',
},
isSubmitting: false,
error: null,

View file

@ -20,6 +20,9 @@ import {
updateUserPasswordSucceeded,
updateUserRequested,
updateUserSucceeded,
updateUserUsernameFailed,
updateUserUsernameRequested,
updateUserUsernameSucceeded,
uploadUserAvatarFailed,
uploadUserAvatarRequested,
uploadUserAvatarSucceeded,
@ -146,6 +149,30 @@ export function* updateUserPasswordRequest(id, data) {
}
}
export function* updateUserUsernameRequest(id, data) {
yield put(updateUserUsernameRequested(id, data));
try {
const { item } = yield call(request, api.updateUserUsername, id, data);
const action = updateUserUsernameSucceeded(id, item);
yield put(action);
return {
success: true,
payload: action.payload,
};
} catch (error) {
const action = updateUserUsernameFailed(id, error);
yield put(action);
return {
success: false,
payload: action.payload,
};
}
}
export function* uploadUserAvatarRequest(id, file) {
yield put(uploadUserAvatarRequested(id));

View file

@ -8,6 +8,7 @@ import {
updateUserEmailRequest,
updateUserPasswordRequest,
updateUserRequest,
updateUserUsernameRequest,
uploadUserAvatarRequest,
} from '../requests';
import { currentUserIdSelector, pathSelector } from '../../../selectors';
@ -17,6 +18,7 @@ import {
clearUserCreateError,
clearUserEmailUpdateError,
clearUserPasswordUpdateError,
clearUserUsernameUpdateError,
createUser,
deleteUser,
updateUser,
@ -84,6 +86,26 @@ export function* clearCurrentUserPasswordUpdateErrorService() {
yield call(clearUserPasswordUpdateErrorService, id);
}
export function* updateUserUsernameService(id, data) {
yield call(updateUserUsernameRequest, id, data);
}
export function* updateCurrentUserUsernameService(data) {
const id = yield select(currentUserIdSelector);
yield call(updateUserUsernameService, id, data);
}
export function* clearUserUsernameUpdateErrorService(id) {
yield put(clearUserUsernameUpdateError(id));
}
export function* clearCurrentUserUsernameUpdateErrorService() {
const id = yield select(currentUserIdSelector);
yield call(clearUserUsernameUpdateErrorService, id);
}
export function* uploadUserAvatarService(id, file) {
yield call(uploadUserAvatarRequest, id, file);
}

View file

@ -6,6 +6,7 @@ import {
addUserToFilterInCurrentBoardService,
clearCurrentUserEmailUpdateErrorService,
clearCurrentUserPasswordUpdateErrorService,
clearCurrentUserUsernameUpdateErrorService,
clearUserCreateErrorService,
createUserService,
deleteUserService,
@ -16,6 +17,7 @@ import {
updateCurrentUserEmailService,
updateCurrentUserPasswordService,
updateCurrentUserService,
updateCurrentUserUsernameService,
uploadCurrentUserAvatarService,
} from '../services';
import EntryActionTypes from '../../../constants/EntryActionTypes';
@ -42,6 +44,12 @@ export default function* () {
takeLatest(EntryActionTypes.CURRENT_USER_PASSWORD_UPDATE_ERROR_CLEAR, () =>
clearCurrentUserPasswordUpdateErrorService(),
),
takeLatest(EntryActionTypes.CURRENT_USER_USERNAME_UPDATE, ({ payload: { data } }) =>
updateCurrentUserUsernameService(data),
),
takeLatest(EntryActionTypes.CURRENT_USER_USERNAME_UPDATE_ERROR_CLEAR, () =>
clearCurrentUserUsernameUpdateErrorService(),
),
takeLatest(EntryActionTypes.CURRENT_USER_AVATAR_UPLOAD, ({ payload: { file } }) =>
uploadCurrentUserAvatarService(file),
),

View file

@ -0,0 +1,6 @@
const USERNAME_REGEX = /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/;
// eslint-disable-next-line import/prefer-default-export
export const isUsername = (string) => {
return string.length >= 3 && string.length <= 16 && USERNAME_REGEX.test(string);
};

View file

@ -1,20 +1,24 @@
const bcrypt = require('bcrypt');
const validator = require('validator');
const Errors = {
EMAIL_NOT_EXIST: {
unauthorized: 'Email does not exist',
INVALID_EMAIL_OR_USERNAME: {
invalidEmailOrUsername: 'Invalid email or username',
},
PASSWORD_NOT_VALID: {
unauthorized: 'Password is not valid',
INVALID_PASSWORD: {
invalidPassword: 'Invalid password',
},
};
module.exports = {
inputs: {
email: {
emailOrUsername: {
type: 'string',
custom: (value) =>
value.includes('@')
? validator.isEmail(value)
: value.length >= 3 && value.length <= 16 && /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/.test(value),
required: true,
isEmail: true,
},
password: {
type: 'string',
@ -23,22 +27,23 @@ module.exports = {
},
exits: {
unauthorized: {
invalidEmailOrUsername: {
responseType: 'unauthorized',
},
invalidPassword: {
responseType: 'unauthorized',
},
},
async fn(inputs, exits) {
const user = await sails.helpers.getUser({
email: inputs.email.toLowerCase(),
});
const user = await sails.helpers.getUserByEmailOrUsername(inputs.emailOrUsername);
if (!user) {
throw Errors.EMAIL_NOT_EXIST;
throw Errors.INVALID_EMAIL_OR_USERNAME;
}
if (!bcrypt.compareSync(inputs.password, user.password)) {
throw Errors.PASSWORD_NOT_VALID;
throw Errors.INVALID_PASSWORD;
}
return exits.success({

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -28,7 +28,7 @@ module.exports = {
const { project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -22,7 +22,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -29,7 +29,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -64,7 +64,7 @@ module.exports = {
{},
);
cards.map(card => ({
cards.map((card) => ({
...card,
isSubscribed: isSubscribedByCardId[card.id] || false,
}));

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,12 +1,12 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
CARD_LABEL_EXIST: {
conflict: 'Card label is already exist',
LABEL_ALREADY_IN_CARD: {
labelAlreadyInCard: 'Label already in card',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
conflict: {
labelNotFound: {
responseType: 'notFound',
},
labelAlreadyInCard: {
responseType: 'conflict',
},
},
@ -38,7 +41,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -60,7 +63,7 @@ module.exports = {
const cardLabel = await sails.helpers
.createCardLabel(card, label, this.req)
.intercept('conflict', () => Errors.CARD_LABEL_EXIST);
.intercept('labelAlreadyInCard', () => Errors.LABEL_ALREADY_IN_CARD);
return exits.success({
item: cardLabel,

View file

@ -1,9 +1,9 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
CARD_LABEL_NOT_FOUND: {
notFound: 'Card label is not found',
LABEL_NOT_IN_CARD: {
labelNotInCard: 'Label not in card',
},
};
@ -22,7 +22,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
labelNotInCard: {
responseType: 'notFound',
},
},
@ -32,7 +35,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -49,13 +52,13 @@ module.exports = {
});
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
throw Errors.LABEL_NOT_IN_CARD;
}
cardLabel = await sails.helpers.deleteCardLabel(cardLabel, board, this.req);
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
throw Errors.LABEL_NOT_IN_CARD;
}
return exits.success({

View file

@ -1,12 +1,12 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CARD_MEMBERSHIP_EXIST: {
conflict: 'Card membership is already exist',
USER_ALREADY_CARD_MEMBER: {
userAlreadyCardMember: 'User already card member',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
conflict: {
userNotFound: {
responseType: 'notFound',
},
userAlreadyCardMember: {
responseType: 'conflict',
},
},
@ -38,7 +41,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -57,7 +60,7 @@ module.exports = {
const cardMembership = await sails.helpers
.createCardMembership(card, inputs.userId, this.req)
.intercept('conflict', () => Errors.CARD_MEMBERSHIP_EXIST);
.intercept('userAlreadyCardMember', () => Errors.USER_ALREADY_CARD_MEMBER);
return exits.success({
item: cardMembership,

View file

@ -1,9 +1,9 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
CARD_MEMBERSHIP_NOT_FOUND: {
notFound: 'Card membership is not found',
USER_NOT_CARD_MEMBER: {
userNotCardMember: 'User not card member',
},
};
@ -22,7 +22,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
userNotCardMember: {
responseType: 'notFound',
},
},
@ -32,7 +35,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -49,13 +52,13 @@ module.exports = {
});
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
throw Errors.USER_NOT_CARD_MEMBER;
}
cardMembership = await sails.helpers.deleteCardMembership(cardMembership, board, this.req);
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
throw Errors.USER_NOT_CARD_MEMBER;
}
return exits.success({

View file

@ -2,7 +2,7 @@ const moment = require('moment');
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -28,11 +28,11 @@ module.exports = {
},
dueDate: {
type: 'string',
custom: value => moment(value, moment.ISO_8601, true).isValid(),
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
},
timer: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
@ -41,7 +41,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -51,7 +51,7 @@ module.exports = {
const { list, project } = await sails.helpers
.getListToProjectPath(inputs.listId)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { project } = cardToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -2,10 +2,10 @@ const moment = require('moment');
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -34,12 +34,12 @@ module.exports = {
},
dueDate: {
type: 'string',
custom: value => moment(value, moment.ISO_8601, true).isValid(),
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
allowNull: true,
},
timer: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
@ -51,7 +51,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
listNotFound: {
responseType: 'notFound',
},
},
@ -61,7 +64,7 @@ module.exports = {
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { list, project } = cardToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -28,7 +28,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found',
commentActionNotFound: 'Comment action not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
commentActionNotFound: {
responseType: 'notFound',
},
},
@ -33,7 +33,7 @@ module.exports = {
const actionToProjectPath = await sails.helpers
.getActionToProjectPath(criteria)
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found',
commentActionNotFound: 'Comment action not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
commentActionNotFound: {
responseType: 'notFound',
},
},
@ -32,7 +32,7 @@ module.exports = {
type: 'commentCard',
userId: currentUser.id,
})
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -24,7 +24,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -34,7 +34,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.boardId)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
labelNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
};
@ -24,7 +24,7 @@ module.exports = {
},
exits: {
notFound: {
labelNotFound: {
responseType: 'notFound',
},
},
@ -34,7 +34,7 @@ module.exports = {
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -22,7 +22,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -32,7 +32,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.boardId)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;

View file

@ -10,12 +10,6 @@ module.exports = {
},
},
exits: {
notFound: {
responseType: 'notFound',
},
},
async fn(inputs, exits) {
const { currentUser } = this.req;

View file

@ -1,12 +1,12 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
PROJECT_MEMBERSHIP_EXIST: {
conflict: 'Project membership is already exist',
USER_ALREADY_PROJECT_MEMBER: {
userAlreadyProjectMember: 'User already project member',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
conflict: {
userNotFound: {
responseType: 'notFound',
},
userAlreadyProjectMember: {
responseType: 'conflict',
},
},
@ -48,7 +51,7 @@ module.exports = {
const projectMembership = await sails.helpers
.createProjectMembership(project, user, this.req)
.intercept('conflict', () => Errors.PROJECT_MEMBERSHIP_EXIST);
.intercept('userAlreadyProjectMember', () => Errors.USER_ALREADY_PROJECT_MEMBER);
return exits.success({
item: projectMembership,

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_MEMBERSHIP_NOT_FOUND: {
notFound: 'Project membership is not found',
projectMembershipNotFound: 'Project membership not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
projectMembershipNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found',
taskNotFound: 'Task not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
taskNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found',
taskNotFound: 'Task not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
taskNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;

View file

@ -1,6 +1,9 @@
const Errors = {
USER_EXIST: {
conflict: 'User is already exist',
EMAIL_ALREADY_IN_USE: {
emailAlreadyInUse: 'Email already in use',
},
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
};
@ -19,20 +22,32 @@ module.exports = {
type: 'string',
required: true,
},
username: {
type: 'string',
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
allowNull: true,
},
},
exits: {
conflict: {
emailAlreadyInUse: {
responseType: 'conflict',
},
usernameAlreadyInUse: {
responseType: 'conflict',
},
},
async fn(inputs, exits) {
const values = _.pick(inputs, ['email', 'password', 'name']);
const values = _.pick(inputs, ['email', 'password', 'name', 'username']);
const user = await sails.helpers
.createUser(values, this.req)
.intercept('conflict', () => Errors.USER_EXIST);
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
return exits.success({
item: user,

View file

@ -1,6 +1,6 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
},

View file

@ -2,13 +2,13 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid',
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
USER_EXIST: {
conflict: 'User is already exist',
EMAIL_ALREADY_IN_USE: {
emailAlreadyInUse: 'Email already in use',
},
};
@ -31,13 +31,13 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
forbidden: {
invalidCurrentPassword: {
responseType: 'forbidden',
},
conflict: {
emailAlreadyInUse: {
responseType: 'conflict',
},
},
@ -47,7 +47,7 @@ module.exports = {
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
@ -63,14 +63,14 @@ module.exports = {
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['email']);
user = await sails.helpers
.updateUser(user, values, this.req)
.intercept('conflict', () => Errors.USER_EXIST);
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE);
if (!user) {
throw Errors.USER_NOT_FOUND;

View file

@ -2,10 +2,10 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid',
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
};
@ -27,10 +27,10 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
forbidden: {
invalidCurrentPassword: {
responseType: 'forbidden',
},
},
@ -40,7 +40,7 @@ module.exports = {
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
@ -56,7 +56,7 @@ module.exports = {
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['password']);

View file

@ -0,0 +1,85 @@
const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
userNotFound: 'User not found',
},
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
username: {
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
allowNull: true,
},
currentPassword: {
type: 'string',
isNotEmptyString: true,
},
},
exits: {
userNotFound: {
responseType: 'notFound',
},
invalidCurrentPassword: {
responseType: 'forbidden',
},
usernameAlreadyInUse: {
responseType: 'conflict',
},
},
async fn(inputs, exits) {
const { currentUser } = this.req;
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
}
let user = await sails.helpers.getUser(inputs.id);
if (!user) {
throw Errors.USER_NOT_FOUND;
}
if (
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['username']);
user = await sails.helpers
.updateUser(user, values, this.req)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
if (!user) {
throw Errors.USER_NOT_FOUND;
}
return exits.success({
item: user.username,
});
},
};

View file

@ -1,6 +1,6 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -20,12 +20,12 @@ module.exports = {
},
avatar: {
type: 'json',
custom: value => _.isNull(value),
custom: (value) => _.isNull(value),
},
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
},

View file

@ -7,7 +7,7 @@ const sharp = require('sharp');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -32,9 +32,7 @@ const createReceiver = () => {
}
firstFileHandled = true;
const resize = sharp()
.resize(36, 36)
.jpeg();
const resize = sharp().resize(36, 36).jpeg();
const transform = new stream.Transform({
transform(chunk, streamEncoding, callback) {
@ -71,10 +69,10 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
unprocessableEntity: {
uploadError: {
responseType: 'unprocessableEntity',
},
},
@ -97,11 +95,11 @@ module.exports = {
this.req.file('file').upload(createReceiver(), async (error, files) => {
if (error) {
return exits.unprocessableEntity(error.message);
return exits.uploadError(error.message);
}
if (files.length === 0) {
return exits.unprocessableEntity('No file was uploaded');
return exits.uploadError('No file was uploaded');
}
user = await sails.helpers.updateUser(

View file

@ -35,7 +35,7 @@ module.exports = {
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(action.cardId, action.userId);
userIds.forEach(async userId => {
userIds.forEach(async (userId) => {
const notification = await Notification.create({
userId,
actionId: action.id,

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {
@ -32,7 +32,7 @@ module.exports = {
position: nextPosition,
});
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
@ -48,7 +48,7 @@ module.exports = {
projectId: inputs.project.id,
}).fetch();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',

View file

@ -13,12 +13,16 @@ module.exports = {
},
},
exits: {
labelAlreadyInCard: {},
},
async fn(inputs, exits) {
const cardLabel = await CardLabel.create({
cardId: inputs.card.id,
labelId: inputs.label.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'labelAlreadyInCard')
.fetch();
sails.sockets.broadcast(

View file

@ -6,7 +6,7 @@ module.exports = {
},
userOrUserId: {
type: 'ref',
custom: value => _.isPlainObject(value) || _.isString(value),
custom: (value) => _.isPlainObject(value) || _.isString(value),
required: true,
},
request: {
@ -14,6 +14,10 @@ module.exports = {
},
},
exits: {
userAlreadyCardMember: {},
},
async fn(inputs, exits) {
const { userId = inputs.userOrUserId } = inputs.userOrUserId;
@ -21,7 +25,7 @@ module.exports = {
userId,
cardId: inputs.card.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'userAlreadyCardMember')
.fetch();
sails.sockets.broadcast(

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
user: {

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {

View file

@ -14,7 +14,7 @@ module.exports = {
},
exits: {
conflict: {},
userAlreadyProjectMember: {},
},
async fn(inputs, exits) {
@ -22,7 +22,7 @@ module.exports = {
projectId: inputs.project.id,
userId: inputs.user.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'userAlreadyProjectMember')
.fetch();
const { userIds, projectMemberships } = await sails.helpers.getMembershipUserIdsForProject(
@ -30,7 +30,7 @@ module.exports = {
true,
);
userIds.forEach(userId => {
userIds.forEach((userId) => {
if (userId !== projectMembership.userId) {
sails.sockets.broadcast(
`user:${userId}`,

View file

@ -4,8 +4,11 @@ module.exports = {
inputs: {
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) && _.isString(value.email) && _.isString(value.password),
custom: (value) =>
_.isPlainObject(value) &&
_.isString(value.email) &&
_.isString(value.password) &&
(!value.username || _.isString(value.username)),
required: true,
},
request: {
@ -14,10 +17,16 @@ module.exports = {
},
exits: {
conflict: {},
emailAlreadyInUse: {},
usernameAlreadyInUse: {},
},
async fn(inputs, exits) {
if (inputs.values.username) {
// eslint-disable-next-line no-param-reassign
inputs.values.username = inputs.values.username.toLowerCase();
}
const user = await User.create({
...inputs.values,
email: inputs.values.email.toLowerCase(),
@ -28,13 +37,20 @@ module.exports = {
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
'emailAlreadyInUse',
)
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_username_unique"',
},
'usernameAlreadyInUse',
)
.fetch();
const userIds = await sails.helpers.getAdminUserIds();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userCreate',

View file

@ -17,7 +17,7 @@ module.exports = {
const userIds = await sails.helpers.getMembershipUserIdsForProject(board.projectId);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardDelete',

View file

@ -34,7 +34,7 @@ module.exports = {
projectMembership.projectId,
);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectMembershipDelete',
@ -47,7 +47,7 @@ module.exports = {
sails.sockets.removeRoomMembersFromRooms(
`user:${projectMembership.userId}`,
boardIds.map(boardId => `board:${boardId}`),
boardIds.map((boardId) => `board:${boardId}`),
);
const project = await Project.findOne(projectMembership.projectId);

View file

@ -20,9 +20,9 @@ module.exports = {
const userIds = sails.helpers.mapRecords(projectMemberships, 'userId');
const boards = await sails.helpers.getBoardsForProject(project.id);
const boardRooms = boards.map(board => `board:${board.id}`);
const boardRooms = boards.map((board) => `board:${board.id}`);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms);
sails.sockets.broadcast(

View file

@ -38,7 +38,7 @@ module.exports = {
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userDelete',

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const action = await Action.findOne(inputs.criteria);
if (!action) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getCardToProjectPath(action.cardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
action,
...nodes,
},

View file

@ -4,7 +4,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
beforeId: {

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
limit: {
type: 'number',
@ -10,9 +10,7 @@ module.exports = {
},
async fn(inputs, exits) {
const actions = await Action.find(inputs.criteria)
.sort('id DESC')
.limit(inputs.limit);
const actions = await Action.find(inputs.criteria).sort('id DESC').limit(inputs.limit);
return exits.success(actions);
},

View file

@ -7,21 +7,21 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const board = await Board.findOne(inputs.criteria);
if (!board) {
throw 'notFound';
throw 'pathNotFound';
}
const project = await Project.findOne(board.projectId);
if (!project) {
throw {
notFound: {
pathNotFound: {
board,
},
};

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptBoardId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const card = await Card.findOne(inputs.criteria);
if (!card) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getListToProjectPath(card.listId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
card,
...nodes,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptCardId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const label = await Label.findOne(inputs.criteria);
if (!label) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(label.boardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
label,
...nodes,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const list = await List.findOne(inputs.criteria);
if (!list) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(list.boardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
list,
...nodes,
},

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptListId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
withProjectMemberships: {

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

Some files were not shown because too many files have changed in this diff Show more