Skip to content

Commit

Permalink
Update Directory logic, add curated onboarding support
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Feb 22, 2024
1 parent 4c5e828 commit 59c7023
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
11 changes: 7 additions & 4 deletions app/Http/Controllers/Admin/AdminDirectoryController.php
Expand Up @@ -75,6 +75,7 @@ public function directoryInitialData(Request $request)
}

$res['community_guidelines'] = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : [];
$res['curated_onboarding'] = (bool) config_cache('instance.curated_registration.enabled');
$res['open_registration'] = (bool) config_cache('pixelfed.open_registration');
$res['oauth_enabled'] = (bool) config_cache('pixelfed.oauth_enabled') && file_exists(storage_path('oauth-public.key')) && file_exists(storage_path('oauth-private.key'));

Expand Down Expand Up @@ -124,7 +125,7 @@ function ($attribute, $value, $fail) {

$res['requirements_validator'] = $validator->errors();

$res['is_eligible'] = $res['open_registration'] &&
$res['is_eligible'] = ($res['open_registration'] || $res['curated_onboarding']) &&
$res['oauth_enabled'] &&
$res['activitypub_enabled'] &&
count($res['requirements_validator']) === 0 &&
Expand Down Expand Up @@ -227,7 +228,7 @@ public function directoryStore(Request $request)
->each(function($name) {
Storage::delete($name);
});
$path = $request->file('banner_image')->store('public/headers');
$path = $request->file('banner_image')->storePublicly('public/headers');
$res['banner_image'] = $path;
ConfigCacheService::put('app.banner_image', url(Storage::url($path)));

Expand All @@ -249,7 +250,8 @@ public function directoryHandleServerSubmission(Request $request)
{
$reqs = [];
$reqs['feature_config'] = [
'open_registration' => config_cache('pixelfed.open_registration'),
'open_registration' => (bool) config_cache('pixelfed.open_registration'),
'curated_onboarding' => (bool) config_cache('instance.curated_registration.enabled'),
'activitypub_enabled' => config_cache('federation.activitypub.enabled'),
'oauth_enabled' => config_cache('pixelfed.oauth_enabled'),
'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','),
Expand All @@ -265,7 +267,8 @@ public function directoryHandleServerSubmission(Request $request)
];

$validator = Validator::make($reqs['feature_config'], [
'open_registration' => 'required|accepted',
'open_registration' => 'required_unless:curated_onboarding,true',
'curated_onboarding' => 'required_unless:open_registration,true',
'activitypub_enabled' => 'required|accepted',
'oauth_enabled' => 'required|accepted',
'media_types' => [
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/PixelfedDirectoryController.php
Expand Up @@ -78,10 +78,11 @@ public function buildListing()
$res['community_guidelines'] = json_decode($guidelines->v, true);
}

$openRegistration = ConfigCache::whereK('pixelfed.open_registration')->first();
if($openRegistration) {
$res['open_registration'] = (bool) $openRegistration;
}
$openRegistration = (bool) config_cache('pixelfed.open_registration');
$res['open_registration'] = $openRegistration;

$curatedOnboarding = (bool) config_cache('instance.curated_registration.enabled');
$res['curated_onboarding'] = $curatedOnboarding;

$oauthEnabled = ConfigCache::whereK('pixelfed.oauth_enabled')->first();
if($oauthEnabled) {
Expand Down
25 changes: 19 additions & 6 deletions resources/assets/components/admin/AdminDirectory.vue
Expand Up @@ -109,12 +109,20 @@
<div class="card text-left">
<div class="list-group list-group-flush">
<div class="list-group-item">
<i
class="far"
:class="[ requirements.open_registration ? 'fa-check-circle text-success' : 'fa-exclamation-circle text-danger']"></i>
<span class="ml-2 font-weight-bold">
{{ requirements.open_registration ? 'Open' : 'Closed' }} account registration
</span>
<template v-if="requirements.curated_onboarding === true">
<i class="far fa-exclamation-circle text-success"></i>
<span class="ml-2 font-weight-bold">
Curated account registration
</span>
</template>
<template v-else>
<i
class="far"
:class="[ requirements.open_registration ? 'fa-check-circle text-success' : 'fa-exclamation-circle text-danger']"></i>
<span class="ml-2 font-weight-bold">
{{ requirements.open_registration ? 'Open' : 'Closed' }} account registration
</span>
</template>
</div>

<div class="list-group-item">
Expand Down Expand Up @@ -895,6 +903,7 @@
activitypub_enabled: undefined,
open_registration: undefined,
oauth_enabled: undefined,
curated_onboarding: undefined,
},
feature_config: [],
requirements_validator: [],
Expand Down Expand Up @@ -951,6 +960,10 @@
this.requirements.open_registration = res.data.open_registration;
}
if(res.data.curated_onboarding) {
this.requirements.curated_onboarding = res.data.curated_onboarding;
}
if(res.data.oauth_enabled) {
this.requirements.oauth_enabled = res.data.oauth_enabled;
}
Expand Down

0 comments on commit 59c7023

Please sign in to comment.