Skip to content

Commit 84af134

Browse files
committed
wip
1 parent 8322644 commit 84af134

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/Http/Controllers/ProfileUpdateController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public function guessRepository(RestifyRequest $request): ?Repository
4141
return null;
4242
}
4343

44+
if (method_exists($repository, 'canUseForProfileUpdate')) {
45+
if (!call_user_func([$repository, 'canUseForProfileUpdate'], $request)) {
46+
return null;
47+
}
48+
}
49+
4450
$repository->withResource(
4551
$repository::query($request)->whereKey(Auth::id())->first()
4652
);

src/Repositories/UserProfile.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ trait UserProfile
88
{
99
public static $canUseForProfile = false;
1010

11+
public static $canUseForProfileUpdate = false;
12+
1113
public static $metaProfile = [];
1214

1315
public static function canUseForProfile(Request $request)
@@ -17,6 +19,13 @@ public static function canUseForProfile(Request $request)
1719
: static::$canUseForProfile;
1820
}
1921

22+
public static function canUseForProfileUpdate(Request $request)
23+
{
24+
return is_callable(static::$canUseForProfileUpdate)
25+
? forward_static_call(static::$canUseForProfileUpdate, $request)
26+
: static::$canUseForProfileUpdate;
27+
}
28+
2029
public static function metaProfile(Request $request): array
2130
{
2231
return static::$metaProfile;
@@ -25,10 +34,10 @@ public static function metaProfile(Request $request): array
2534
public function resolveShowMeta($request)
2635
{
2736
return [
28-
'authorizedToShow' => $this->authorizedToShow($request),
29-
'authorizedToStore' => $this->authorizedToStore($request),
30-
'authorizedToUpdate' => $this->authorizedToUpdate($request),
31-
'authorizedToDelete' => $this->authorizedToDelete($request),
32-
] + static::metaProfile($request);
37+
'authorizedToShow' => $this->authorizedToShow($request),
38+
'authorizedToStore' => $this->authorizedToStore($request),
39+
'authorizedToUpdate' => $this->authorizedToUpdate($request),
40+
'authorizedToDelete' => $this->authorizedToDelete($request),
41+
] + static::metaProfile($request);
3342
}
3443
}

tests/Controllers/ProfileControllerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function test_profile_upload_avatar()
116116

117117
public function test_profile_validation_from_repository()
118118
{
119+
UserRepository::$canUseForProfileUpdate = true;
120+
119121
$this->putJson('/restify-api/profile', [
120122
'email' => '[email protected]',
121123
'name' => 'Ed',
@@ -185,4 +187,22 @@ public function test_profile_returns_authenticated_user_with_meta_profile_data_v
185187
],
186188
]);
187189
}
190+
191+
public function test_profile_update_via_repository()
192+
{
193+
UserRepository::$canUseForProfileUpdate = true;
194+
195+
$response = $this->putJson('restify-api/profile', [
196+
'email' => '[email protected]',
197+
'name' => 'Eduard',
198+
])
199+
->assertStatus(200);
200+
201+
$response->assertJsonFragment([
202+
'email' => '[email protected]',
203+
'name' => 'Eduard',
204+
]);
205+
}
206+
207+
188208
}

0 commit comments

Comments
 (0)