Merge pull request #4996 from pixelfed/staging

Staging
This commit is contained in:
daniel 2024-03-08 06:04:27 -07:00 committed by GitHub
commit 24c467c558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 641 additions and 477 deletions

View file

@ -2,33 +2,36 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use Cache;
use DB;
use View;
use App\AccountInterstitial; use App\AccountInterstitial;
use App\Follower; use App\Follower;
use App\FollowRequest; use App\FollowRequest;
use App\Profile; use App\Profile;
use App\Story;
use App\Status;
use App\User;
use App\UserSetting;
use App\UserFilter;
use League\Fractal;
use App\Services\AccountService; use App\Services\AccountService;
use App\Services\FollowerService; use App\Services\FollowerService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Util\Lexer\Nickname; use App\Status;
use App\Util\Webfinger\Webfinger; use App\Story;
use App\Transformer\ActivityPub\ProfileOutbox;
use App\Transformer\ActivityPub\ProfileTransformer; use App\Transformer\ActivityPub\ProfileTransformer;
use App\User;
use App\UserFilter;
use App\UserSetting;
use Auth;
use Cache;
use Illuminate\Http\Request;
use League\Fractal;
use View;
class ProfileController extends Controller class ProfileController extends Controller
{ {
public function show(Request $request, $username) public function show(Request $request, $username)
{ {
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
$user = $this->getCachedUser($username, true);
abort_if(! $user, 404, 'Not found');
return $this->showActivityPub($request, $user);
}
// redirect authed users to Metro 2.0 // redirect authed users to Metro 2.0
if ($request->user()) { if ($request->user()) {
// unless they force static view // unless they force static view
@ -40,17 +43,11 @@ class ProfileController extends Controller
} }
} }
$user = Profile::whereNull('domain') $user = $this->getCachedUser($username);
->whereNull('status')
->whereUsername($username)
->firstOrFail();
abort_unless($user, 404);
if($request->wantsJson() && config_cache('federation.activitypub.enabled')) { $aiCheck = Cache::remember('profile:ai-check:spam-login:'.$user->id, 3600, function () use ($user) {
return $this->showActivityPub($request, $user);
}
$aiCheck = Cache::remember('profile:ai-check:spam-login:' . $user->id, 86400, function() use($user) {
$exists = AccountInterstitial::whereUserId($user->user_id)->where('is_spam', 1)->count(); $exists = AccountInterstitial::whereUserId($user->user_id)->where('is_spam', 1)->count();
if ($exists) { if ($exists) {
return true; return true;
@ -61,6 +58,7 @@ class ProfileController extends Controller
if ($aiCheck) { if ($aiCheck) {
return redirect('/login'); return redirect('/login');
} }
return $this->buildProfile($request, $user); return $this->buildProfile($request, $user);
} }
@ -79,6 +77,7 @@ class ProfileController extends Controller
if ($user->is_private == true) { if ($user->is_private == true) {
$profile = null; $profile = null;
return view('profile.private', compact('user')); return view('profile.private', compact('user'));
} }
@ -90,13 +89,14 @@ class ProfileController extends Controller
'crawlable' => $settings->crawlable, 'crawlable' => $settings->crawlable,
'following' => [ 'following' => [
'count' => $settings->show_profile_following_count, 'count' => $settings->show_profile_following_count,
'list' => $settings->show_profile_following 'list' => $settings->show_profile_following,
], ],
'followers' => [ 'followers' => [
'count' => $settings->show_profile_follower_count, 'count' => $settings->show_profile_follower_count,
'list' => $settings->show_profile_followers 'list' => $settings->show_profile_followers,
] ],
]; ];
return view('profile.show', compact('profile', 'settings')); return view('profile.show', compact('profile', 'settings'));
} else { } else {
$key = 'profile:settings:'.$user->id; $key = 'profile:settings:'.$user->id;
@ -118,6 +118,7 @@ class ProfileController extends Controller
$requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id) $requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id)
->whereFollowingId($user->id) ->whereFollowingId($user->id)
->exists() : false; ->exists() : false;
return view('profile.private', compact('user', 'is_following', 'requested')); return view('profile.private', compact('user', 'is_following', 'requested'));
} }
@ -127,25 +128,50 @@ class ProfileController extends Controller
'crawlable' => $settings->crawlable, 'crawlable' => $settings->crawlable,
'following' => [ 'following' => [
'count' => $settings->show_profile_following_count, 'count' => $settings->show_profile_following_count,
'list' => $settings->show_profile_following 'list' => $settings->show_profile_following,
], ],
'followers' => [ 'followers' => [
'count' => $settings->show_profile_follower_count, 'count' => $settings->show_profile_follower_count,
'list' => $settings->show_profile_followers 'list' => $settings->show_profile_followers,
] ],
]; ];
return view('profile.show', compact('profile', 'settings')); return view('profile.show', compact('profile', 'settings'));
} }
} }
protected function getCachedUser($username, $withTrashed = false)
{
$val = str_replace(['_', '.', '-'], '', $username);
if (! ctype_alnum($val)) {
return;
}
$hash = ($withTrashed ? 'wt:' : 'wot:').strtolower($username);
return Cache::remember('pfc:cached-user:'.$hash, ($withTrashed ? 14400 : 900), function () use ($username, $withTrashed) {
if (! $withTrashed) {
return Profile::whereNull(['domain', 'status'])
->whereUsername($username)
->first();
} else {
return Profile::withTrashed()
->whereNull('domain')
->whereUsername($username)
->first();
}
});
}
public function permalinkRedirect(Request $request, $username) public function permalinkRedirect(Request $request, $username)
{ {
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
$user = $this->getCachedUser($username, true);
if ($request->wantsJson() && config_cache('federation.activitypub.enabled')) {
return $this->showActivityPub($request, $user); return $this->showActivityPub($request, $user);
} }
$user = $this->getCachedUser($username);
return redirect($user->url()); return redirect($user->url());
} }
@ -180,6 +206,7 @@ class ProfileController extends Controller
default: default:
break; break;
} }
return abort(404); return abort(404);
} }
@ -201,12 +228,14 @@ class ProfileController extends Controller
public function showActivityPub(Request $request, $user) public function showActivityPub(Request $request, $user)
{ {
abort_if(! config_cache('federation.activitypub.enabled'), 404); abort_if(! config_cache('federation.activitypub.enabled'), 404);
abort_if(! $user, 404, 'Not found');
abort_if($user->domain, 404); abort_if($user->domain, 404);
return Cache::remember('pf:activitypub:user-object:by-id:' . $user->id, 3600, function() use($user) { return Cache::remember('pf:activitypub:user-object:by-id:'.$user->id, 1800, function () use ($user) {
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager();
$resource = new Fractal\Resource\Item($user, new ProfileTransformer); $resource = new Fractal\Resource\Item($user, new ProfileTransformer);
$res = $fractal->createData($resource)->toArray(); $res = $fractal->createData($resource)->toArray();
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json'); return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
}); });
} }
@ -253,7 +282,7 @@ class ProfileController extends Controller
abort_if(! $enabled, 404); abort_if(! $enabled, 404);
$data = Cache::remember('pf:atom:user-feed:by-id:' . $profile['id'], 900, function() use($pid, $profile) { $data = Cache::remember('pf:atom:user-feed:by-id:'.$profile['id'], 14400, function () use ($pid, $profile) {
$items = Status::whereProfileId($pid) $items = Status::whereProfileId($pid)
->whereScope('public') ->whereScope('public')
->whereIn('type', ['photo', 'photo:album']) ->whereIn('type', ['photo', 'photo:album'])
@ -280,12 +309,13 @@ class ProfileController extends Controller
return compact('items', 'permalink', 'headers'); return compact('items', 'permalink', 'headers');
}); });
abort_if(! $data || ! isset($data['items']) || ! isset($data['permalink']), 404); abort_if(! $data || ! isset($data['items']) || ! isset($data['permalink']), 404);
return response() return response()
->view('atom.user', ->view('atom.user',
[ [
'profile' => $profile, 'profile' => $profile,
'items' => $data['items'], 'items' => $data['items'],
'permalink' => $data['permalink'] 'permalink' => $data['permalink'],
] ]
) )
->withHeaders($data['headers']); ->withHeaders($data['headers']);
@ -294,6 +324,7 @@ class ProfileController extends Controller
public function meRedirect() public function meRedirect()
{ {
abort_if(! Auth::check(), 404); abort_if(! Auth::check(), 404);
return redirect(Auth::user()->url()); return redirect(Auth::user()->url());
} }
@ -309,13 +340,9 @@ class ProfileController extends Controller
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
$profile = Profile::whereUsername($username) $profile = $this->getCachedUser($username);
->whereIsPrivate(false)
->whereNull('status')
->whereNull('domain')
->first();
if(!$profile) { if (! $profile || $profile->is_private) {
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
@ -338,6 +365,7 @@ class ProfileController extends Controller
$profile = AccountService::get($profile->id); $profile = AccountService::get($profile->id);
$res = view('profile.embed', compact('profile')); $res = view('profile.embed', compact('profile'));
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
} }
@ -352,6 +380,7 @@ class ProfileController extends Controller
->whereActive(true) ->whereActive(true)
->exists(); ->exists();
abort_unless($exists, 404); abort_unless($exists, 404);
return view('profile.story', compact('pid', 'profile')); return view('profile.story', compact('pid', 'profile'));
} }
} }

View file

@ -95,6 +95,8 @@ trait PrivacySettings
Cache::forget('pf:acct:settings:hidden-following:' . $pid); Cache::forget('pf:acct:settings:hidden-following:' . $pid);
Cache::forget('pf:acct-trans:hideFollowing:' . $pid); Cache::forget('pf:acct-trans:hideFollowing:' . $pid);
Cache::forget('pf:acct-trans:hideFollowers:' . $pid); Cache::forget('pf:acct-trans:hideFollowers:' . $pid);
Cache::forget('pfc:cached-user:wt:' . strtolower($profile->username));
Cache::forget('pfc:cached-user:wot:' . strtolower($profile->username));
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
} }

View file

@ -2,14 +2,18 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Page;
use App\Profile;
use App\Services\FollowerService;
use App\Status;
use App\User;
use App\Util\ActivityPub\Helpers;
use App\Util\Localization\Localization;
use Auth;
use Cache;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App, Auth, Cache, View; use View;
use App\Util\Lexer\PrettyNumber;
use App\{Follower, Page, Profile, Status, User, UserFilter};
use App\Util\Localization\Localization;
use App\Services\FollowerService;
use App\Util\ActivityPub\Helpers;
class SiteController extends Controller class SiteController extends Controller
{ {
@ -58,6 +62,7 @@ class SiteController extends Controller
$user_count = number_format(User::count()); $user_count = number_format(User::count());
$post_count = number_format(Status::count()); $post_count = number_format(Status::count());
$rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null; $rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null;
return view('site.about', compact('rules', 'user_count', 'post_count'))->render(); return view('site.about', compact('rules', 'user_count', 'post_count'))->render();
}); });
} }
@ -72,6 +77,7 @@ class SiteController extends Controller
return Cache::remember('site:help:community-guidelines', now()->addDays(120), function () { return Cache::remember('site:help:community-guidelines', now()->addDays(120), function () {
$slug = '/site/kb/community-guidelines'; $slug = '/site/kb/community-guidelines';
$page = Page::whereSlug($slug)->whereActive(true)->first(); $page = Page::whereSlug($slug)->whereActive(true)->first();
return View::make('site.help.community-guidelines')->with(compact('page'))->render(); return View::make('site.help.community-guidelines')->with(compact('page'))->render();
}); });
} }
@ -80,8 +86,10 @@ class SiteController extends Controller
{ {
$page = Cache::remember('site:privacy', now()->addDays(120), function () { $page = Cache::remember('site:privacy', now()->addDays(120), function () {
$slug = '/site/privacy'; $slug = '/site/privacy';
return Page::whereSlug($slug)->whereActive(true)->first(); return Page::whereSlug($slug)->whereActive(true)->first();
}); });
return View::make('site.privacy')->with(compact('page'))->render(); return View::make('site.privacy')->with(compact('page'))->render();
} }
@ -89,8 +97,10 @@ class SiteController extends Controller
{ {
$page = Cache::remember('site:terms', now()->addDays(120), function () { $page = Cache::remember('site:terms', now()->addDays(120), function () {
$slug = '/site/terms'; $slug = '/site/terms';
return Page::whereSlug($slug)->whereActive(true)->first(); return Page::whereSlug($slug)->whereActive(true)->first();
}); });
return View::make('site.terms')->with(compact('page'))->render(); return View::make('site.terms')->with(compact('page'))->render();
} }
@ -98,10 +108,11 @@ class SiteController extends Controller
{ {
abort_if(! $request->user(), 404); abort_if(! $request->user(), 404);
$this->validate($request, [ $this->validate($request, [
'url' => 'required|url' 'url' => 'required|url',
]); ]);
$url = request()->input('url'); $url = request()->input('url');
abort_if(Helpers::validateUrl($url) == false, 404); abort_if(Helpers::validateUrl($url) == false, 404);
return view('site.redirect', compact('url')); return view('site.redirect', compact('url'));
} }
@ -114,6 +125,7 @@ class SiteController extends Controller
$user = $request->user(); $user = $request->user();
abort_if($user && $profile->id == $user->profile_id, 404); abort_if($user && $profile->id == $user->profile_id, 404);
$following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false; $following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false;
return view('site.intents.follow', compact('profile', 'user', 'following')); return view('site.intents.follow', compact('profile', 'user', 'following'));
} }
@ -159,9 +171,33 @@ class SiteController extends Controller
{ {
$page = Cache::remember('site:legal-notice', now()->addDays(120), function () { $page = Cache::remember('site:legal-notice', now()->addDays(120), function () {
$slug = '/site/legal-notice'; $slug = '/site/legal-notice';
return Page::whereSlug($slug)->whereActive(true)->first(); return Page::whereSlug($slug)->whereActive(true)->first();
}); });
abort_if(! $page, 404); abort_if(! $page, 404);
return View::make('site.legal-notice')->with(compact('page'))->render(); return View::make('site.legal-notice')->with(compact('page'))->render();
} }
public function curatedOnboarding(Request $request)
{
if ($request->user()) {
return redirect('/i/web');
}
$regOpen = (bool) config_cache('pixelfed.open_registration');
$curOnboarding = (bool) config_cache('instance.curated_registration.enabled');
$curOnlyClosed = (bool) config('instance.curated_registration.state.only_enabled_on_closed_reg');
if ($regOpen) {
if ($curOnlyClosed) {
return redirect('/register');
}
} else {
if (! $curOnboarding) {
return redirect('/');
}
}
return view('auth.curated-register.index', ['step' => 1]);
}
} }

View file

@ -3,8 +3,8 @@
namespace App\Transformer\ActivityPub; namespace App\Transformer\ActivityPub;
use App\Profile; use App\Profile;
use League\Fractal;
use App\Services\AccountService; use App\Services\AccountService;
use League\Fractal;
class ProfileTransformer extends Fractal\TransformerAbstract class ProfileTransformer extends Fractal\TransformerAbstract
{ {
@ -19,13 +19,14 @@ class ProfileTransformer extends Fractal\TransformerAbstract
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'alsoKnownAs' => [ 'alsoKnownAs' => [
'@id' => 'as:alsoKnownAs', '@id' => 'as:alsoKnownAs',
'@type' => '@id' '@type' => '@id',
], ],
'movedTo' => [ 'movedTo' => [
'@id' => 'as:movedTo', '@id' => 'as:movedTo',
'@type' => '@id' '@type' => '@id',
], ],
'indexable' => 'toot:indexable', 'indexable' => 'toot:indexable',
'suspended' => 'toot:suspended',
], ],
], ],
'id' => $profile->permalink(), 'id' => $profile->permalink(),
@ -52,16 +53,28 @@ class ProfileTransformer extends Fractal\TransformerAbstract
'url' => $profile->avatarUrl(), 'url' => $profile->avatarUrl(),
], ],
'endpoints' => [ 'endpoints' => [
'sharedInbox' => config('app.url') . '/f/inbox' 'sharedInbox' => config('app.url').'/f/inbox',
] ],
]; ];
if ($profile->status === 'delete' || $profile->deleted_at != null) {
$res['suspended'] = true;
$res['name'] = '';
unset($res['icon']);
$res['summary'] = '';
$res['indexable'] = false;
$res['manuallyApprovesFollowers'] = false;
} else {
if ($profile->aliases->count()) { if ($profile->aliases->count()) {
$res['alsoKnownAs'] = $profile->aliases->map(fn ($alias) => $alias->uri); $res['alsoKnownAs'] = $profile->aliases->map(fn ($alias) => $alias->uri);
} }
if ($profile->moved_to_profile_id) { if ($profile->moved_to_profile_id) {
$res['movedTo'] = AccountService::get($profile->moved_to_profile_id)['url']; $movedTo = AccountService::get($profile->moved_to_profile_id);
if ($movedTo && isset($movedTo['url'], $movedTo['id'])) {
$res['movedTo'] = $movedTo['url'];
}
}
} }
return $res; return $res;

View file

@ -0,0 +1,24 @@
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\Profile;
use League\Fractal;
class DeleteActor extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
return [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $profile->permalink('#delete'),
'type' => 'Delete',
'actor' => $profile->permalink(),
'to' => [
'https://www.w3.org/ns/activitystreams#Public'
],
'object' => $profile->permalink()
];
}
}

View file

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('instances', function (Blueprint $table) {
$table->string('shared_inbox')->nullable()->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('instances', function (Blueprint $table) {
$table->dropColumn('shared_inbox');
});
}
};

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Instance;
use App\Profile;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
foreach(Instance::lazyById(50, 'id') as $instance) {
$si = Profile::whereDomain($instance->domain)->whereNotNull('sharedInbox')->first();
if($si && $si->sharedInbox) {
$instance->shared_inbox = $si->sharedInbox;
$instance->save();
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
}
};

View file

@ -29,7 +29,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('auth/pci/{id}/{code}', 'ParentalControlsController@inviteRegister'); Route::get('auth/pci/{id}/{code}', 'ParentalControlsController@inviteRegister');
Route::post('auth/pci/{id}/{code}', 'ParentalControlsController@inviteRegisterStore'); Route::post('auth/pci/{id}/{code}', 'ParentalControlsController@inviteRegisterStore');
Route::get('auth/sign_up', 'CuratedRegisterController@index')->name('auth.curated-onboarding'); Route::get('auth/sign_up', 'SiteController@curatedOnboarding')->name('auth.curated-onboarding');
Route::post('auth/sign_up', 'CuratedRegisterController@proceed'); Route::post('auth/sign_up', 'CuratedRegisterController@proceed');
Route::get('auth/sign_up/concierge/response-sent', 'CuratedRegisterController@conciergeResponseSent'); Route::get('auth/sign_up/concierge/response-sent', 'CuratedRegisterController@conciergeResponseSent');
Route::get('auth/sign_up/concierge', 'CuratedRegisterController@concierge'); Route::get('auth/sign_up/concierge', 'CuratedRegisterController@concierge');