Skip to content

Commit

Permalink
fix(user edit): fix user edit not being able to be saved (#651)
Browse files Browse the repository at this point in the history
Co-authored-by: sct <sctsnipe@gmail.com>
  • Loading branch information
ankarhem and sct committed Jan 15, 2021
1 parent 23624bd commit b04d00e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -47,9 +49,7 @@ components:
$ref: '#/components/schemas/MediaRequest'
required:
- id
- userType
- email
- permissions
- createdAt
- updatedAt
MainSettings:
Expand Down
5 changes: 3 additions & 2 deletions server/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions server/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions server/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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');
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/PermissionOption/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/components/UserEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down
6 changes: 2 additions & 4 deletions src/components/UserList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit b04d00e

Please sign in to comment.