añadir nuevas funcionalidades

This commit is contained in:
2025-04-30 20:56:28 +02:00
parent 883daf32ed
commit 655ea60d6b
71 changed files with 3836 additions and 1158 deletions

View File

@@ -15,7 +15,7 @@ return new class extends Migration
$table->id();
$table->string('name');
$table->foreignId('project_id')->constrained();
$table->foreignId('creator_id')->constrained('users');
//$table->foreignId('creator_id')->constrained('users');
$table->timestamps();
});
}

View File

@@ -0,0 +1,51 @@
<?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('users', function (Blueprint $table) {
$table->string('title')->nullable()->after('id');
$table->string('first_name')->after('title');
$table->string('last_name')->after('first_name');
$table->string('username')->unique()->after('last_name');
$table->date('access_start')->nullable()->after('password');
$table->date('access_end')->nullable()->after('access_start');
$table->string('phone')->nullable()->after('email');
$table->text('address')->nullable()->after('phone');
$table->boolean('is_active')->default(true)->after('address');
$table->string('profile_photo_path')->nullable();
// Eliminar campos no necesarios
$table->dropColumn('name');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('title');
$table->dropColumn('first_name');
$table->dropColumn('last_name');
$table->dropColumn('username');
$table->dropColumn('access_start');
$table->dropColumn('access_end');
$table->dropColumn('phone');
$table->dropColumn('address');
$table->dropColumn('is_active');
$table->dropColumn('profile_photo_path ');
$table->string('name')->after('id');
});
}
};

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('documents', function (Blueprint $table) {
$table->string('file_path')->require();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->dropColumn('file_path');
});
}
};

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('document_comments', function (Blueprint $table) {
$table->id();
$table->foreignId('document_id')->constrained();
$table->foreignId('user_id')->constrained();
$table->foreignId('parent_id')->nullable()->constrained('document_comments');
$table->text('content');
$table->unsignedInteger('page');
$table->decimal('x', 5, 3); // Posición X normalizada (0-1)
$table->decimal('y', 5, 3); // Posición Y normalizada (0-1)
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('document_comments');
}
};

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('comments', function (Blueprint $table) {
$table->id();
$table->text('content');
$table->foreignId('user_id')->constrained();
$table->foreignId('document_id')->constrained();
$table->foreignId('parent_id')->nullable()->constrained('comments');
$table->unsignedInteger('page');
$table->decimal('x', 5, 3); // Posición X (0-1)
$table->decimal('y', 5, 3); // Posición Y (0-1)
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('comments');
}
};

View File

@@ -3,9 +3,8 @@
namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\Hash;
class DatabaseSeeder extends Seeder
{
@@ -16,10 +15,14 @@ class DatabaseSeeder extends Seeder
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'admin',
User::create([
'first_name' => 'Administrador',
'last_name' => '',
'username' => 'admin',
'email' => 'admin@example.com',
'password' => '12345678',
'password' => Hash::make('12345678'),
'is_active' => true,
'access_start' => now(),
]);
$this->call([

View File

@@ -13,6 +13,7 @@ class PermissionSeeder extends Seeder
*/
public function run()
{
/*
$permissions = [
// Permissions for Projects
'create projects',
@@ -49,6 +50,22 @@ class PermissionSeeder extends Seeder
'name' => $permission,
'guard_name' => 'web'
]);
}*/
$permissions = [
'user' => ['view', 'create', 'edit', 'delete'],
'document' => ['view', 'upload', 'edit', 'delete', 'approve'],
'project' => ['view', 'create', 'edit', 'delete'],
'comment' => ['create', 'edit', 'delete'],
'folder' => ['view', 'create', 'edit', 'delete'],
'role' => ['view', 'create', 'edit', 'delete'],
'permission' => ['view', 'create', 'edit', 'delete'],
];
foreach ($permissions as $type => $actions) {
foreach ($actions as $action) {
Permission::create(['name' => "{$type}.{$action}"]);
}
}
}
}

View File

@@ -23,48 +23,10 @@ class RolePermissionSeeder extends Seeder
//['description' => 'Administrador del sistema']
);
// Obtener o crear todos los permisos existentes
$permissions = Permission::all();
if ($permissions->isEmpty()) {
// Crear permisos básicos si no existen
$permissions = collect([
'view projects',
'edit projects',
'delete projects',
'view roles',
'create roles',
'edit roles',
'delete roles',
'view permissions',
'create permissions',
'edit permissions',
'delete permissions',
'assign permissions',
'revoke permissions',
])->map(function ($permission) {
return Permission::updateOrCreate(
['name' => $permission],
['guard_name' => 'web']
);
});
}
// Sincronizar todos los permisos con el rol admin
$allPermissions = Permission::all();
$adminRole->syncPermissions($allPermissions);
$adminRole->syncPermissions($permissions);
// Crear usuario admin si no existe
/*User::updateOrCreate(
['email' => env('ADMIN_EMAIL', 'admin@example.com')],
[
'name' => 'Administrador',
'password' => bcrypt(env('ADMIN_PASSWORD', 'password')),
'email_verified_at' => now()
]
)->assignRole($adminRole);*/
$adminEmail = env('ADMIN_EMAIL', 'admin@example.com');
$user = User::where('email', $adminEmail)->first();
if ($user) {
@@ -75,9 +37,11 @@ class RolePermissionSeeder extends Seeder
} else {
// Crear solo si no existe
User::create([
'name' => 'admin',
'email' => $adminEmail,
'password' => bcrypt(env('ADMIN_PASSWORD', '12345678')),
'first_name' => 'Administrador',
'username' => 'admin',
'email' => 'admin@example.com',
'password' => '12345678',
'is_active' => true,
'email_verified_at' => now()
])->assignRole($adminRole);
}