Repository navigation
Expand file tree
/
Copy pathSecurityLog.php
More file actions
127 lines (114 loc) · 3.25 KB
/
Copy pathSecurityLog.php
File metadata and controls
127 lines (114 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace ProcessMaker\Models;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Traits\ExtendedPMQL;
/**
* Class SecurityLog
*
*
* @property Carbon $updated_at
* @property Carbon $created_at
*
* @OA\Schema(
* schema="securityLog",
* @OA\Property(property="id", type="integer"),
* @OA\Property(property="event", type="string"),
* @OA\Property(property="ip", type="string"),
* @OA\Property(property="meta", type="array",
* @OA\Items(type="object",
* @OA\Property(property="os", type="array",
* @OA\Items(type="object",
* @OA\Property(property="name", type="string"),
* @OA\Property(property="version", type="string"),
* ),
* ),
* @OA\Property(property="browser", type="array",
* @OA\Items(type="object",
* @OA\Property(property="name", type="string"),
* @OA\Property(property="version", type="string"),
* ),
* ),
* @OA\Property(property="user_agent", type="string"),
* ),
* ),
* @OA\Property(property="user_id", type="integer"),
* @OA\Property(property="occured_at", type="string"),
* ),
*/
class SecurityLog extends ProcessMakerModel
{
use ExtendedPMQL;
const CREATED_AT = 'occurred_at';
const UPDATED_AT = null;
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [
'id',
'occurred_at',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'data' => 'object',
'meta' => 'object',
];
/**
* Get the associated user, if any.
*/
public function user()
{
return $this->belongsTo('ProcessMaker\Models\User');
}
/**
* PMQL value alias for fulltext field
*
* @param string $value
*
* @return callable
*/
public function valueAliasFullText($value, $expression)
{
return function ($query) use ($value) {
$this->scopeFilter($query, $value);
};
}
/**
* Filter settings with a string
*
* @param $query
*
* @param $filter string
*/
public function scopeFilter($query, $filter)
{
$filter = '%' . mb_strtolower($filter) . '%';
$query->where(function ($query) use ($filter) {
$query->where(DB::raw('LOWER(`event`)'), 'like', $filter)
->orWhere(DB::raw('LOWER(`meta`)'), 'like', $filter)
->orWhere('ip', 'like', $filter);
});
return $query;
}
public static function rules()
{
return [
'event' => ['required', 'max:40'],
'ip' => ['required', 'max:40'],
'meta' => ['required', 'array'],
'meta.user_agent' => ['required', 'string'],
'meta.browser.name' => ['required', 'string'],
'meta.browser.version' => ['nullable', 'string'],
'meta.os.name' => ['required', 'string'],
'meta.os.version' => ['nullable', 'string'],
'user_id' => ['required', 'int'],
'occurred_at' => ['required', 'int'],
'data' => ['nullable', 'array'],
];
}
}