Permessi per gli hook

This commit is contained in:
Thomas Zilio 2019-05-24 12:07:10 -07:00
parent c11e3c4e88
commit 271346f6aa
4 changed files with 50 additions and 5 deletions

View File

@ -87,11 +87,13 @@ switch (get('op')) {
$results = []; $results = [];
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
if ($hook->permission != '-') {
$results[] = [ $results[] = [
'id' => $hook->id, 'id' => $hook->id,
'name' => $hook->name, 'name' => $hook->name,
]; ];
} }
}
echo json_encode($results); echo json_encode($results);

View File

@ -64,6 +64,12 @@ if (Auth::check()) {
success: function(data) { success: function(data) {
hooks = JSON.parse(data); hooks = JSON.parse(data);
if (hooks.length == 0) {
$("#hooks-loading").hide();
$("#hooks-number").text(0);
$("#hooks-header").append(\'<span class="small">\' + globals.translations.hookNone + \'</small>\');
}
hooks.forEach(function(item, index){ hooks.forEach(function(item, index){
executeHook(item, hooks.length); executeHook(item, hooks.length);
}); });

View File

@ -5,6 +5,7 @@ namespace Models;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\CarbonInterval; use Carbon\CarbonInterval;
use Common\Model; use Common\Model;
use Illuminate\Database\Eloquent\Builder;
use Traits\StoreTrait; use Traits\StoreTrait;
class Hook extends Model class Hook extends Model
@ -13,9 +14,23 @@ class Hook extends Model
protected $table = 'zz_hooks'; protected $table = 'zz_hooks';
protected $appends = [
'permission',
];
protected $cached = null; protected $cached = null;
protected $use_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() public function getIsCachedAttribute()
{ {
if (!isset($this->use_cached)) { if (!isset($this->use_cached)) {
@ -81,4 +96,20 @@ class Hook extends Model
return $this->cached; 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);
});
}
} }

View File

@ -17,3 +17,9 @@ FROM co_contratti WHERE
(SELECT id FROM co_contratti contratti WHERE contratti.idcontratto_prev = co_contratti.id) IS NULL (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)) 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'; 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;