Update policies to migrate from user_id to space_id for earnings, spendings, tags and recurrings
MODIFY
app/Policies/EarningPolicy.php
app/Policies/EarningPolicy.php
@@ -7,10 +7,10 @@ use App\Earning;
class EarningPolicy {
public function view(User $user, Earning $earning) {
- return $user->id === $earning->user_id;
+ return $user->spaces->contains($earning->space_id);
}
public function delete(User $user, Earning $earning) {
- return $user->id === $earning->user_id;
+ return $user->spaces->contains($earning->space_id);
}
}

MODIFY
app/Policies/RecurringPolicy.php
app/Policies/RecurringPolicy.php
@@ -7,6 +7,6 @@ use App\Recurring;
class RecurringPolicy {
public function view(User $user, Recurring $recurring) {
- return $user->id === $recurring->user_id;
+ return $user->spaces->contains($recurring->space_id);
}
}

MODIFY
app/Policies/SpendingPolicy.php
app/Policies/SpendingPolicy.php
@@ -7,10 +7,10 @@ use App\Spending;
class SpendingPolicy {
public function view(User $user, Spending $spending) {
- return $user->id === $spending->user_id;
+ return $user->spaces->contains($spending->space_id);
}
public function delete(User $user, Spending $spending) {
- return $user->id === $spending->user_id;
+ return $user->spaces->contains($spending->space_id);
}
}

MODIFY
app/Policies/TagPolicy.php
app/Policies/TagPolicy.php
@@ -7,10 +7,10 @@ use App\Tag;
class TagPolicy {
public function update(User $user, Tag $tag) {
- return $user->id === $tag->user_id;
+ return $user->spaces->contains($tag->space_id);
}
public function delete(User $user, Tag $tag) {
- return $user->id === $tag->user_id;
+ return $user->spaces->contains($tag->space_id);
}
}

Update policies to migrate from user_id to space_id for earnings, spendings, tags and recurrings