From 271346f6aa277f002312b4175769f9140dfb8943 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 24 May 2019 12:07:10 -0700 Subject: [PATCH] Permessi per gli hook --- ajax.php | 10 ++++++---- include/bottom.php | 8 +++++++- src/Models/Hook.php | 31 +++++++++++++++++++++++++++++++ update/2_4_10.sql | 6 ++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/ajax.php b/ajax.php index 6b906ecfb..88c554958 100644 --- a/ajax.php +++ b/ajax.php @@ -87,10 +87,12 @@ switch (get('op')) { $results = []; foreach ($hooks as $hook) { - $results[] = [ - 'id' => $hook->id, - 'name' => $hook->name, - ]; + if ($hook->permission != '-') { + $results[] = [ + 'id' => $hook->id, + 'name' => $hook->name, + ]; + } } echo json_encode($results); diff --git a/include/bottom.php b/include/bottom.php index cbcd94edf..19e978ad2 100644 --- a/include/bottom.php +++ b/include/bottom.php @@ -63,7 +63,13 @@ if (Auth::check()) { }, success: function(data) { hooks = JSON.parse(data); - + + if (hooks.length == 0) { + $("#hooks-loading").hide(); + $("#hooks-number").text(0); + $("#hooks-header").append(\'\' + globals.translations.hookNone + \'\'); + } + hooks.forEach(function(item, index){ executeHook(item, hooks.length); }); diff --git a/src/Models/Hook.php b/src/Models/Hook.php index d89c0952b..600cf3019 100644 --- a/src/Models/Hook.php +++ b/src/Models/Hook.php @@ -5,6 +5,7 @@ namespace Models; use Carbon\Carbon; use Carbon\CarbonInterval; use Common\Model; +use Illuminate\Database\Eloquent\Builder; use Traits\StoreTrait; class Hook extends Model @@ -13,9 +14,23 @@ class Hook extends Model protected $table = 'zz_hooks'; + protected $appends = [ + 'permission', + ]; + protected $cached = null; protected $use_cached = null; + /** + * Restituisce i permessi relativi all'account in utilizzo. + * + * @return string + */ + public function getPermissionAttribute() + { + return $this->module->permission; + } + public function getIsCachedAttribute() { if (!isset($this->use_cached)) { @@ -81,4 +96,20 @@ class Hook extends Model return $this->cached; } + + /* Relazioni Eloquent */ + + public function module() + { + return $this->belongsTo(Module::class, 'id_module'); + } + + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('enabled', function (Builder $builder) { + $builder->where('enabled', true); + }); + } } diff --git a/update/2_4_10.sql b/update/2_4_10.sql index c2307dfaf..3edeeeeb9 100644 --- a/update/2_4_10.sql +++ b/update/2_4_10.sql @@ -17,3 +17,9 @@ FROM co_contratti WHERE (SELECT id FROM co_contratti contratti WHERE contratti.idcontratto_prev = co_contratti.id) IS NULL HAVING (ore_rimanenti < ore_preavviso_rinnovo OR DATEDIFF(data_conclusione, NOW()) < ABS(giorni_preavviso_rinnovo)) ORDER BY giorni_rimanenti ASC, ore_rimanenti ASC' WHERE `zz_widgets`.`name` = 'Contratti in scadenza'; + +-- Miglioramento hooks +ALTER TABLE `zz_hooks` ADD `enabled` boolean NOT NULL DEFAULT 1, ADD `id_module` int(11) NOT NULL; +UPDATE `zz_hooks` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') WHERE `name` = 'Ricevute'; +UPDATE `zz_hooks` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di acquisto') WHERE `name` = 'Fatture'; +ALTER TABLE `zz_hooks` ADD FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE;