From b8effb319d34da86d06efc6a6269ae6b8d258f79 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Sun, 27 Aug 2023 19:12:47 -0400 Subject: [PATCH 1/4] feat: add support for feature flags --- app/Site/AppServiceProvider.php | 5 +++++ config/envy.php | 2 ++ config/feature.php | 10 ++++++++++ resources/views/demo.blade.php | 13 +++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 config/feature.php diff --git a/app/Site/AppServiceProvider.php b/app/Site/AppServiceProvider.php index 8cdd3666cd..82b06a0b9e 100644 --- a/app/Site/AppServiceProvider.php +++ b/app/Site/AppServiceProvider.php @@ -20,6 +20,7 @@ use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Blade; class AppServiceProvider extends ServiceProvider { @@ -55,6 +56,10 @@ public function boot(): void $schedule->command(DeleteOverdueUserAccounts::class)->daily(); }); + Blade::if('hasfeature', function ($feature) { + return config("feature.$feature", false); + }); + /* * https://josephsilber.com/posts/2018/07/02/eloquent-polymorphic-relations-morph-map */ diff --git a/config/envy.php b/config/envy.php index 0c602294ef..9e2c4dee9d 100644 --- a/config/envy.php +++ b/config/envy.php @@ -79,6 +79,8 @@ 'REDIS_DB', 'REDIS_CACHE_DB', 'MYSQL_ATTR_SSL_CA', + // config/feature.php + 'FEATURE_BEAT', // config/filesystem.php 'AWS_ENDPOINT', 'AWS_URL', diff --git a/config/feature.php b/config/feature.php new file mode 100644 index 0000000000..2b7d4c4d27 --- /dev/null +++ b/config/feature.php @@ -0,0 +1,10 @@ + env('FEATURE_BEAT', false), + +]; diff --git a/resources/views/demo.blade.php b/resources/views/demo.blade.php index da5118ac09..5ab5b83b6f 100644 --- a/resources/views/demo.blade.php +++ b/resources/views/demo.blade.php @@ -51,6 +51,19 @@ {{ '
' }}
s are meant for single line breaks.

+ + +

Feature Flags

+
+

Beaten Games Player-facing UX

+ @hasfeature("beat") + Enabled + @else + Disabled + @endhasfeature +
+
+
This is not in a {{ '
' }}.
From 8cb2fe76f64c81bd5f1ec8296f883bf5c789f8d6 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Sun, 27 Aug 2023 19:13:02 -0400 Subject: [PATCH 2/4] chore: lint --- app/Site/AppServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Site/AppServiceProvider.php b/app/Site/AppServiceProvider.php index 82b06a0b9e..7ebd09dece 100644 --- a/app/Site/AppServiceProvider.php +++ b/app/Site/AppServiceProvider.php @@ -18,9 +18,9 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; -use Illuminate\Support\Facades\Blade; class AppServiceProvider extends ServiceProvider { From 4bad5fc96b1b33c8860486729d8e16a04f73a984 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Sun, 27 Aug 2023 19:16:15 -0400 Subject: [PATCH 3/4] chore: update .env.example --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.env.example b/.env.example index f26c43c062..1ee39a3bed 100644 --- a/.env.example +++ b/.env.example @@ -85,6 +85,10 @@ MAIL_PASSWORD="${DB_USERNAME}" MAIL_FROM_ADDRESS=noreply@retroachievements.org MAIL_FROM_NAME="${APP_NAME}" +# Feature Flags + +FEATURE_BEAT=true + # Providers CLAMAV_SKIP_VALIDATION=true From f01048c7e7fee83cdee66b77188a020485e082cc Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Mon, 28 Aug 2023 07:26:51 -0400 Subject: [PATCH 4/4] fix: address pr feedback --- public/admin.php | 6 ++++++ resources/views/components/feature-flags.blade.php | 8 ++++++++ resources/views/demo.blade.php | 9 +-------- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 resources/views/components/feature-flags.blade.php diff --git a/public/admin.php b/public/admin.php index 7e9c0d97b8..cb23b90974 100644 --- a/public/admin.php +++ b/public/admin.php @@ -4,6 +4,7 @@ use App\Site\Enums\Permissions; use App\Site\Models\StaticData; use App\Site\Models\User; +use Illuminate\Support\Facades\Blade; if (!authenticateFromCookie($user, $permissions, $userDetails, Permissions::Moderator)) { abort(401); @@ -388,6 +389,11 @@ + +
+

Feature Flags

+ '); ?> +
diff --git a/resources/views/components/feature-flags.blade.php b/resources/views/components/feature-flags.blade.php new file mode 100644 index 0000000000..de9d9d005c --- /dev/null +++ b/resources/views/components/feature-flags.blade.php @@ -0,0 +1,8 @@ +
+

Beaten Games Player-facing UX

+ @hasfeature("beat") + Enabled + @else + Disabled + @endhasfeature +
diff --git a/resources/views/demo.blade.php b/resources/views/demo.blade.php index 5ab5b83b6f..e592bd9380 100644 --- a/resources/views/demo.blade.php +++ b/resources/views/demo.blade.php @@ -54,14 +54,7 @@

Feature Flags

-
-

Beaten Games Player-facing UX

- @hasfeature("beat") - Enabled - @else - Disabled - @endhasfeature -
+