mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 14:24:33 -04:00
Fixes for group settings parser
This commit is contained in:
parent
3fcce909f5
commit
ddc949c260
@ -24,16 +24,19 @@ class UpdateGroupSettingRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->group_setting);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('edit', $this->group_setting);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||
|
||||
// $rules['name'] = 'unique:group_settings,name,'.$this->id.',id,company_id,'.$this->group_setting->company_id;
|
||||
return [
|
||||
'settings' => [new ValidClientGroupSettingsRule()],
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
|
@ -18,6 +18,15 @@ class GroupSettingRepository extends BaseRepository
|
||||
{
|
||||
public function save($data, GroupSetting $group_setting) :?GroupSetting
|
||||
{
|
||||
|
||||
if(isset($data['settings']['translations'])) {
|
||||
unset($data['settings']['translations']);
|
||||
}
|
||||
|
||||
if(isset($data['settings']['pdf_variables'])) {
|
||||
unset($data['settings']['pdf_variables']);
|
||||
}
|
||||
|
||||
$group_setting->fill($data);
|
||||
$group_setting->save();
|
||||
|
||||
@ -25,16 +34,16 @@ class GroupSettingRepository extends BaseRepository
|
||||
$settings = $group_setting->settings;
|
||||
unset($settings->company_logo);
|
||||
$group_setting->settings = $settings;
|
||||
$group_setting->save();
|
||||
}
|
||||
|
||||
if (! array_key_exists('settings', $data) || count((array) $data['settings']) == 0) {
|
||||
$settings = new \stdClass;
|
||||
$settings->entity = Client::class;
|
||||
$group_setting->settings = $settings;
|
||||
$group_setting->save();
|
||||
}
|
||||
|
||||
$group_setting->save();
|
||||
|
||||
return $group_setting;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,14 @@ trait ClientGroupSettingsSaver
|
||||
unset($settings[$field]);
|
||||
}
|
||||
|
||||
|
||||
foreach(['translations','pdf_variables'] as $field) {
|
||||
if (isset($settings[$field])) {
|
||||
unset($settings[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* for clients and group settings, if a field is not set or is set to a blank value,
|
||||
* we unset it from the settings object
|
||||
@ -86,6 +94,12 @@ trait ClientGroupSettingsSaver
|
||||
unset($settings->translations);
|
||||
}
|
||||
|
||||
foreach(['translations','pdf_variables'] as $key){
|
||||
if (property_exists($settings, $key)) {
|
||||
unset($settings->{$key});
|
||||
}
|
||||
}
|
||||
|
||||
//18-07-2022 removed || empty($settings->{$key}) from this check to allow "0" values to persist
|
||||
foreach ($settings as $key => $value) {
|
||||
if (! isset($settings->{$key}) || (! is_object($settings->{$key}) && strlen($settings->{$key}) == 0)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user