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

feat(profile): support bluesky and mastodon #41 #44

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Filament/Resources/ProfileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static function form(Form $form): Form
->maxLength(255),
Forms\Components\TextInput::make('twitter')
->maxLength(1024),
Forms\Components\TextInput::make('mastodon')
->maxLength(1024),
Forms\Components\TextInput::make('bluesky')
->maxLength(1024),
Forms\Components\TextInput::make('telegram')
->maxLength(1024),
Forms\Components\TextInput::make('discord')
Expand Down Expand Up @@ -83,6 +87,8 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('art_desc'),
Tables\Columns\TextColumn::make('website'),
Tables\Columns\TextColumn::make('twitter'),
Tables\Columns\TextColumn::make('mastodon'),
Tables\Columns\TextColumn::make('bluesky'),
Tables\Columns\TextColumn::make('telegram'),
Tables\Columns\TextColumn::make('discord'),
Tables\Columns\TextColumn::make('tweet'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function exportAppDataAdmin()
{
/** @var User $user */
$user = Auth::user();
abort_if($user->isAdmin(), 403, 'Insufficient permissions');
abort_if(!$user->isAdmin(), 403, 'Insufficient permissions');
return $this->exportAppData();
}

Expand Down
35 changes: 29 additions & 6 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class ProfileController extends Controller

public function index()
{

}

public function create(Request $request)
{

}

public static function createOrUpdate(Request $request, int $applicationId): Profile
Expand All @@ -31,6 +29,8 @@ public static function createOrUpdate(Request $request, int $applicationId): Pro
"art_desc" => $request->get('art_desc'),
"website" => $request->get('profile_website'),
"twitter" => $request->get('twitter'),
"mastodon" => $request->get('mastodon'),
"bluesky" => $request->get('bluesky'),
"telegram" => $request->get('telegram'),
"discord" => $request->get('discord'),
"tweet" => $request->get('tweet'),
Expand Down Expand Up @@ -86,12 +86,10 @@ public static function getByApplicationId(int|null $applicationId): Profile|null

public function store(Request $request)
{

}

public function show(Profile $profile)
{

}

public function edit(Profile $profile)
Expand Down Expand Up @@ -144,6 +142,32 @@ public static function getValidations()
// Twitter user name validation: https://help.twitter.com/en/managing-your-account/twitter-username-rules
'regex:/^[0-9a-z_]{4,15}$/i',
],
"mastodon" => [
'nullable',
// Mastodon user name validation loosely based on
// https://docs.joinmastodon.org/spec/webfinger/#intro and
// https://datatracker.ietf.org/doc/html/rfc7565#section-7
/*
* acctURI = "acct" ":" userpart "@" host
* userpart = unreserved / sub-delims 0*( unreserved / pct-encoded / sub-delims )
* host = IP-literal / IPv4address / reg-name
* IP-literal = "[" ( IPv6address / IPvFuture ) "]"
* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
* reg-name = *( unreserved / pct-encoded / sub-delims )
* reserved = gen-delims / sub-delims
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"/ "*" / "+" / "," / ";" / "="
* pct-encoded = "%" HEXDIG HEXDIG
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
*/
'regex:/([A-Z0-9\-._~!$&\'\(\)\*,;=][A-Z0-9\-._~%!$&\'\(\)\*,;=]*)@([A-Z0-9\-._~%!$&\'\(\)\*,;=]+\.[A-Z]{2,})/i'
],
"bluesky" => [
'nullable',
// Bluesky user name validation:
// https://atproto.com/specs/handle
'regex:/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/',
],
"telegram" => [
'nullable',
// Telegram user name validation: https://core.telegram.org/method/account.checkUsername
Expand Down Expand Up @@ -176,8 +200,7 @@ public static function getValidations()
];
}

// FIXME: migrate to support non-local storage like S3
public static function addImagesToZip(ZipArchive $zip, string $zipFileName)
public static function addImagesToZip(ZipArchive $zip)
{
foreach (Profile::all() as $profile) {
$imgThumbnail = $profile->image_thumbnail;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public static function getAllApplicationsForAppExport()
'art_desc AS About the Art',
'profiles.website as Website',
'twitter as Twitter',
'mastodon as Mastodon',
'bluesky as Bluesky',
'telegram as Telegram',
'art_preview_caption as Art Preview Caption',
DB::raw("CASE WHEN image_thumbnail IS NOT NULL THEN 'X' ELSE '' END AS 'ThumbailImg'"),
Expand Down
2 changes: 2 additions & 0 deletions database/factories/ProfileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function definition(): array
'art_desc' => $this->faker->text(),
'website' => $this->faker->word(),
'twitter' => $this->faker->word(),
'mastodon' => $this->faker->word(),
'bluesky' => $this->faker->word(),
'telegram' => $this->faker->word(),
'discord' => $this->faker->word(),
'tweet' => $this->faker->text(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function up(): void
$table->dropColumn('is_fursuit');
$table->dropColumn('is_commissions');
$table->dropColumn('is_misc');
$table->dropColumn('is_mature');
});
}

Expand All @@ -32,7 +31,6 @@ public function down(): void
$table->boolean('is_fursuit')->nullable();
$table->boolean('is_commissions')->nullable();
$table->boolean('is_misc')->nullable();
$table->boolean('is_mature')->nullable();
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('profiles', function (Blueprint $table) {
$table->string('mastodon')->nullable()->default(null);
$table->string('bluesky')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('profiles', function (Blueprint $table) {
$table->dropColumn('mastodon');
$table->dropColumn('bluesky');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('applications', function (Blueprint $table) {
$table->string('invite_code_shares')->nullable()->unique()->change();
$table->string('invite_code_assistants')->nullable()->unique()->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->string('invite_code_shares')->nullable()->change();
$table->string('invite_code_assistants')->nullable()->change();
});
}
};
6 changes: 6 additions & 0 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
'twitter' => [
'regex' => 'Please verify your Twitter handle, it must be between 4 and 15 characters and only contain letters, numbers and underscores (_).'
],
'mastodon' => [
'regex' => 'Please verify your Mastodon handle, it must be in the format [email protected]'
],
'bluesky' => [
'regex' => 'Please verify your Bluesky handle, it may only contain letters, numbers, dots (.) and hyphens (-).'
],
'telegram' => [
'regex' => 'Please verify your Telegram handle, it must be between 5 and 32 characters and only contain letters, numbers and underscores (_).'
],
Expand Down
42 changes: 40 additions & 2 deletions resources/views/forms/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class="form-control @error('profile_website') is-invalid @enderror" id="profile_
</div>
</div>
<div class="row mb-3">
<label for="twitter" class="col-sm-2 col-form-label fw-bold">Twit&shy;ter</label>
<label for="twitter" class="col-sm-2 col-form-label fw-bold">Twit&shy;ter (cur&shy;rent&shy;ly X)</label>
<div class="col-sm-10">
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -283,7 +283,45 @@ class="form-control @error('twitter') is-invalid @enderror" id="twitter"
@enderror
</div>
<div id="twitterHelp" class="form-text">
Want to make sure people find you on Twitter? Add your handle above to guide them there!
Want to make sure people find you on Twitter (cur­rent­ly X)? Add your handle above to guide them there!
</div>
</div>
</div>
<div class="row mb-3">
<label for="mastodon" class="col-sm-2 col-form-label fw-bold">Mas&shy;to&shy;don</label>
<div class="col-sm-10">
<div class="input-group">
<div class="input-group-prepend">
<span clasS="input-group-text">@</span>
</div>
<input type="text" name="mastodon" placeholder="YourMastodonHandle"
class="form-control @error('mastodon') is-invalid @enderror" id="mastodon"
value="{{ old('_token') ? old('mastodon') : $profile?->mastodon }}">
@error('mastodon')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div id="mastodonHelp" class="form-text">
Want to make sure people find you on Mastodon? Add your handle above to guide them there!
</div>
</div>
</div>
<div class="row mb-3">
<label for="bluesky" class="col-sm-2 col-form-label fw-bold">Blue&shy;sky</label>
<div class="col-sm-10">
<div class="input-group">
<div class="input-group-prepend">
<span clasS="input-group-text">@</span>
</div>
<input type="text" name="bluesky" placeholder="YourBlueskyHandle"
class="form-control @error('bluesky') is-invalid @enderror" id="bluesky"
value="{{ old('_token') ? old('bluesky') : $profile?->bluesky }}">
@error('bluesky')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div id="blueskyHelp" class="form-text">
Want to make sure people find you on Bluesky? Add your handle above to guide them there!
</div>
</div>
</div>
Expand Down
Loading