implement new feature

This commit is contained in:
subhajit 2026-07-16 17:31:32 +05:30
parent d2c286e326
commit 462762a13f
10 changed files with 561 additions and 1 deletions

View File

@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\PersonalApp;
use Laravel\Socialite\Facades\Socialite;
class DashboardController extends Controller
@ -19,7 +20,10 @@ public function index()
// Get authorized apps for this user
$services = $user->authorizedApps();
return view('dashboard', compact('user', 'services'));
// Get personal custom apps for this user
$personalApps = $user->personalApps()->orderBy('name', 'asc')->get();
return view('dashboard', compact('user', 'services', 'personalApps'));
}
/**
@ -148,4 +152,94 @@ public function launchApp(Request $request)
return view('sso.launch-app', compact('name', 'url', 'protocol'));
}
/**
* Store a new user custom personal app.
*/
public function storePersonalApp(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'url' => 'required|url|max:255',
'logo' => 'nullable|file|mimes:jpg,jpeg,png,webp,svg|max:2048',
'color' => 'nullable|string|max:20',
'desc' => 'nullable|string',
'tag' => 'nullable|string|max:255',
]);
$logoPath = null;
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$filename = time() . '_' . uniqid() . '.' . $file->getClientOriginalExtension();
$file->move(public_path('uploads/logos'), $filename);
$logoPath = 'uploads/logos/' . $filename;
}
Auth::user()->personalApps()->create([
'name' => $request->name,
'url' => $request->url,
'logo' => $logoPath,
'color' => $request->color ?? '#4f46e5',
'desc' => $request->desc,
'tag' => $request->tag ?? 'Personal',
]);
return redirect()->route('dashboard')->with('success', 'Custom app added successfully.');
}
/**
* Update an existing user custom personal app.
*/
public function updatePersonalApp(Request $request, $id)
{
$app = Auth::user()->personalApps()->findOrFail($id);
$request->validate([
'name' => 'required|string|max:255',
'url' => 'required|url|max:255',
'logo' => 'nullable|file|mimes:jpg,jpeg,png,webp,svg|max:2048',
'color' => 'nullable|string|max:20',
'desc' => 'nullable|string',
'tag' => 'nullable|string|max:255',
]);
$logoPath = $app->logo;
if ($request->hasFile('logo')) {
// Delete old file
if ($app->logo && file_exists(public_path($app->logo))) {
@unlink(public_path($app->logo));
}
$file = $request->file('logo');
$filename = time() . '_' . uniqid() . '.' . $file->getClientOriginalExtension();
$file->move(public_path('uploads/logos'), $filename);
$logoPath = 'uploads/logos/' . $filename;
}
$app->update([
'name' => $request->name,
'url' => $request->url,
'logo' => $logoPath,
'color' => $request->color ?? '#4f46e5',
'desc' => $request->desc,
'tag' => $request->tag ?? 'Personal',
]);
return redirect()->route('dashboard')->with('success', 'Custom app updated successfully.');
}
/**
* Delete a user custom personal app.
*/
public function destroyPersonalApp($id)
{
$app = Auth::user()->personalApps()->findOrFail($id);
if ($app->logo && file_exists(public_path($app->logo))) {
@unlink(public_path($app->logo));
}
$app->delete();
return redirect()->route('dashboard')->with('success', 'Custom app deleted successfully.');
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Attributes\Fillable;
#[Fillable(['user_id', 'name', 'url', 'logo', 'color', 'desc', 'tag'])]
class PersonalApp extends Model
{
/**
* Get the user that owns the custom app.
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -56,6 +56,14 @@ public function overrides()
return $this->hasMany(UserAppOverride::class);
}
/**
* Get the personal custom apps for this user.
*/
public function personalApps()
{
return $this->hasMany(PersonalApp::class);
}
/**
* Get the authorized apps for this user, computed from roles and overrides.
*/

View File

@ -0,0 +1,34 @@
<?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::create('personal_apps', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->string('name');
$table->string('url');
$table->string('logo')->nullable();
$table->string('color')->default('#4f46e5');
$table->text('desc')->nullable();
$table->string('tag')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_apps');
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -22,6 +22,138 @@
--info-color: #06b6d4;
}
.personal-app-card:hover .personal-app-actions {
opacity: 1 !important;
pointer-events: auto !important;
}
/* Personal Modal Styling */
.personal-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(11, 15, 25, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
pointer-events: none;
transition: all 0.3s ease;
}
.personal-modal.active {
opacity: 1;
pointer-events: all;
}
.personal-modal-content {
background-color: rgba(25, 30, 45, 0.9);
border: 1px solid var(--card-border);
border-radius: 20px;
padding: 30px;
width: 90%;
max-width: 500px;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
transform: scale(0.9);
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
max-height: 90vh;
overflow-y: auto;
}
.personal-modal.active .personal-modal-content {
transform: scale(1);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
border-bottom: 1px solid rgba(255,255,255,0.08);
padding-bottom: 12px;
}
.modal-title {
font-family: 'Outfit', sans-serif;
font-size: 1.2rem;
font-weight: 700;
color: #a5b4fc;
}
.modal-close {
background: none;
border: none;
color: var(--text-muted);
font-size: 1.5rem;
cursor: pointer;
transition: color 0.2s;
}
.modal-close:hover {
color: white;
}
.form-group {
margin-bottom: 16px;
}
.form-label {
display: block;
font-size: 0.75rem;
color: var(--text-muted);
margin-bottom: 6px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.3px;
}
.form-input {
width: 100%;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--card-border);
border-radius: 8px;
color: white;
outline: none;
font-size: 0.85rem;
transition: all 0.2s;
}
.form-input:focus {
border-color: var(--accent-primary);
background: rgba(255, 255, 255, 0.06);
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 24px;
border-top: 1px solid rgba(255,255,255,0.08);
padding-top: 16px;
}
.btn-cancel {
padding: 8px 16px;
border-radius: 8px;
border: 1px solid var(--card-border);
background: transparent;
color: var(--text-main);
font-size: 0.8rem;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
}
.btn-cancel:hover {
background: rgba(255,255,255,0.05);
}
* {
box-sizing: border-box;
margin: 0;
@ -690,6 +822,71 @@
</div>
</section>
<!-- My Custom Apps Section -->
<section class="services-container" style="margin-top: 50px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); padding-bottom: 12px;">
<h2 class="section-title" style="margin-bottom: 0; border: none; padding: 0;">My Custom Apps</h2>
<button onclick="openAddPersonalAppModal()" class="nav-action-btn admin" style="background-color: var(--accent-primary); border-color: var(--accent-primary); color: white; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-transform: uppercase;">
+ Add Custom App
</button>
</div>
<div class="services-grid">
@forelse($personalApps as $pApp)
<div class="service-card-glass personal-app-card" style="--service-color: {{ $pApp->color ?? '#4f46e5' }};">
<!-- Relative Wrapper for Logo + Actions -->
<div style="position: relative; display: inline-block;">
<!-- Delete & Edit overlay buttons on hover -->
<div class="personal-app-actions" style="position: absolute; top: -6px; right: -6px; display: flex; gap: 6px; z-index: 100; opacity: 0; transition: opacity 0.2s ease; pointer-events: none;">
<button onclick="event.stopPropagation(); openEditPersonalAppModal({{ $pApp->id }}, '{{ addslashes($pApp->name) }}', '{{ addslashes($pApp->url) }}', '{{ addslashes($pApp->color) }}', '{{ addslashes($pApp->tag) }}', '{{ addslashes($pApp->desc) }}', '{{ $pApp->logo }}')"
style="pointer-events: auto; background: #6366f1; border: 1.5px solid rgba(255, 255, 255, 0.2); color: white; border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.6); transition: transform 0.2s;"
onmouseover="this.style.transform='scale(1.15)'" onmouseout="this.style.transform='scale(1)'" title="Edit App">
<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</button>
<form action="{{ route('dashboard.personal-apps.destroy', $pApp->id) }}" method="POST" onsubmit="return confirm('Are you sure you want to delete this custom app?')" style="display: inline;">
@csrf
@method('DELETE')
<button type="submit" onclick="event.stopPropagation();"
style="pointer-events: auto; background: #ef4444; border: 1.5px solid rgba(255, 255, 255, 0.2); color: white; border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.6); transition: transform 0.2s;"
onmouseover="this.style.transform='scale(1.15)'" onmouseout="this.style.transform='scale(1)'" title="Delete App">
<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
</svg>
</button>
</form>
</div>
<!-- Logo Wrapper -->
<div class="service-logo-wrapper" onclick="window.open('{{ $pApp->url }}', '_blank')">
@if($pApp->logo)
<img src="{{ asset($pApp->logo) }}" alt="{{ $pApp->name }}" class="service-logo-img">
@else
<div class="service-logo-fallback" style="background: linear-gradient(135deg, var(--service-color) 20%, rgba(255,255,255,0.05) 100%); width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-family: 'Outfit', sans-serif; font-size: 1.1rem; font-weight: 800; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.2);">
{{ strtoupper(substr($pApp->name, 0, 1)) }}
</div>
@endif
</div>
</div>
<!-- Name -->
<h3 class="service-title" onclick="window.open('{{ $pApp->url }}', '_blank')">{{ strtoupper($pApp->name) }}</h3>
@if($pApp->tag)
<div style="font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; margin-top: 4px; letter-spacing: 0.5px;">{{ $pApp->tag }}</div>
@endif
</div>
@empty
<div style="grid-column: 1 / -1; text-align: center; padding: 40px; background: rgba(255,255,255,0.02); border: 1px dashed var(--card-border); border-radius: 16px; color: var(--text-muted); font-size: 0.9rem;">
No custom apps added yet. Click "+ Add Custom App" to add your own shortcuts!
</div>
@endforelse
</div>
</section>
</main>
<!-- SSO Interstitial Loading Modal -->
@ -707,6 +904,96 @@
</div>
</div>
<!-- Add Personal App Modal -->
<div id="add-personal-app-modal" class="personal-modal">
<div class="personal-modal-content">
<div class="modal-header">
<h3 class="modal-title">Add Custom Application</h3>
<button class="modal-close" onclick="closePersonalModal('add-personal-app-modal')">&times;</button>
</div>
<form action="{{ route('dashboard.personal-apps.store') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label class="form-label">Application Name *</label>
<input type="text" name="name" required placeholder="e.g. My Github, Internal Wiki" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Redirect URL *</label>
<input type="url" name="url" required placeholder="https://github.com" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Custom Logo Image (Optional)</label>
<input type="file" name="logo" class="form-input" style="padding: 6px 12px;">
<div style="font-size:0.65rem; color:var(--text-muted); margin-top:4px;">Supported: PNG, JPG, WEBP, SVG (Max 2MB)</div>
</div>
<div class="form-group">
<label class="form-label">Brand Color (Hex Code)</label>
<div style="display: flex; gap: 8px;">
<input type="color" name="color_picker" id="add-color-picker" value="#4f46e5" oninput="document.getElementById('add-color-input').value = this.value" style="width: 40px; height: 38px; padding: 0; border: none; border-radius: 8px; cursor: pointer; background: transparent;">
<input type="text" name="color" id="add-color-input" value="#4f46e5" oninput="document.getElementById('add-color-picker').value = this.value" class="form-input" style="flex: 1;">
</div>
</div>
<div class="form-group">
<label class="form-label">Category Tag (Optional)</label>
<input type="text" name="tag" placeholder="e.g. Development, HR, Tools" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Description (Optional)</label>
<textarea name="desc" placeholder="Brief note about this shortcut..." class="form-input" style="min-height: 80px; resize: vertical;"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn-cancel" onclick="closePersonalModal('add-personal-app-modal')">Cancel</button>
<button type="submit" class="nav-action-btn admin" style="background-color: var(--accent-primary); border-color: var(--accent-primary); color: white; cursor: pointer;">Save Application</button>
</div>
</form>
</div>
</div>
<!-- Edit Personal App Modal -->
<div id="edit-personal-app-modal" class="personal-modal">
<div class="personal-modal-content">
<div class="modal-header">
<h3 class="modal-title">Edit Custom Application</h3>
<button class="modal-close" onclick="closePersonalModal('edit-personal-app-modal')">&times;</button>
</div>
<form id="edit-personal-app-form" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label class="form-label">Application Name *</label>
<input type="text" id="edit-papp-name" name="name" required class="form-input">
</div>
<div class="form-group">
<label class="form-label">Redirect URL *</label>
<input type="url" id="edit-papp-url" name="url" required class="form-input">
</div>
<div class="form-group">
<label class="form-label">Custom Logo Image (Optional)</label>
<input type="file" name="logo" class="form-input" style="padding: 6px 12px;">
<div id="edit-papp-logo-status" style="font-size:0.65rem; margin-top:4px;"></div>
</div>
<div class="form-group">
<label class="form-label">Brand Color (Hex Code)</label>
<div style="display: flex; gap: 8px;">
<input type="color" id="edit-papp-color-picker" oninput="document.getElementById('edit-papp-color').value = this.value" style="width: 40px; height: 38px; padding: 0; border: none; border-radius: 8px; cursor: pointer; background: transparent;">
<input type="text" name="color" id="edit-papp-color" oninput="document.getElementById('edit-papp-color-picker').value = this.value" class="form-input" style="flex: 1;">
</div>
</div>
<div class="form-group">
<label class="form-label">Category Tag (Optional)</label>
<input type="text" id="edit-papp-tag" name="tag" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Description (Optional)</label>
<textarea id="edit-papp-desc" name="desc" class="form-input" style="min-height: 80px; resize: vertical;"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn-cancel" onclick="closePersonalModal('edit-personal-app-modal')">Cancel</button>
<button type="submit" class="nav-action-btn admin" style="background-color: var(--accent-primary); border-color: var(--accent-primary); color: white; cursor: pointer;">Update Application</button>
</div>
</form>
</div>
</div>
<script>
function launchSSO(serviceName, url) {
const modal = document.getElementById('sso-modal');
@ -722,6 +1009,37 @@ function launchSSO(serviceName, url) {
window.open(url, '_blank');
}, 1200);
}
function openAddPersonalAppModal() {
document.getElementById('add-personal-app-modal').classList.add('active');
}
function openEditPersonalAppModal(id, name, url, color, tag, desc, logo) {
const form = document.getElementById('edit-personal-app-form');
form.action = `{{ route('dashboard.personal-apps.update', ':id') }}`.replace(':id', id);
document.getElementById('edit-papp-name').value = name;
document.getElementById('edit-papp-url').value = url;
document.getElementById('edit-papp-color').value = color || '#4f46e5';
document.getElementById('edit-papp-color-picker').value = color || '#4f46e5';
document.getElementById('edit-papp-tag').value = tag || '';
document.getElementById('edit-papp-desc').value = desc || '';
const logoStatus = document.getElementById('edit-papp-logo-status');
if (logo) {
logoStatus.innerText = 'Has custom logo uploaded';
logoStatus.style.color = '#10b981';
} else {
logoStatus.innerText = 'No custom logo uploaded (using name fallback)';
logoStatus.style.color = '#9ca3af';
}
document.getElementById('edit-personal-app-modal').classList.add('active');
}
function closePersonalModal(modalId) {
document.getElementById(modalId).classList.remove('active');
}
</script>
</body>
</html>

View File

@ -27,6 +27,11 @@
Route::get('/sso/launch/{id}', [DashboardController::class, 'launchSSO'])->name('sso.launch');
Route::get('/sso/callback', [DashboardController::class, 'handleSSOCallback'])->name('sso.callback');
Route::get('/sso/launch-app', [DashboardController::class, 'launchApp'])->name('sso.launch-app');
// Personal custom apps management
Route::post('/dashboard/personal-apps', [DashboardController::class, 'storePersonalApp'])->name('dashboard.personal-apps.store');
Route::post('/dashboard/personal-apps/{id}/update', [DashboardController::class, 'updatePersonalApp'])->name('dashboard.personal-apps.update');
Route::delete('/dashboard/personal-apps/{id}', [DashboardController::class, 'destroyPersonalApp'])->name('dashboard.personal-apps.destroy');
});

View File

@ -434,4 +434,87 @@ public function test_admin_toggle_privileges(): void
$response3->assertRedirect(route('admin.dashboard'));
$this->assertTrue($admin->fresh()->isAdmin());
}
/**
* Test user personal custom apps CRUD and isolation.
*/
public function test_user_personal_custom_apps(): void
{
$user1 = User::create([
'name' => 'User One',
'email' => 'user1@sentientgeeks.com',
'role' => 'user',
]);
$user2 = User::create([
'name' => 'User Two',
'email' => 'user2@sentientgeeks.com',
'role' => 'user',
]);
$this->withoutMiddleware(\Illuminate\Foundation\Http\Middleware\PreventRequestForgery::class);
// 1. Create personal app
$response = $this->actingAs($user1)
->post(route('dashboard.personal-apps.store'), [
'name' => 'My Test App',
'url' => 'https://example.com/test',
'color' => '#123456',
'tag' => 'Testing',
'desc' => 'Some description'
]);
$response->assertRedirect(route('dashboard'));
$this->assertDatabaseHas('personal_apps', [
'user_id' => $user1->id,
'name' => 'My Test App',
'url' => 'https://example.com/test',
'color' => '#123456'
]);
$personalApp = \App\Models\PersonalApp::where('name', 'My Test App')->first();
$this->assertNotNull($personalApp);
// 2. View dashboard and see the custom app
$viewResponse = $this->actingAs($user1)->get('/dashboard');
$viewResponse->assertStatus(200);
$viewResponse->assertSee('MY TEST APP'); // Displayed upper case in UI
// 3. Update personal app
$updateResponse = $this->actingAs($user1)
->post(route('dashboard.personal-apps.update', $personalApp->id), [
'name' => 'Updated Test App',
'url' => 'https://example.com/updated',
'color' => '#654321',
'tag' => 'UpdatedTag',
'desc' => 'New description'
]);
$updateResponse->assertRedirect(route('dashboard'));
$this->assertDatabaseHas('personal_apps', [
'id' => $personalApp->id,
'name' => 'Updated Test App',
'url' => 'https://example.com/updated',
'color' => '#654321'
]);
// 4. Security: User 2 cannot update User 1's custom app
$hackerResponse = $this->actingAs($user2)
->post(route('dashboard.personal-apps.update', $personalApp->id), [
'name' => 'Hacked App',
'url' => 'https://hacked.com',
]);
// Let's assert a 404 status because user2 doesn't own it (Auth::user()->personalApps()->findOrFail($id) throws ModelNotFoundException which is rendered as 404)
$hackerResponse->assertStatus(404);
// 5. Delete personal app
$deleteResponse = $this->actingAs($user1)
->delete(route('dashboard.personal-apps.destroy', $personalApp->id));
$deleteResponse->assertRedirect(route('dashboard'));
$this->assertDatabaseMissing('personal_apps', [
'id' => $personalApp->id
]);
}
}