Make sure all objects also add user group

This commit is contained in:
James Cole
2023-08-11 19:37:28 +02:00
parent e1ba2d9ad9
commit a9bd0f551d
20 changed files with 60 additions and 38 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
@@ -93,6 +94,7 @@ class UpdateGroupInformation extends Command
Bill::class, Bill::class,
Budget::class, Budget::class,
Category::class, Category::class,
ObjectGroup::class,
CurrencyExchangeRate::class, CurrencyExchangeRate::class,
Recurrence::class, Recurrence::class,
RuleGroup::class, RuleGroup::class,

View File

@@ -92,6 +92,7 @@ class AccountFactory
$return = $this->create( $return = $this->create(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'name' => $accountName, 'name' => $accountName,
'account_type_id' => $type->id, 'account_type_id' => $type->id,
'account_type_name' => null, 'account_type_name' => null,
@@ -199,6 +200,7 @@ class AccountFactory
$active = array_key_exists('active', $data) ? $data['active'] : true; $active = array_key_exists('active', $data) ? $data['active'] : true;
$databaseData = [ $databaseData = [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'account_type_id' => $type->id, 'account_type_id' => $type->id,
'name' => $data['name'], 'name' => $data['name'],
'order' => 25000, 'order' => 25000,

View File

@@ -67,6 +67,7 @@ class BillFactory
'match' => 'MIGRATED_TO_RULES', 'match' => 'MIGRATED_TO_RULES',
'amount_min' => $data['amount_min'], 'amount_min' => $data['amount_min'],
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'transaction_currency_id' => $currency->id, 'transaction_currency_id' => $currency->id,
'amount_max' => $data['amount_max'], 'amount_max' => $data['amount_max'],
'date' => $data['date'], 'date' => $data['date'],

View File

@@ -70,8 +70,9 @@ class CategoryFactory
try { try {
return Category::create( return Category::create(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'name' => $categoryName, 'user_group_id' => $this->user->user_group_id,
'name' => $categoryName,
] ]
); );
} catch (QueryException $e) { } catch (QueryException $e) {

View File

@@ -107,6 +107,7 @@ class RecurrenceFactory
$recurrence = new Recurrence( $recurrence = new Recurrence(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'transaction_type_id' => $type->id, 'transaction_type_id' => $type->id,
'title' => $title, 'title' => $title,
'description' => $description, 'description' => $description,

View File

@@ -83,14 +83,15 @@ class TagFactory
$latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude']; // intentional float $latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude']; // intentional float
$longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude']; // intentional float $longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude']; // intentional float
$array = [ $array = [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'tag' => trim($data['tag']), 'user_group_id' => $this->user->user_group_id,
'tagMode' => 'nothing', 'tag' => trim($data['tag']),
'date' => $data['date'], 'tagMode' => 'nothing',
'description' => $data['description'], 'date' => $data['date'],
'latitude' => null, 'description' => $data['description'],
'longitude' => null, 'latitude' => null,
'zoomLevel' => null, 'longitude' => null,
'zoomLevel' => null,
]; ];
$tag = Tag::create($array); $tag = Tag::create($array);
if (null !== $tag && null !== $latitude && null !== $longitude) { if (null !== $tag && null !== $latitude && null !== $longitude) {

View File

@@ -131,6 +131,7 @@ class BudgetLimitHandler
$availableBudget = new AvailableBudget( $availableBudget = new AvailableBudget(
[ [
'user_id' => $budgetLimit->budget->user->id, 'user_id' => $budgetLimit->budget->user->id,
'user_group_id' => $budgetLimit->budget->user->user_group_id,
'transaction_currency_id' => $budgetLimit->transaction_currency_id, 'transaction_currency_id' => $budgetLimit->transaction_currency_id,
'start_date' => $current, 'start_date' => $current,
'end_date' => $currentEnd, 'end_date' => $currentEnd,
@@ -180,8 +181,8 @@ class BudgetLimitHandler
); );
// overlap in days: // overlap in days:
$limitPeriod = Period::make( $limitPeriod = Period::make(
$budgetLimit->start_date, $budgetLimit->start_date,
$budgetLimit->end_date, $budgetLimit->end_date,
precision : Precision::DAY(), precision : Precision::DAY(),
boundaries: Boundaries::EXCLUDE_NONE() boundaries: Boundaries::EXCLUDE_NONE()
); );
@@ -223,8 +224,8 @@ class BudgetLimitHandler
return '0'; return '0';
} }
$limitPeriod = Period::make( $limitPeriod = Period::make(
$budgetLimit->start_date, $budgetLimit->start_date,
$budgetLimit->end_date, $budgetLimit->end_date,
precision : Precision::DAY(), precision : Precision::DAY(),
boundaries: Boundaries::EXCLUDE_NONE() boundaries: Boundaries::EXCLUDE_NONE()
); );

View File

@@ -125,9 +125,9 @@ class Account extends Model
'encrypted' => 'boolean', 'encrypted' => 'boolean',
]; ];
/** @var array Fields that can be filled */ /** @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 */ /** @var array Hidden from view */
protected $hidden = ['encrypted']; protected $hidden = ['encrypted'];
private bool $joinedAccountTypes = false; private bool $joinedAccountTypes = false;
/** /**
@@ -291,7 +291,7 @@ class Account extends Model
protected function virtualBalance(): Attribute protected function virtualBalance(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn ($value) => (string)$value, get: fn($value) => (string)$value,
); );
} }
} }

View File

@@ -85,7 +85,7 @@ class AvailableBudget extends Model
'transaction_currency_id' => 'int', 'transaction_currency_id' => 'int',
]; ];
/** @var array Fields that can be filled */ /** @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). * 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 protected function amount(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn ($value) => (string)$value, get: fn($value) => (string)$value,
); );
} }
} }

View File

@@ -130,6 +130,7 @@ class Bill extends Model
'match', 'match',
'amount_min', 'amount_min',
'user_id', 'user_id',
'user_group_id',
'amount_max', 'amount_max',
'date', 'date',
'repeat_freq', 'repeat_freq',
@@ -241,7 +242,7 @@ class Bill extends Model
protected function amountMax(): Attribute protected function amountMax(): Attribute
{ {
return Attribute::make( 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 protected function amountMin(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn ($value) => (string)$value, get: fn($value) => (string)$value,
); );
} }
} }

View File

@@ -89,7 +89,7 @@ class Category extends Model
'encrypted' => 'boolean', 'encrypted' => 'boolean',
]; ];
/** @var array Fields that can be filled */ /** @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 */ /** @var array Hidden from view */
protected $hidden = ['encrypted']; protected $hidden = ['encrypted'];

View File

@@ -77,7 +77,7 @@ class ObjectGroup extends Model
'user_id' => 'integer', 'user_id' => 'integer',
'deleted_at' => 'datetime', '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). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@@ -165,4 +165,12 @@ class Rule extends Model
{ {
$this->attributes['description'] = e($value); $this->attributes['description'] = e($value);
} }
/**
* @return BelongsTo
*/
public function userGroup(): BelongsTo
{
return $this->belongsTo(UserGroup::class);
}
} }

View File

@@ -99,7 +99,7 @@ class Tag extends Model
'longitude' => 'float', 'longitude' => 'float',
]; ];
/** @var array Fields that can be filled */ /** @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']; protected $hidden = ['zoomLevel', 'latitude', 'longitude'];

View File

@@ -88,7 +88,7 @@ class Webhook extends Model
'response' => 'integer', 'response' => 'integer',
'delivery' => '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 * @return array

View File

@@ -249,6 +249,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return AvailableBudget::create( return AvailableBudget::create(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'transaction_currency_id' => $data['currency_id'], 'transaction_currency_id' => $data['currency_id'],
'amount' => $data['amount'], 'amount' => $data['amount'],
'start_date' => $start, 'start_date' => $start,

View File

@@ -53,9 +53,10 @@ trait CreatesObjectGroups
if (!$this->hasObjectGroup($title)) { if (!$this->hasObjectGroup($title)) {
return ObjectGroup::create( return ObjectGroup::create(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'title' => $title, 'user_group_id' => $this->user->user_group_id,
'order' => $maxOrder + 1, 'title' => $title,
'order' => $maxOrder + 1,
] ]
); );
} }

View File

@@ -280,7 +280,8 @@ class RuleRepository implements RuleRepositoryInterface
// start by creating a new rule: // start by creating a new rule:
$rule = 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->rule_group_id = $ruleGroup->id;
$rule->order = 31337; $rule->order = 31337;

View File

@@ -121,14 +121,15 @@ class WebhookRepository implements WebhookRepositoryInterface
{ {
$secret = Str::random(24); $secret = Str::random(24);
$fullData = [ $fullData = [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'active' => $data['active'] ?? false, 'user_group_id' => $this->user->user_group_id,
'title' => $data['title'] ?? null, 'active' => $data['active'] ?? false,
'trigger' => $data['trigger'], 'title' => $data['title'] ?? null,
'response' => $data['response'], 'trigger' => $data['trigger'],
'delivery' => $data['delivery'], 'response' => $data['response'],
'secret' => $secret, 'delivery' => $data['delivery'],
'url' => $data['url'], 'secret' => $secret,
'url' => $data['url'],
]; ];
return Webhook::create($fullData); return Webhook::create($fullData);

View File

@@ -112,7 +112,7 @@ return [
], ],
'version' => '6.0.20', 'version' => '6.0.20',
'api_version' => '2.0.5', 'api_version' => '2.0.5',
'db_version' => 19, 'db_version' => 20,
// generic settings // generic settings
'maxUploadSize' => 1073741824, // 1 GB 'maxUploadSize' => 1073741824, // 1 GB