JoshKisb / genealogy-laravel

Full genealogy application using Laravel 11, PHP 8.3, Filament 3.2 and Livewire 3.4
https://www.liberu.co.uk
MIT License
0 stars 0 forks source link

Sweep: create default permissions seeder #1

Closed JoshKisb closed 1 month ago

JoshKisb commented 1 month ago

Details

Create a seeder class database/seeders/PermissionsSeeder.php that creates all the spatie permissions as seen in the policies. app/Policies/*.php

Checklist - [X] Create `database/seeders/PermissionsSeeder.php` ✗ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b [Edit](https://github.com/JoshKisb/genealogy-laravel/edit/sweep/create_default_permissions_seeder/database/seeders/PermissionsSeeder.php) - [X] Modify `database/seeders/DatabaseSeeder.php` ✓ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b [Edit](https://github.com/JoshKisb/genealogy-laravel/edit/sweep/create_default_permissions_seeder/database/seeders/DatabaseSeeder.php)
sweep-ai[bot] commented 1 month ago

🚀 Here's the PR! #2

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 45846d6c70)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/JoshKisb/genealogy-laravel/blob/54aa8cf4fdd65a7f9bb6f1185e8888dd950f6d40/database/seeders/DatabaseSeeder.php#L1-L105

Step 2: ⌨️ Coding

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
use Spatie\Permission\Models\Permission;

class PermissionsSeeder extends Seeder
{
    public function run()
    {
        $policiesPath = app_path('Policies');
        $policyFiles = File::allFiles($policiesPath);

        foreach ($policyFiles as $policyFile) {
            $policyClass = 'App\\Policies\\' . $policyFile->getFilenameWithoutExtension();
            $policyMethods = get_class_methods($policyClass);

            foreach ($policyMethods as $method) {
                if (in_array($method, ['viewAny', 'view', 'create', 'update', 'delete', 'restore', 'forceDelete'])) {
                    Permission::findOrCreate($method);
                }
            }
        }
    }
}

This seeder class will read all the policy files in the app/Policies/ directory, extract the permission names based on the method names, and create permissions using the Spatie package.

class DatabaseSeeder extends Seeder { /** * Seed the application's database. */ public function run(): void { User::factory(1)->create(); // Addr::factory(1)->create(); // Author::factory(1)->create(); // CalendarEvent::factory(1)->create(); // Chan::factory(1)->create(); // Chat::factory(1)->create(); // ChatMessage::factory(1)->create(); //Citation::factory(1)->create(); // Company::factory(1)->create(); // Dna::factory(1)->create(); // DnaMatching::factory(1)->create(); // Event::factory(1)->create(); //Type::factory(4)->create(); //Person::factory(2)->create(); //FamilyEvent::factory(1)->create(); //Family::factory(1)->create(); // FamilySlgs::factory(1)->create(); // ForumCategory::factory(1)->create(); // ForumPostComment::factory(1)->create(); // ForumPost::factory(1)->create(); // ForumTopic::factory(1)->create(); // Geneanum::factory(1)->create(); // skipping because of missing migration // ImportJob::factory(1)->create(); // MediaObject::factory(1)->create(); // MediaObjectFile::factory(1)->create(); // Note::factory(1)->create(); // PersonAlia::factory(1)->create(); // PersonAnci::factory(1)->create(); // PersonAsso::factory(1)->create(); // PersonDesi::factory(1)->create(); // missing model // PersonEvent::factory(1)->create(); // PersonLds::factory(1)->create(); // PersonName::factory(1)->create(); // PersonNameFone::factory(1)->create(); // PersonNameRomn::factory(1)->create(); // PersonSubm::factory(1)->create(); // Place::factory(1)->create(); // Provider::factory(1)->create(); // Publication::factory(1)->create(); // Refn::factory(1)->create(); // Repository::factory(1)->create(); // SourceDataEven::factory(1)->create(); // SourceData::factory(1)->create(); // Source::factory(1)->create(); // SourceRefEven::factory(1)->create(); // SourceRef::factory(1)->create(); // SourceRepo::factory(1)->create(); // Subm::factory(1)->create(); // Subn::factory(1)->create(); // Tree::factory(1)->create(); } } class DatabaseSeeder extends Seeder { /** * Seed the application's database. */ public function run(): void { User::factory(1)->create(); // Addr::factory(1)->create(); // Author::factory(1)->create(); // CalendarEvent::factory(1)->create(); // Chan::factory(1)->create(); // Chat::factory(1)->create(); // ChatMessage::factory(1)->create(); //Citation::factory(1)->create(); // Company::factory(1)->create(); // Dna::factory(1)->create(); // DnaMatching::factory(1)->create(); // Event::factory(1)->create(); //Type::factory(4)->create(); //Person::factory(2)->create(); //FamilyEvent::factory(1)->create(); //Family::factory(1)->create(); // FamilySlgs::factory(1)->create(); // ForumCategory::factory(1)->create(); // ForumPostComment::factory(1)->create(); // ForumPost::factory(1)->create(); // ForumTopic::factory(1)->create(); // Geneanum::factory(1)->create(); // skipping because of missing migration // ImportJob::factory(1)->create(); // MediaObject::factory(1)->create(); // MediaObjectFile::factory(1)->create(); // Note::factory(1)->create(); // PersonAlia::factory(1)->create(); // PersonAnci::factory(1)->create(); // PersonAsso::factory(1)->create(); // PersonDesi::factory(1)->create(); // missing model // PersonEvent::factory(1)->create(); // PersonLds::factory(1)->create(); // PersonName::factory(1)->create(); // PersonNameFone::factory(1)->create(); // PersonNameRomn::factory(1)->create(); // PersonSubm::factory(1)->create(); // Place::factory(1)->create(); // Provider::factory(1)->create(); // Publication::factory(1)->create(); // Refn::factory(1)->create(); // Repository::factory(1)->create(); // SourceDataEven::factory(1)->create(); // SourceData::factory(1)->create(); // Source::factory(1)->create(); // SourceRefEven::factory(1)->create(); // SourceRef::factory(1)->create(); // SourceRepo::factory(1)->create(); // Subm::factory(1)->create(); // Subn::factory(1)->create(); // Tree::factory(1)->create(); $this->call(PermissionsSeeder::class); } }


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_default_permissions_seeder.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.