Skip to content

Firefly III: a personal finances manager

Make sure all objects also add user group

James Colea9bd0f551d99
diff --git a/app/Console/Commands/Integrity/UpdateGroupInformation.php b/app/Console/Commands/Integrity/UpdateGroupInformation.php
index af6c979311..7b0d80f31d 100644
--- a/app/Console/Commands/Integrity/UpdateGroupInformation.php
+++ b/app/Console/Commands/Integrity/UpdateGroupInformation.php
@@ -32,6 +32,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\CurrencyExchangeRate;
+use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
@@ -93,6 +94,7 @@ class UpdateGroupInformation extends Command
Bill::class,
Budget::class,
Category::class,
+ ObjectGroup::class,
CurrencyExchangeRate::class,
Recurrence::class,
RuleGroup::class,
diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php
index ca8b583b20..82519e0eff 100644
--- a/app/Factory/AccountFactory.php
+++ b/app/Factory/AccountFactory.php
@@ -92,6 +92,7 @@ class AccountFactory
$return = $this->create(
[
'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
'name' => $accountName,
'account_type_id' => $type->id,
'account_type_name' => null,
@@ -199,6 +200,7 @@ class AccountFactory
$active = array_key_exists('active', $data) ? $data['active'] : true;
$databaseData = [
'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
'account_type_id' => $type->id,
'name' => $data['name'],
'order' => 25000,
diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php
index cff8187735..c2bf305d3a 100644
--- a/app/Factory/BillFactory.php
+++ b/app/Factory/BillFactory.php
@@ -67,6 +67,7 @@ class BillFactory
'match' => 'MIGRATED_TO_RULES',
'amount_min' => $data['amount_min'],
'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
'transaction_currency_id' => $currency->id,
'amount_max' => $data['amount_max'],
'date' => $data['date'],
diff --git a/app/Factory/CategoryFactory.php b/app/Factory/CategoryFactory.php
index 2695b0edf1..affe1abf52 100644
--- a/app/Factory/CategoryFactory.php
+++ b/app/Factory/CategoryFactory.php
@@ -70,8 +70,9 @@ class CategoryFactory
try {
return Category::create(
[
- 'user_id' => $this->user->id,
- 'name' => $categoryName,
+ 'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
+ 'name' => $categoryName,
]
);
} catch (QueryException $e) {
diff --git a/app/Factory/RecurrenceFactory.php b/app/Factory/RecurrenceFactory.php
index 2b6b86653f..6c5be3c1d3 100644
--- a/app/Factory/RecurrenceFactory.php
+++ b/app/Factory/RecurrenceFactory.php
@@ -107,6 +107,7 @@ class RecurrenceFactory
$recurrence = new Recurrence(
[
'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
'transaction_type_id' => $type->id,
'title' => $title,
'description' => $description,
diff --git a/app/Factory/TagFactory.php b/app/Factory/TagFactory.php
index 0c12f37348..dcfd9b8741 100644
--- a/app/Factory/TagFactory.php
+++ b/app/Factory/TagFactory.php
@@ -83,14 +83,15 @@ class TagFactory
$latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude']; // intentional float
$longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude']; // intentional float
$array = [
- 'user_id' => $this->user->id,
- 'tag' => trim($data['tag']),
- 'tagMode' => 'nothing',
- 'date' => $data['date'],
- 'description' => $data['description'],
- 'latitude' => null,
- 'longitude' => null,
- 'zoomLevel' => null,
+ 'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
+ 'tag' => trim($data['tag']),
+ 'tagMode' => 'nothing',
+ 'date' => $data['date'],
+ 'description' => $data['description'],
+ 'latitude' => null,
+ 'longitude' => null,
+ 'zoomLevel' => null,
];
$tag = Tag::create($array);
if (null !== $tag && null !== $latitude && null !== $longitude) {
diff --git a/app/Handlers/Events/Model/BudgetLimitHandler.php b/app/Handlers/Events/Model/BudgetLimitHandler.php
index 49e0b2ecec..5a45dc41e0 100644
--- a/app/Handlers/Events/Model/BudgetLimitHandler.php
+++ b/app/Handlers/Events/Model/BudgetLimitHandler.php
@@ -131,6 +131,7 @@ class BudgetLimitHandler
$availableBudget = new AvailableBudget(
[
'user_id' => $budgetLimit->budget->user->id,
+ 'user_group_id' => $budgetLimit->budget->user->user_group_id,
'transaction_currency_id' => $budgetLimit->transaction_currency_id,
'start_date' => $current,
'end_date' => $currentEnd,
@@ -180,8 +181,8 @@ class BudgetLimitHandler
);
// overlap in days:
$limitPeriod = Period::make(
- $budgetLimit->start_date,
- $budgetLimit->end_date,
+ $budgetLimit->start_date,
+ $budgetLimit->end_date,
precision : Precision::DAY(),
boundaries: Boundaries::EXCLUDE_NONE()
);
@@ -223,8 +224,8 @@ class BudgetLimitHandler
return '0';
}
$limitPeriod = Period::make(
- $budgetLimit->start_date,
- $budgetLimit->end_date,
+ $budgetLimit->start_date,
+ $budgetLimit->end_date,
precision : Precision::DAY(),
boundaries: Boundaries::EXCLUDE_NONE()
);
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 5ef09f8ef0..799e05ef4a 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -125,9 +125,9 @@ class Account extends Model
'encrypted' => 'boolean',
];
/** @var array Fields that can be filled */
- protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
+ protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
/** @var array Hidden from view */
- protected $hidden = ['encrypted'];
+ protected $hidden = ['encrypted'];
private bool $joinedAccountTypes = false;
/**
@@ -291,7 +291,7 @@ class Account extends Model
protected function virtualBalance(): Attribute
{
return Attribute::make(
- get: fn ($value) => (string)$value,
+ get: fn($value) => (string)$value,
);
}
}
diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php
index c3e114b436..f80a962f9a 100644
--- a/app/Models/AvailableBudget.php
+++ b/app/Models/AvailableBudget.php
@@ -85,7 +85,7 @@ class AvailableBudget extends Model
'transaction_currency_id' => 'int',
];
/** @var array Fields that can be filled */
- protected $fillable = ['user_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date'];
+ protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date'];
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
@@ -132,7 +132,7 @@ class AvailableBudget extends Model
protected function amount(): Attribute
{
return Attribute::make(
- get: fn ($value) => (string)$value,
+ get: fn($value) => (string)$value,
);
}
}
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index d7ef58b2bf..160d83ae3e 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -130,6 +130,7 @@ class Bill extends Model
'match',
'amount_min',
'user_id',
+ 'user_group_id',
'amount_max',
'date',
'repeat_freq',
@@ -241,7 +242,7 @@ class Bill extends Model
protected function amountMax(): Attribute
{
return Attribute::make(
- get: fn ($value) => (string)$value,
+ get: fn($value) => (string)$value,
);
}
@@ -253,7 +254,7 @@ class Bill extends Model
protected function amountMin(): Attribute
{
return Attribute::make(
- get: fn ($value) => (string)$value,
+ get: fn($value) => (string)$value,
);
}
}
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 84ac0c3038..dc52f22bbb 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -89,7 +89,7 @@ class Category extends Model
'encrypted' => 'boolean',
];
/** @var array Fields that can be filled */
- protected $fillable = ['user_id', 'name'];
+ protected $fillable = ['user_id', 'user_group_id', 'name'];
/** @var array Hidden from view */
protected $hidden = ['encrypted'];
diff --git a/app/Models/ObjectGroup.php b/app/Models/ObjectGroup.php
index ec1aa89410..a4c86b72d0 100644
--- a/app/Models/ObjectGroup.php
+++ b/app/Models/ObjectGroup.php
@@ -77,7 +77,7 @@ class ObjectGroup extends Model
'user_id' => 'integer',
'deleted_at' => 'datetime',
];
- protected $fillable = ['title', 'order', 'user_id'];
+ protected $fillable = ['title', 'order', 'user_id', 'user_group_id'];
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
diff --git a/app/Models/Rule.php b/app/Models/Rule.php
index 7660de859a..5e8807863a 100644
--- a/app/Models/Rule.php
+++ b/app/Models/Rule.php
@@ -165,4 +165,12 @@ class Rule extends Model
{
$this->attributes['description'] = e($value);
}
+
+ /**
+ * @return BelongsTo
+ */
+ public function userGroup(): BelongsTo
+ {
+ return $this->belongsTo(UserGroup::class);
+ }
}
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index 6d1ffd2cfa..1e0e28fd14 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -99,7 +99,7 @@ class Tag extends Model
'longitude' => 'float',
];
/** @var array Fields that can be filled */
- protected $fillable = ['user_id', 'tag', 'date', 'description', 'tagMode'];
+ protected $fillable = ['user_id', 'user_group_id', 'tag', 'date', 'description', 'tagMode'];
protected $hidden = ['zoomLevel', 'latitude', 'longitude'];
diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php
index c928d35758..4d8a64bf7f 100644
--- a/app/Models/Webhook.php
+++ b/app/Models/Webhook.php
@@ -88,7 +88,7 @@ class Webhook extends Model
'response' => 'integer',
'delivery' => 'integer',
];
- protected $fillable = ['active', 'trigger', 'response', 'delivery', 'user_id', 'url', 'title', 'secret'];
+ protected $fillable = ['active', 'trigger', 'response', 'delivery', 'user_id', 'user_group_id', 'url', 'title', 'secret'];
/**
* @return array
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index 9553a6f243..a17b17d4e2 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -249,6 +249,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return AvailableBudget::create(
[
'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
'transaction_currency_id' => $data['currency_id'],
'amount' => $data['amount'],
'start_date' => $start,
diff --git a/app/Repositories/ObjectGroup/CreatesObjectGroups.php b/app/Repositories/ObjectGroup/CreatesObjectGroups.php
index 7cf5550675..5258479fbf 100644
--- a/app/Repositories/ObjectGroup/CreatesObjectGroups.php
+++ b/app/Repositories/ObjectGroup/CreatesObjectGroups.php
@@ -53,9 +53,10 @@ trait CreatesObjectGroups
if (!$this->hasObjectGroup($title)) {
return ObjectGroup::create(
[
- 'user_id' => $this->user->id,
- 'title' => $title,
- 'order' => $maxOrder + 1,
+ 'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
+ 'title' => $title,
+ 'order' => $maxOrder + 1,
]
);
}
diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.php
index 46e8a84afb..09e02cbe75 100644
--- a/app/Repositories/Rule/RuleRepository.php
+++ b/app/Repositories/Rule/RuleRepository.php
@@ -280,7 +280,8 @@ class RuleRepository implements RuleRepositoryInterface
// start by creating a new rule:
$rule = new Rule();
- $rule->user()->associate($this->user->id);
+ $rule->user()->associate($this->user);
+ $rule->userGroup()->associate($this->user->userGroup);
$rule->rule_group_id = $ruleGroup->id;
$rule->order = 31337;
diff --git a/app/Repositories/Webhook/WebhookRepository.php b/app/Repositories/Webhook/WebhookRepository.php
index 931638aecd..451e376bae 100644
--- a/app/Repositories/Webhook/WebhookRepository.php
+++ b/app/Repositories/Webhook/WebhookRepository.php
@@ -121,14 +121,15 @@ class WebhookRepository implements WebhookRepositoryInterface
{
$secret = Str::random(24);
$fullData = [
- 'user_id' => $this->user->id,
- 'active' => $data['active'] ?? false,
- 'title' => $data['title'] ?? null,
- 'trigger' => $data['trigger'],
- 'response' => $data['response'],
- 'delivery' => $data['delivery'],
- 'secret' => $secret,
- 'url' => $data['url'],
+ 'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
+ 'active' => $data['active'] ?? false,
+ 'title' => $data['title'] ?? null,
+ 'trigger' => $data['trigger'],
+ 'response' => $data['response'],
+ 'delivery' => $data['delivery'],
+ 'secret' => $secret,
+ 'url' => $data['url'],
];
return Webhook::create($fullData);
diff --git a/config/firefly.php b/config/firefly.php
index 3ded7995ae..8f537d9c42 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -112,7 +112,7 @@ return [
],
'version' => '6.0.20',
'api_version' => '2.0.5',
- 'db_version' => 19,
+ 'db_version' => 20,
// generic settings
'maxUploadSize' => 1073741824, // 1 GB