Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up Filament + basic user management commands #231

Merged

Conversation

JSn1nj4
Copy link

@JSn1nj4 JSn1nj4 commented Feb 10, 2024

Accessing Filament Dashboard

Filament's default routes are:

  • Dashboard URL root: default admin, but customizable via APP_DASHBOARD_ROOT in .env
  • Login route: {dashboard-root}/login
  • Password reset request: {dashboard-root}/password-reset/request
    • Generates a password reset URL with a token that's good for 60 minutes
    • Password reset URL loads the form every time, but the form will only accept the token once

Routes removed

The default auth routes pulled in with Auth::routes(). Since Filament has its own routes for login, logout, password resets etc., the default ones provided by Laravel are no longer needed.

The old views and controllers specifically for those actions have also been removed.

Filament customizations

Filament's color customization is built around Tailwind's palette. Registering custom colors also works similarly, just using Filament's built-in tools.

For example:

Current customizations were done via the default AdminPanelProvider generated by Filament.

  • A variation of HackGreenville's logo was also added for if a user prefers light mode in the dashboard.

User management commands created

Laravel 10 generates custom commands with the app: prefix by default, so these new commands have that currently. We can adjust them if preferred.

Create User command

php artisan app:user:create <email> <first_name> <last_name>

Creates a new user account with a random password. If a user matching the email address exists, log an error instead.

A Password Reset email will also be generated.

Activate/Deactivate User commands

php artisan app:user:activate <email>
php artisan app:user:deactivate <email>

Activate or deactivate an existing user account. This controls whether users can log into the admin dashboard.

Note: Newly-created accounts are activated by default.

Password Reset command

php artisan app:user:reset-password <email>

Use this to reset the user's password to a new, strong password. Will ask to confirm before performing password reset.

The user will have to reset their password next time they want to sign in.

Delete User command

php artisan app:user:delete <email>

Delete an existing user. Will ask to confirm before deleting.

Considerations

  1. What other actions, if any, should trigger an email to the user? (e.g. password reset, deactivation, reactivation)
  2. What actions, if any, should trigger an email to the application admin? (e.g. user activation/deactivation)

Closes #229

-  Livewire v2.12.3 > v3.4.4

This is in preparation for a fresh install of Filament v3, which uses Livewire v3 under the hood.

Most upgrades were automatic via `livewire:upgrade` with a couple of exceptions:
- On HackgreenvilleTimeline.php:29, an old method "dispatchBrowserEvent()" was condensed into "dispatch()", and now takes args as named params instead of array keys.
- Livewire's config was published so the `app.blade.php` could stay where it was.

`@livewireStyles` and `@livewireScripts` also no longer need to be added manually.

- Laravel v10.14.1 > v10.34.2

This is due to Livewire v3 using Illuminate\Support\Stringable::isUrl() indirectly when rendering Livewire components. This method did not exist in earlier versions of Laravel 10.
This will control whether a user can access the admin dashboard.
@JSn1nj4 JSn1nj4 added the enhancement New feature or request label Feb 10, 2024
@JSn1nj4
Copy link
Author

JSn1nj4 commented Feb 11, 2024

@zach2825 I think this was the leftover stuff from the old login system:
https://github.com/hackgvl/hackgreenville-com/tree/develop/app/Http/Controllers/Auth

The login form is still there and works...
image

But it just takes you to the default /home URL after logging in, which 404s
image

Assuming Filament doesn't need these controllers and the related views, is it alright if I prune this stuff? I only see Laravel's default auth routes.

@JSn1nj4
Copy link
Author

JSn1nj4 commented Feb 12, 2024

Ok, I'm gonna take a break from pushing until I have all the commands done. Don't want to keep running GitHub Actions for small commits...

@JSn1nj4 JSn1nj4 marked this pull request as ready for review February 16, 2024 04:06
@JSn1nj4 JSn1nj4 self-assigned this Feb 16, 2024
@JSn1nj4 JSn1nj4 force-pushed the feature/229-filament-and-user-management branch from 6777aa0 to 5b2a1b9 Compare February 16, 2024 04:10
@JSn1nj4
Copy link
Author

JSn1nj4 commented Feb 17, 2024

@zach2825 since this PR pairs admin commands for user management w/ installing Filament, think it useful to at least include a user index and maybe "latest users" dashboard widget, or should those be separate PRs at this point?

Copy link
Collaborator

@zach2825 zach2825 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added my feedback as a comment because everything works, just wanted to see what you thought about some of these other things...

app/Providers/Filament/AdminPanelProvider.php Outdated Show resolved Hide resolved
app/Providers/Filament/AdminPanelProvider.php Outdated Show resolved Hide resolved
resources/views/layouts/app.blade.php Show resolved Hide resolved
database/seeders/UsersTableSeeder.php Show resolved Hide resolved
For some reason, the admin/login route was not behaving correctly anymore despite no apparent changes to the lock files and having dependencies reinstalled.

But upgrading filament seems to fix the issue.
composer/composer, affected by: CVE-2024-24821

phpseclib/phpseclib, affected by: CVE-2023-49316
@bogdankharchenko
Copy link
Collaborator

Sorry I have not been paying much attention to this, but I like it =)

app/Listeners/EmailNewUser.php Outdated Show resolved Hide resolved
@bogdankharchenko
Copy link
Collaborator

@JSn1nj4 these seem to be some conflicts, can you go ahead and resolve them?

@JSn1nj4
Copy link
Author

JSn1nj4 commented Mar 5, 2024

@bogdankharchenko handled. Thanks!

@allella allella requested a review from zach2825 March 5, 2024 16:06
@bogdankharchenko
Copy link
Collaborator

@zach2825 can you also take a peek into this?

@zach2825
Copy link
Collaborator

zach2825 commented Mar 7, 2024

@bogdankharchenko I did, and had a little feedback its all been resolved and talked about 💯 thanks ‼️

Copy link
Collaborator

@zach2825 zach2825 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

@allella
Copy link
Member

allella commented Mar 8, 2024

@JSn1nj4 it looks like we're just about ready to merge.

One question, which we could address in another PR if it's worth doing. Is it possible to have the login form, or even all of the admin stuff, have routes/paths that's are not obvious and/or not publicly known.

Using /admin/login would likely attract unnecessary hammering from bots over time. I'm accustom to changing at least the login form to something that isn't obvious. Bonus points if it's a path that's defined in a .env so even people reading this repo wouldn't know where to login or where the admin exists without being invited.

As for deploying this to stage for testing, can you list any necessary or optional commands or steps?

I'm assuming to run scripts/handle-deploy-update.sh and then are there any other artisan commands or other special things to run that aren't related to users?

After that, I'm guessing the user-specific commands above, like php artisan app:user:create <email> <first_name> <last_name> would be run from the command line to add people and send them emails.

On the email side, we don't have the .env configured to actually send email.

The stage and production server runs sendmail/postfix locally to relay messages through Sendgrid. So, I think it would be pretty easy for me to edit the .env vars, like

MAIL_DRIVER=sendmail
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_FROM_ADDRESS=noreply @ hackgreenville ... com
MAIL_FROM_NAME=HackGreenville Labs

Sendgrid was previously authorized to send emails on behalf of HG, but I think with the November transfer we lost some DNS records, so I just added them back. Which remains me we still need to move the DNS and transactional email system away from my control. (which is sort of bottlenecked by the HG Committee getting with RefactorGVL to get email MX setup, pass wd manager, and such)

@JSn1nj4
Copy link
Author

JSn1nj4 commented Mar 9, 2024

@allella on customizing the admin URL, I made it configurable via APP_DASHBOARD_ROOT in .env and updated the top of the PR description to reflect this change. This value affects all auth-related routes for this admin panel: the dashboard, login, logout, password reset routes, any model CRUD resources we create later.

After a quick review, no extra setup steps should be needed. The deploy script as it currently is should result in everything being up.

For email configuration, I believe you're correct.

@JSn1nj4
Copy link
Author

JSn1nj4 commented Mar 9, 2024

Oh, also just updated the deploy script (here cc4db3f) according to this section:
https://filamentphp.com/docs/3.x/panels/installation#caching-filament-components

@allella
Copy link
Member

allella commented Mar 10, 2024

@JSn1nj4 thanks.

What do you think about adding the world "path" to the new dashboard config variable so it's more clear that it's not related to "root" permissions, but rather a root directory. Perhaps APP_DASHBOARD_ROOT_PATH

Also, how about we added this variable to the .env.example too?

@allella allella merged commit 758a960 into hackgvl:develop Mar 15, 2024
1 check passed
@allella
Copy link
Member

allella commented Mar 15, 2024

@JSn1nj4 this was merged, but I did run into a Composer error because ext-intl wasn't installed and wasn't declared in the composer.json.

Should we add ext-intl as a composer required package to possibly fail earlier in the install process during the dependency stage? It seemed like composer started doing things and only realized the extension was missing after the fact.

I haven't tried to create any users yet, but the log in path is rendering. I'll share the admin path root in the Slack.

@JSn1nj4 JSn1nj4 deleted the feature/229-filament-and-user-management branch March 20, 2024 03:17
@allella
Copy link
Member

allella commented Mar 29, 2024

@JSn1nj4 the email configuration is now setup on production and I created the first account as a test.

Not that we need it right now, but are there any roles, or is every user an equal admin out of the gate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up base filament dashboard + admin commands for managing users
4 participants