fix(user edit): fix user edit not being able to be saved (#651)

Co-authored-by: sct <sctsnipe@gmail.com>
pull/655/head
Jakob Ankarhem 4 years ago committed by GitHub
parent 23624bd144
commit b04d00ef50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,11 +23,13 @@ components:
userType:
type: integer
example: 1
readOnly: true
permissions:
type: number
example: 0
avatar:
type: string
readOnly: true
createdAt:
type: string
example: '2020-09-02T05:02:23.000Z'
@ -47,9 +49,7 @@ components:
$ref: '#/components/schemas/MediaRequest'
required:
- id
- userType
- email
- permissions
- createdAt
- updatedAt
MainSettings:

@ -15,6 +15,7 @@ import PreparedEmail from '../lib/email';
import logger from '../logger';
import { getSettings } from '../lib/settings';
import { default as generatePassword } from 'secure-random-password';
import { UserType } from '../constants/user';
@Entity()
export class User {
@ -36,8 +37,8 @@ export class User {
@Column({ nullable: true, select: false })
public password?: string;
@Column({ type: 'integer', default: 1 })
public userType = 1;
@Column({ type: 'integer', default: UserType.PLEX })
public userType: UserType;
@Column({ nullable: true, select: false })
public plexId?: number;

@ -68,6 +68,7 @@ authRoutes.post('/login', async (req, res, next) => {
plexToken: account.authToken,
permissions: Permission.ADMIN,
avatar: account.thumb,
userType: UserType.PLEX,
});
await userRepository.save(user);
}
@ -90,6 +91,7 @@ authRoutes.post('/login', async (req, res, next) => {
plexToken: account.authToken,
permissions: settings.main.defaultPermissions,
avatar: account.thumb,
userType: UserType.PLEX,
});
await userRepository.save(user);
} else {

@ -7,6 +7,7 @@ import { hasPermission, Permission } from '../lib/permissions';
import { getSettings } from '../lib/settings';
import logger from '../logger';
import gravatarUrl from 'gravatar-url';
import { UserType } from '../constants/user';
const router = Router();
@ -26,7 +27,7 @@ router.post('/', async (req, res, next) => {
const userRepository = getRepository(User);
const passedExplicitPassword = body.password && body.password.length > 0;
const avatar = gravatarUrl(body.email);
const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 });
if (!passedExplicitPassword && !settings.enabled) {
throw new Error('Email notifications must be enabled');
@ -37,9 +38,9 @@ router.post('/', async (req, res, next) => {
username: body.username ?? body.email,
email: body.email,
password: body.password,
permissions: body.permissions,
permissions: Permission.REQUEST,
plexToken: '',
userType: body.userType,
userType: UserType.LOCAL,
});
if (passedExplicitPassword) {
@ -201,6 +202,7 @@ router.post('/import-from-plex', async (req, res, next) => {
plexId: parseInt(account.id),
plexToken: '',
avatar: account.thumb,
userType: UserType.PLEX,
});
await userRepository.save(newUser);
createdUsers.push(newUser);

@ -59,7 +59,7 @@ const PermissionOption: React.FC<PermissionOptionProps> = ({
!hasPermission(Permission.MANAGE_SETTINGS, user.permissions) &&
option.permission === Permission.MANAGE_SETTINGS)
}
onClick={() => {
onChange={() => {
onUpdate(
hasPermission(option.permission, currentPermission)
? currentPermission - option.permission

@ -79,7 +79,6 @@ const UserEdit: React.FC = () => {
await axios.put(`/api/v1/user/${user?.id}`, {
permissions: currentPermission,
email: user?.email,
avatar: user?.avatar,
});
addToast(intl.formatMessage(messages.usersaved), {

@ -204,8 +204,6 @@ const UserList: React.FC = () => {
await axios.post('/api/v1/user', {
email: values.email,
password: values.genpassword ? null : values.password,
permissions: Permission.REQUEST,
userType: UserType.LOCAL,
});
addToast(intl.formatMessage(messages.usercreatedsuccess), {
appearance: 'success',
@ -315,7 +313,7 @@ const UserList: React.FC = () => {
}}
</Formik>
</Transition>
<div className="flex-col sm:flex-row flex justify-between">
<div className="flex flex-col justify-between sm:flex-row">
<Header>{intl.formatMessage(messages.userlist)}</Header>
<div className="flex">
<Button
@ -363,7 +361,7 @@ const UserList: React.FC = () => {
<div className="text-sm font-medium leading-5">
{user.username}
</div>
<div className="text-sm text-gray-300 leading-5">
<div className="text-sm leading-5 text-gray-300">
{user.email}
</div>
</div>

Loading…
Cancel
Save