diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index b4133abd..c5164381 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -16,8 +16,8 @@ class UserResource extends JsonResource public function toArray($request) { return [ - 'name' => $this->name, - 'email' => $this->email, + 'name' => $this->getFirstname(), + 'email' => null, 'avatar' => [ 'src' => Storage::url('avatar.png') ] diff --git a/app/Initialize/InitializeJob.php b/app/Initialize/InitializeJob.php index 12a07196..9500bc19 100644 --- a/app/Initialize/InitializeJob.php +++ b/app/Initialize/InitializeJob.php @@ -2,7 +2,6 @@ namespace App\Initialize; -use App\User; use App\Member; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; @@ -10,6 +9,7 @@ use Aweos\Agnoster\Progress\HasProgress; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; +use Zoomyboy\LaravelNami\NamiUser; class InitializeJob implements ShouldQueue { @@ -28,7 +28,7 @@ class InitializeJob implements ShouldQueue InitializeMembers::class, ]; - public function __construct(User $user) + public function __construct(NamiUser $user) { $this->user = $user; } @@ -40,7 +40,7 @@ class InitializeJob implements ShouldQueue */ public function handle() { - $api = $this->user->getNamiApi(); + $api = $this->user->api(); $bar = $this->createProgressBar('Initialisiere'); foreach (static::$initializers as $initializer) { diff --git a/app/Initialize/InitializeMembers.php b/app/Initialize/InitializeMembers.php index ebdd82d2..00f6d65c 100644 --- a/app/Initialize/InitializeMembers.php +++ b/app/Initialize/InitializeMembers.php @@ -53,6 +53,7 @@ class InitializeMembers { 'country_id' => Country::where('nami_id', $member->country_id)->firstOrFail()->id, 'fee_id' => optional(Fee::firstWhere('nami_id', $member->fee_id ?: -1))->id, 'nationality_id' => Nationality::where('nami_id', $member->nationality_id)->firstOrFail()->id, + 'version' => $member->version, ]); }); }); diff --git a/app/Initialize/InitializeNationalities.php b/app/Initialize/InitializeNationalities.php index 481999e4..c1115096 100644 --- a/app/Initialize/InitializeNationalities.php +++ b/app/Initialize/InitializeNationalities.php @@ -14,7 +14,6 @@ class InitializeNationalities { public function handle() { $this->bar->task('Synchronisiere Nationalitäten', function() { - $this->api->group(auth()->user()->getNamiGroupId())->fees(); $this->api->nationalities()->each(function($nationality) { \App\Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]); }); diff --git a/app/Member/Member.php b/app/Member/Member.php index 1c2d7ea4..04d2ccf0 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -16,7 +16,7 @@ class Member extends Model use Notifiable; use HasFactory; - public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id']; + public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version']; public $dates = ['joined_at', 'birthday']; @@ -44,6 +44,10 @@ class Member extends Model return $this->firstname.' '.$this->lastname; } + public function getHasNamiAttribute() { + return $this->nami_id !== null; + } + //---------------------------------- Relations ---------------------------------- public function country() { @@ -106,7 +110,7 @@ class Member extends Model }); static::updated(function($model) { - UpdateJob::dispatch($model); + UpdateJob::dispatch($model, auth()->user()); }); } } diff --git a/app/Member/UpdateJob.php b/app/Member/UpdateJob.php index 2a6d6f61..26b75ce8 100644 --- a/app/Member/UpdateJob.php +++ b/app/Member/UpdateJob.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Zoomyboy\LaravelNami\Nami; +use App\Confession; class UpdateJob implements ShouldQueue { @@ -15,10 +16,12 @@ class UpdateJob implements ShouldQueue public $memberId; public $member; + public $user; - public function __construct(Member $member) + public function __construct(Member $member, $user) { $this->memberId = $member->id; + $this->user = $user; } /** @@ -30,7 +33,11 @@ class UpdateJob implements ShouldQueue { $this->member = Member::find($this->memberId); - Nami::putMember([ + if (!$this->member->hasNami) { + return false; + } + + $response = Nami::login($this->user->mglnr)->putMember([ 'firstname' => $this->member->firstname, 'lastname' => $this->member->lastname, 'nickname' => $this->member->nickname, @@ -49,14 +56,18 @@ class UpdateJob implements ShouldQueue 'fax' => $this->member->fax, 'email' => $this->member->email, 'email_parents' => $this->member->email_parents, - 'gender_id' => optional($this->member)->nami_id, - 'confession_id' => optional($this->member->confession)->nami_id, + 'gender_id' => optional($this->member->gender)->nami_id, + 'confession_id' => $this->member->confession ? $this->member->confession->nami_id : Confession::firstWhere('is_null', true)->id, 'region_id' => optional($this->member->region)->nami_id, 'country_id' => $this->member->country->nami_id, 'fee_id' => optional($this->member->fee)->nami_id, 'nationality_id' => $this->member->nationality->nami_id, 'id' => $this->member->nami_id, 'group_id' => $this->member->group->nami_id, + 'version' => $this->member->version, ]); + Member::withoutEvents(function() use ($response) { + $this->member->update(['version' => $response['version']]); + }); } } diff --git a/composer.json b/composer.json index 31311800..29439170 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,13 @@ "laravel" ], "repositories": [ - { "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} } + { "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} }, + { "type": "path", "url": "./packages/agnoster-installer", "options": {"symlink": true} } ], "license": "MIT", "require": { "php": "^7.2.5", + "aweos/agnoster-installer": "1.0", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^7.0.1", diff --git a/composer.lock b/composer.lock index 2750e292..78651a19 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "939238f463369e99565304bd5d3e68de", + "content-hash": "d960b31f70a251387c83d7ab9803fb0e", "packages": [ { "name": "asm89/stack-cors", @@ -62,6 +62,35 @@ }, "time": "2019-12-24T22:41:47+00:00" }, + { + "name": "aweos/agnoster-installer", + "version": "1.0.0", + "dist": { + "type": "path", + "url": "./packages/agnoster-installer", + "reference": "e33794cdf0a68d161ce22856650c288700cdbd7c" + }, + "bin": [ + "bin/agnoster" + ], + "type": "library", + "autoload": { + "psr-4": { + "Aweos\\Agnoster\\": "src/" + } + }, + "authors": [ + { + "name": "philipp lang", + "email": "philipp@aweos.de" + } + ], + "description": "Agnoster Backend package for UI scaffolding", + "transport-options": { + "symlink": true, + "relative": true + } + }, { "name": "brick/math", "version": "0.9.2", @@ -1432,16 +1461,16 @@ }, { "name": "league/commonmark", - "version": "1.6.2", + "version": "1.6.4", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "7d70d2f19c84bcc16275ea47edabee24747352eb" + "reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/7d70d2f19c84bcc16275ea47edabee24747352eb", - "reference": "7d70d2f19c84bcc16275ea47edabee24747352eb", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c3c8b7217c52572fb42aaf84211abccf75a151b2", + "reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2", "shasum": "" }, "require": { @@ -1459,7 +1488,7 @@ "github/gfm": "0.29.0", "michelf/php-markdown": "~1.4", "mikehaertl/php-shellcommand": "^1.4", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "^0.12.90", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", "scrutinizer/ocular": "^1.5", "symfony/finder": "^4.2" @@ -1529,7 +1558,7 @@ "type": "tidelift" } ], - "time": "2021-05-12T11:39:41+00:00" + "time": "2021-06-19T20:08:14+00:00" }, { "name": "league/flysystem", @@ -5769,7 +5798,7 @@ "dist": { "type": "path", "url": "./packages/laravel-nami", - "reference": "4a89f167f825dc7e58aaf7b426657531163d82cf" + "reference": "009a9b1678b4736d3b45144cf410a5a5c9a27bed" }, "require": { "guzzlehttp/guzzle": "^6.3.1|^7.0" @@ -8226,6 +8255,7 @@ "type": "github" } ], + "abandoned": true, "time": "2020-09-28T06:45:17+00:00" }, { diff --git a/config/session.php b/config/session.php index da692f3b..1afe371b 100644 --- a/config/session.php +++ b/config/session.php @@ -31,7 +31,7 @@ return [ | */ - 'lifetime' => env('SESSION_LIFETIME', 120), + 'lifetime' => env('SESSION_LIFETIME', 120000), 'expire_on_close' => false, diff --git a/database/migrations/2020_04_12_223230_create_members_table.php b/database/migrations/2020_04_12_223230_create_members_table.php index ab013d46..dfdc1eed 100644 --- a/database/migrations/2020_04_12_223230_create_members_table.php +++ b/database/migrations/2020_04_12_223230_create_members_table.php @@ -51,6 +51,7 @@ class CreateMembersTable extends Migration $table->foreignId('fee_id')->constrained(); $table->text('letter_address')->nullable(); $table->foreignId('bill_kind_id')->nullable()->constrained(); + $table->unsignedInteger('version')->default(1); $table->timestamps(); }); diff --git a/resources/js/views/member/Edit.vue b/resources/js/views/member/Edit.vue index c7d3ece3..217cbfc1 100644 --- a/resources/js/views/member/Edit.vue +++ b/resources/js/views/member/Edit.vue @@ -71,22 +71,13 @@ -
-
- -
-
- -
-
- -
-
- -
-
- -
+
+ + + + + +
diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index 794ee6e7..8a3966b4 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -28,9 +28,9 @@ class LoginTest extends TestCase $key = session()->get('auth_key'); $cache = Cache::get("namiauth-{$key}"); $this->assertEquals('secret', data_get($cache, 'credentials.password')); - $this->assertEquals(123, auth()->user()->mglnr); - $this->assertEquals('Max', auth()->user()->firstname); - $this->assertEquals('Muster', auth()->user()->lastname); + $this->assertEquals(123, auth()->user()->getMglnr()); + $this->assertEquals('Max', auth()->user()->getFirstname()); + $this->assertEquals('Muster', auth()->user()->getLastname()); $this->assertTrue(auth()->check()); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 0772de0a..6737608f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,11 +24,9 @@ abstract class TestCase extends BaseTestCase ]); $this->fakeNamiPassword(999, 'secret', [12399]); - $api = Nami::login(999, 'secret'); - $this->be(new NamiUser([ - 'cookie' => $api->cookie->toArray(), + $this->be(NamiUser::fromPayload([ 'credentials' => [ 'mglnr' => 999, 'password' => 'secret'