From bf9dfa87dab677727f86e606a1dd34aad9640ee9 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 28 Jul 2021 21:31:00 -0600 Subject: [PATCH] yeet name_first and name_last from users table --- app/Console/Commands/User/MakeUserCommand.php | 4 +- .../Application/Users/StoreUserRequest.php | 17 --- app/Models/User.php | 4 - app/Notifications/AddedToServer.php | 2 +- app/Notifications/RemovedFromServer.php | 2 +- app/Observers/SubuserObserver.php | 2 - .../Subusers/SubuserCreationService.php | 2 - .../Api/Application/UserTransformer.php | 2 - .../Api/Client/AccountTransformer.php | 2 - ..._29_032255_yeet_names_from_users_table.php | 29 +++++ resources/scripts/api/admin/users/getUsers.ts | 6 - .../scripts/api/admin/users/updateUser.ts | 2 - resources/scripts/components/App.tsx | 4 - .../admin/servers/ServersContainer.tsx | 2 +- .../admin/users/UserAboutContainer.tsx | 0 .../admin/users/UserEditContainer.tsx | 30 +---- .../components/admin/users/UserRouter.tsx | 105 ++++++++++++++++++ .../components/admin/users/UsersContainer.tsx | 2 +- resources/scripts/routers/AdminRouter.tsx | 7 +- resources/scripts/state/user.ts | 2 - 20 files changed, 144 insertions(+), 82 deletions(-) create mode 100644 database/migrations/2021_07_29_032255_yeet_names_from_users_table.php create mode 100644 resources/scripts/components/admin/users/UserAboutContainer.tsx create mode 100644 resources/scripts/components/admin/users/UserRouter.tsx diff --git a/app/Console/Commands/User/MakeUserCommand.php b/app/Console/Commands/User/MakeUserCommand.php index f981a2f23..a3fefd965 100644 --- a/app/Console/Commands/User/MakeUserCommand.php +++ b/app/Console/Commands/User/MakeUserCommand.php @@ -50,8 +50,6 @@ class MakeUserCommand extends Command $root_admin = $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin')); $email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email')); $username = $this->option('username') ?? $this->ask(trans('command/messages.user.ask_username')); - $name_first = $this->option('name-first') ?? $this->ask(trans('command/messages.user.ask_name_first')); - $name_last = $this->option('name-last') ?? $this->ask(trans('command/messages.user.ask_name_last')); if (is_null($password = $this->option('password')) && !$this->option('no-password')) { $this->warn(trans('command/messages.user.ask_password_help')); @@ -59,7 +57,7 @@ class MakeUserCommand extends Command $password = $this->secret(trans('command/messages.user.ask_password')); } - $user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin')); + $user = $this->creationService->handle(compact('email', 'username', 'password', 'root_admin')); $this->table(['Field', 'Value'], [ ['UUID', $user->uuid], ['Email', $user->email], diff --git a/app/Http/Requests/Api/Application/Users/StoreUserRequest.php b/app/Http/Requests/Api/Application/Users/StoreUserRequest.php index a1bb8f0e0..cdc4255c0 100644 --- a/app/Http/Requests/Api/Application/Users/StoreUserRequest.php +++ b/app/Http/Requests/Api/Application/Users/StoreUserRequest.php @@ -24,30 +24,13 @@ class StoreUserRequest extends ApplicationApiRequest 'admin_role_id', ])->toArray(); - $response['first_name'] = $rules['name_first']; - $response['last_name'] = $rules['name_last']; - return $response; } - public function validated(): array - { - $data = parent::validated(); - - $data['name_first'] = $data['first_name']; - $data['name_last'] = $data['last_name']; - - unset($data['first_name'], $data['last_name']); - - return $data; - } - public function attributes(): array { return [ 'external_id' => 'Third Party Identifier', - 'name_first' => 'First Name', - 'name_last' => 'Last Name', 'root_admin' => 'Root Administrator Status', ]; } diff --git a/app/Models/User.php b/app/Models/User.php index 86627e4b3..b035d4a6d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -87,8 +87,6 @@ class User extends Model implements 'external_id', 'username', 'email', - 'name_first', - 'name_last', 'password', 'language', 'use_totp', @@ -144,8 +142,6 @@ class User extends Model implements 'email' => 'required|email|between:1,191|unique:users,email', 'external_id' => 'sometimes|nullable|string|max:191|unique:users,external_id', 'username' => 'required|between:1,191|unique:users,username', - 'name_first' => 'required|string|between:1,191', - 'name_last' => 'required|string|between:1,191', 'password' => 'sometimes|nullable|string', 'admin_role_id' => 'sometimes|nullable|exists:admin_roles,id', 'root_admin' => 'boolean', diff --git a/app/Notifications/AddedToServer.php b/app/Notifications/AddedToServer.php index c116a2e29..19e23f5ac 100644 --- a/app/Notifications/AddedToServer.php +++ b/app/Notifications/AddedToServer.php @@ -53,7 +53,7 @@ class AddedToServer extends Notification implements ShouldQueue public function toMail($notifiable) { return (new MailMessage()) - ->greeting('Hello ' . $this->server->user . '!') + ->greeting('Hello user!') ->line('You have been added as a subuser for the following server, allowing you certain control over the server.') ->line('Server Name: ' . $this->server->name) ->action('Visit Server', url('/server/' . $this->server->uuidShort)); diff --git a/app/Notifications/RemovedFromServer.php b/app/Notifications/RemovedFromServer.php index 24418e51c..1699a5e29 100644 --- a/app/Notifications/RemovedFromServer.php +++ b/app/Notifications/RemovedFromServer.php @@ -54,7 +54,7 @@ class RemovedFromServer extends Notification implements ShouldQueue { return (new MailMessage()) ->error() - ->greeting('Hello ' . $this->server->user . '.') + ->greeting('Hello user!') ->line('You have been removed as a subuser for the following server.') ->line('Server Name: ' . $this->server->name) ->action('Visit Panel', route('index')); diff --git a/app/Observers/SubuserObserver.php b/app/Observers/SubuserObserver.php index 128de77fb..aff005c60 100644 --- a/app/Observers/SubuserObserver.php +++ b/app/Observers/SubuserObserver.php @@ -32,7 +32,6 @@ class SubuserObserver event(new Events\Subuser\Created($subuser)); $subuser->user->notify((new AddedToServer([ - 'user' => $subuser->user->name_first, 'name' => $subuser->server->name, 'uuidShort' => $subuser->server->uuidShort, ]))); @@ -54,7 +53,6 @@ class SubuserObserver event(new Events\Subuser\Deleted($subuser)); $subuser->user->notify((new RemovedFromServer([ - 'user' => $subuser->user->name_first, 'name' => $subuser->server->name, ]))); } diff --git a/app/Services/Subusers/SubuserCreationService.php b/app/Services/Subusers/SubuserCreationService.php index b1affd3f3..e4415893f 100644 --- a/app/Services/Subusers/SubuserCreationService.php +++ b/app/Services/Subusers/SubuserCreationService.php @@ -82,8 +82,6 @@ class SubuserCreationService $user = $this->userCreationService->handle([ 'email' => $email, 'username' => $username, - 'name_first' => 'Server', - 'name_last' => 'Subuser', 'root_admin' => false, ]); } diff --git a/app/Transformers/Api/Application/UserTransformer.php b/app/Transformers/Api/Application/UserTransformer.php index 0146a0caa..f79aad102 100644 --- a/app/Transformers/Api/Application/UserTransformer.php +++ b/app/Transformers/Api/Application/UserTransformer.php @@ -33,8 +33,6 @@ class UserTransformer extends BaseTransformer 'uuid' => $model->uuid, 'username' => $model->username, 'email' => $model->email, - 'first_name' => $model->name_first, - 'last_name' => $model->name_last, 'language' => $model->language, 'root_admin' => (bool) $model->root_admin, '2fa' => (bool) $model->use_totp, diff --git a/app/Transformers/Api/Client/AccountTransformer.php b/app/Transformers/Api/Client/AccountTransformer.php index 405a4208a..770d24c02 100644 --- a/app/Transformers/Api/Client/AccountTransformer.php +++ b/app/Transformers/Api/Client/AccountTransformer.php @@ -26,8 +26,6 @@ class AccountTransformer extends BaseClientTransformer 'admin' => $model->root_admin, 'username' => $model->username, 'email' => $model->email, - 'first_name' => $model->name_first, - 'last_name' => $model->name_last, 'language' => $model->language, ]; } diff --git a/database/migrations/2021_07_29_032255_yeet_names_from_users_table.php b/database/migrations/2021_07_29_032255_yeet_names_from_users_table.php new file mode 100644 index 000000000..5692d6c1c --- /dev/null +++ b/database/migrations/2021_07_29_032255_yeet_names_from_users_table.php @@ -0,0 +1,29 @@ +dropColumn(['name_first', 'name_last']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->string('name_first')->after('email')->nullable(); + $table->string('name_last')->after('name_first')->nullable(); + }); + } +} diff --git a/resources/scripts/api/admin/users/getUsers.ts b/resources/scripts/api/admin/users/getUsers.ts index 5f11da48d..51aaf8489 100644 --- a/resources/scripts/api/admin/users/getUsers.ts +++ b/resources/scripts/api/admin/users/getUsers.ts @@ -11,8 +11,6 @@ export interface User { uuid: string; username: string; email: string; - firstName: string; - lastName: string; language: string; adminRoleId: number | null; rootAdmin: boolean; @@ -33,8 +31,6 @@ export const rawDataToUser = ({ attributes }: FractalResponseData): User => ({ uuid: attributes.uuid, username: attributes.username, email: attributes.email, - firstName: attributes.first_name, - lastName: attributes.last_name, language: attributes.language, adminRoleId: attributes.admin_role_id, rootAdmin: attributes.root_admin, @@ -54,8 +50,6 @@ export interface Filters { uuid?: string; username?: string; email?: string; - firstName?: string; - lastName?: string; } export const Context = createContext(); diff --git a/resources/scripts/api/admin/users/updateUser.ts b/resources/scripts/api/admin/users/updateUser.ts index 7baf7c708..4b63b8a66 100644 --- a/resources/scripts/api/admin/users/updateUser.ts +++ b/resources/scripts/api/admin/users/updateUser.ts @@ -4,8 +4,6 @@ import { User, rawDataToUser } from '@/api/admin/users/getUsers'; export interface Values { username: string; email: string; - firstName: string; - lastName: string; password: string; adminRoleId: number | null; } diff --git a/resources/scripts/components/App.tsx b/resources/scripts/components/App.tsx index 340e2b7bb..6d73f5e66 100644 --- a/resources/scripts/components/App.tsx +++ b/resources/scripts/components/App.tsx @@ -24,8 +24,6 @@ interface ExtendedWindow extends Window { username: string; email: string; /* eslint-disable camelcase */ - name_first: string; - name_last: string; root_admin: boolean; use_totp: boolean; language: string; @@ -56,8 +54,6 @@ const App = () => { uuid: PterodactylUser.uuid, username: PterodactylUser.username, email: PterodactylUser.email, - firstName: PterodactylUser.name_first, - lastName: PterodactylUser.name_last, language: PterodactylUser.language, rootAdmin: PterodactylUser.root_admin, useTotp: PterodactylUser.use_totp, diff --git a/resources/scripts/components/admin/servers/ServersContainer.tsx b/resources/scripts/components/admin/servers/ServersContainer.tsx index 50d78a805..0ff594280 100644 --- a/resources/scripts/components/admin/servers/ServersContainer.tsx +++ b/resources/scripts/components/admin/servers/ServersContainer.tsx @@ -131,7 +131,7 @@ const ServersContainer = () => {
- {server.relations.user?.firstName} {server.relations.user?.lastName} + Silly User
diff --git a/resources/scripts/components/admin/users/UserAboutContainer.tsx b/resources/scripts/components/admin/users/UserAboutContainer.tsx new file mode 100644 index 000000000..e69de29bb diff --git a/resources/scripts/components/admin/users/UserEditContainer.tsx b/resources/scripts/components/admin/users/UserEditContainer.tsx index d051c039f..0a893d1d7 100644 --- a/resources/scripts/components/admin/users/UserEditContainer.tsx +++ b/resources/scripts/components/admin/users/UserEditContainer.tsx @@ -52,8 +52,6 @@ export function InformationContainer ({ title, initialValues, children, onSubmit initialValues = { username: '', email: '', - firstName: '', - lastName: '', password: '', adminRoleId: 0, }; @@ -66,8 +64,6 @@ export function InformationContainer ({ title, initialValues, children, onSubmit validationSchema={object().shape({ username: string().min(1).max(32), email: string(), - firstName: string(), - lastName: string(), password: exists ? string() : string().required(), })} > @@ -98,26 +94,6 @@ export function InformationContainer ({ title, initialValues, children, onSubmit
-
-
- -
- -
- -
-
-
-

{user.firstName} {user.lastName}

-

{user.email}

+

{user.email}

+

{user.uuid}

diff --git a/resources/scripts/components/admin/users/UserRouter.tsx b/resources/scripts/components/admin/users/UserRouter.tsx new file mode 100644 index 000000000..00c5d857b --- /dev/null +++ b/resources/scripts/components/admin/users/UserRouter.tsx @@ -0,0 +1,105 @@ +import React, { useEffect, useState } from 'react'; +import { useLocation } from 'react-router'; +import tw from 'twin.macro'; +import { Route, Switch, useRouteMatch } from 'react-router-dom'; +import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy'; +import { User } from '@/api/admin/users/getUsers'; +import getUser from '@/api/admin/users/getUser'; +import AdminContentBlock from '@/components/admin/AdminContentBlock'; +import Spinner from '@/components/elements/Spinner'; +import FlashMessageRender from '@/components/FlashMessageRender'; +import { ApplicationStore } from '@/state'; +import { SubNavigation, SubNavigationLink } from '@/components/admin/SubNavigation'; + +interface ctx { + user: User | undefined; + setUser: Action; +} + +export const Context = createContextStore({ + user: undefined, + + setUser: action((state, payload) => { + state.user = payload; + }), +}); + +const UserRouter = () => { + const location = useLocation(); + const match = useRouteMatch<{ id?: string }>(); + + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + const [ loading, setLoading ] = useState(true); + + const user = Context.useStoreState(state => state.user); + const setUser = Context.useStoreActions(actions => actions.setUser); + + useEffect(() => { + clearFlashes('user'); + + getUser(Number(match.params?.id), [ 'database_host', 'location' ]) + .then(user => setUser(user)) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'user', error }); + }) + .then(() => setLoading(false)); + }, []); + + if (loading || user === undefined) { + return ( + + + +
+ +
+
+ ); + } + + return ( + +
+
+

{user.email}

+

{user.uuid}

+
+
+ + + + + + + + + + + + + + + + + + + +

About

+
+ + +

Servers

+
+
+
+ ); +}; + +export default () => { + return ( + + + + ); +}; diff --git a/resources/scripts/components/admin/users/UsersContainer.tsx b/resources/scripts/components/admin/users/UsersContainer.tsx index 790e7dfad..a77a58233 100644 --- a/resources/scripts/components/admin/users/UsersContainer.tsx +++ b/resources/scripts/components/admin/users/UsersContainer.tsx @@ -130,7 +130,7 @@ const UsersContainer = () => {
- {user.firstName} {user.lastName} + Silly User
diff --git a/resources/scripts/routers/AdminRouter.tsx b/resources/scripts/routers/AdminRouter.tsx index fc95792e9..0f964290a 100644 --- a/resources/scripts/routers/AdminRouter.tsx +++ b/resources/scripts/routers/AdminRouter.tsx @@ -20,7 +20,7 @@ import ServersContainer from '@/components/admin/servers/ServersContainer'; import NewServerContainer from '@/components/admin/servers/NewServerContainer'; import UsersContainer from '@/components/admin/users/UsersContainer'; import NewUserContainer from '@/components/admin/users/NewUserContainer'; -import UserEditContainer from '@/components/admin/users/UserEditContainer'; +import UserRouter from '@/components/admin/users/UserRouter'; import RolesContainer from '@/components/admin/roles/RolesContainer'; import RoleEditContainer from '@/components/admin/roles/RoleEditContainer'; import NestsContainer from '@/components/admin/nests/NestsContainer'; @@ -173,7 +173,7 @@ const AdminRouter = ({ location, match }: RouteComponentProps) => { Profile Picture
- {user?.firstName} {user?.lastName} + Silly User {user?.roleName}
@@ -237,8 +237,7 @@ const AdminRouter = ({ location, match }: RouteComponentProps) => { diff --git a/resources/scripts/state/user.ts b/resources/scripts/state/user.ts index a49329338..ec3b8b5fb 100644 --- a/resources/scripts/state/user.ts +++ b/resources/scripts/state/user.ts @@ -5,8 +5,6 @@ export interface UserData { uuid: string; username: string; email: string; - firstName: string; - lastName: string; language: string; rootAdmin: boolean; useTotp: boolean;