refactor(social): address PR review follow-ups
- DeleteWorkspace now reassigns affected users to another workspace they
belong to (instead of nulling current_workspace_id), so deleting the
current workspace while owning others no longer bounces to "create".
- Remove the dead LINKEDIN_PAGE_CLIENT_REDIRECT env (the unified flow uses
a single callback; config no longer reads a page redirect).
- useOAuthPopup uses the Wayfinder connect helpers per platform instead of
hardcoding /connect/{platform}.
- Unify the Inertia\Response alias in Mastodon/Bluesky controllers to
InertiaResponse, matching the other connect controllers.
- Add tests: workspace reassignment on delete, and independent refresh of
a linkedin row vs its linkedin-page sibling.
This commit is contained in:
parent
dba6346226
commit
12a1baa757
7 changed files with 85 additions and 15 deletions
|
|
@ -107,8 +107,6 @@ LINKEDIN_CLIENT_ID=
|
|||
LINKEDIN_CLIENT_SECRET=
|
||||
LINKEDIN_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin/callback"
|
||||
# LINKEDIN_SCOPES="openid,profile,email,w_member_social"
|
||||
LINKEDIN_PAGE_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin-page/callback"
|
||||
LINKEDIN_PAGE_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin-page/callback"
|
||||
# LINKEDIN_PAGE_SCOPES="openid,profile,email,w_organization_social,r_organization_social,rw_organization_admin,w_member_social"
|
||||
|
||||
# X / Twitter (https://developer.twitter.com)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,15 @@ class DeleteWorkspace
|
|||
{
|
||||
public static function execute(User $user, Workspace $workspace): void
|
||||
{
|
||||
User::where('current_workspace_id', $workspace->id)->update(['current_workspace_id' => null]);
|
||||
User::where('current_workspace_id', $workspace->id)
|
||||
->get()
|
||||
->each(function (User $affected) use ($workspace): void {
|
||||
$fallback = $affected->workspaces()
|
||||
->where('workspaces.id', '!=', $workspace->id)
|
||||
->first();
|
||||
|
||||
$affected->update(['current_workspace_id' => $fallback?->id]);
|
||||
});
|
||||
|
||||
$account = $workspace->account;
|
||||
$accountId = (string) $workspace->account_id;
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@
|
|||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inertia\Response as InertiaResponse;
|
||||
|
||||
class BlueskyController extends SocialController
|
||||
{
|
||||
protected SocialPlatform $platform = SocialPlatform::Bluesky;
|
||||
|
||||
public function connect(Request $request): Response
|
||||
public function connect(Request $request): InertiaResponse
|
||||
{
|
||||
$this->ensurePlatformEnabled();
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ public function connect(Request $request): Response
|
|||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): Response
|
||||
public function store(Request $request): InertiaResponse
|
||||
{
|
||||
$this->ensurePlatformEnabled();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||
use Inertia\Response as InertiaResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class MastodonController extends SocialController
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ class MastodonController extends SocialController
|
|||
/**
|
||||
* Show form to enter Mastodon instance URL
|
||||
*/
|
||||
public function connect(Request $request): Response
|
||||
public function connect(Request $request): InertiaResponse
|
||||
{
|
||||
$this->ensurePlatformEnabled();
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ public function connect(Request $request): Response
|
|||
/**
|
||||
* Register app on instance and redirect to OAuth
|
||||
*/
|
||||
public function authorizeInstance(Request $request): SymfonyResponse
|
||||
public function authorizeInstance(Request $request): Response
|
||||
{
|
||||
$this->ensurePlatformEnabled();
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ public function authorizeInstance(Request $request): SymfonyResponse
|
|||
/**
|
||||
* Handle OAuth callback
|
||||
*/
|
||||
public function callback(Request $request): Response
|
||||
public function callback(Request $request): InertiaResponse
|
||||
{
|
||||
$workspaceId = session('social_connect_workspace');
|
||||
$savedState = session('mastodon_oauth_state');
|
||||
|
|
|
|||
|
|
@ -1,20 +1,56 @@
|
|||
import { onMounted, onUnmounted } from 'vue';
|
||||
|
||||
import { connect as blueskyConnect } from '@/routes/app/social/bluesky';
|
||||
import { connect as discordConnect } from '@/routes/app/social/discord';
|
||||
import { connect as facebookConnect } from '@/routes/app/social/facebook';
|
||||
import { connect as instagramConnect } from '@/routes/app/social/instagram';
|
||||
import { connect as instagramFacebookConnect } from '@/routes/app/social/instagram-facebook';
|
||||
import { connect as linkedinConnect } from '@/routes/app/social/linkedin';
|
||||
import { connect as mastodonConnect } from '@/routes/app/social/mastodon';
|
||||
import { connect as pinterestConnect } from '@/routes/app/social/pinterest';
|
||||
import { connect as threadsConnect } from '@/routes/app/social/threads';
|
||||
import { connect as tiktokConnect } from '@/routes/app/social/tiktok';
|
||||
import { connect as xConnect } from '@/routes/app/social/x';
|
||||
import { connect as youtubeConnect } from '@/routes/app/social/youtube';
|
||||
import { Platform } from '@/types/platform';
|
||||
|
||||
const POPUP_WIDTH = 600;
|
||||
const POPUP_HEIGHT = 700;
|
||||
|
||||
const CONNECT_ROUTES: Record<string, { url: () => string }> = {
|
||||
[Platform.Bluesky]: blueskyConnect,
|
||||
[Platform.Discord]: discordConnect,
|
||||
[Platform.Facebook]: facebookConnect,
|
||||
[Platform.Instagram]: instagramConnect,
|
||||
[Platform.InstagramFacebook]: instagramFacebookConnect,
|
||||
[Platform.LinkedIn]: linkedinConnect,
|
||||
[Platform.LinkedInPage]: linkedinConnect,
|
||||
[Platform.Mastodon]: mastodonConnect,
|
||||
[Platform.Pinterest]: pinterestConnect,
|
||||
[Platform.Threads]: threadsConnect,
|
||||
[Platform.TikTok]: tiktokConnect,
|
||||
[Platform.X]: xConnect,
|
||||
[Platform.YouTube]: youtubeConnect,
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a platform's `/connect/{platform}` OAuth flow in a centered popup and
|
||||
* invokes `onSuccess` when the popup posts back the `social-oauth-callback`
|
||||
* message. The listener is wired to the calling component's lifecycle.
|
||||
* Opens a platform's OAuth connect flow in a centered popup and invokes
|
||||
* `onSuccess` when the popup posts back the `social-oauth-callback` message.
|
||||
* The listener is wired to the calling component's lifecycle.
|
||||
*/
|
||||
export const useOAuthPopup = (onSuccess: () => void) => {
|
||||
const openOAuthPopup = (platform: string) => {
|
||||
const route = CONNECT_ROUTES[platform];
|
||||
|
||||
if (!route) {
|
||||
return;
|
||||
}
|
||||
|
||||
const left = window.screenX + (window.outerWidth - POPUP_WIDTH) / 2;
|
||||
const top = window.screenY + (window.outerHeight - POPUP_HEIGHT) / 2;
|
||||
|
||||
window.open(
|
||||
`/connect/${platform}`,
|
||||
route.url(),
|
||||
'oauth-popup',
|
||||
`width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top},scrollbars=yes,resizable=yes`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,24 @@
|
|||
Http::assertSent(fn ($request) => str_contains($request->url(), 'linkedin.com/oauth/v2/accessToken'));
|
||||
});
|
||||
|
||||
test('refreshing one linkedin row leaves a sibling linkedin-page row untouched', function () {
|
||||
Http::fake([
|
||||
'www.linkedin.com/oauth/v2/accessToken' => Http::response([
|
||||
'access_token' => 'new_token',
|
||||
'refresh_token' => 'new_refresh_token',
|
||||
'expires_in' => 5184000,
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$person = SocialAccount::factory()->linkedin()->create(['refresh_token' => 'old_refresh_token']);
|
||||
$page = SocialAccount::factory()->linkedinPage()->create(['refresh_token' => 'old_refresh_token']);
|
||||
|
||||
(new ConnectionVerifier)->refreshToken($person);
|
||||
|
||||
expect($person->fresh()->refresh_token)->toBe('new_refresh_token');
|
||||
expect($page->fresh()->refresh_token)->toBe('old_refresh_token');
|
||||
});
|
||||
|
||||
test('refreshes x token before verifying when expired', function () {
|
||||
Http::fake([
|
||||
'api.x.com/2/oauth2/token' => Http::response([
|
||||
|
|
|
|||
|
|
@ -431,6 +431,16 @@
|
|||
expect($this->user->current_workspace_id)->toBeNull();
|
||||
});
|
||||
|
||||
test('destroy workspace reassigns current to another joined workspace', function () {
|
||||
$other = Workspace::factory()->create(['user_id' => $this->user->id]);
|
||||
$other->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
||||
|
||||
$this->actingAs($this->user)->delete(route('app.workspaces.destroy', $this->workspace));
|
||||
|
||||
$this->user->refresh();
|
||||
expect($this->user->current_workspace_id)->toBe($other->id);
|
||||
});
|
||||
|
||||
test('destroy workspace is blocked when it is the only workspace', function () {
|
||||
config(['trypost.self_hosted' => false]);
|
||||
$this->user->account->subscriptions()->create([
|
||||
|
|
|
|||
Loading…
Reference in a new issue