Skip to content

Commit

Permalink
log kayıtları
Browse files Browse the repository at this point in the history
  • Loading branch information
bulentsakarya committed Sep 11, 2023
1 parent 6fec49e commit 5a350b5
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 702 deletions.
44 changes: 0 additions & 44 deletions app/Http/Controllers/Activity/Activity.php

This file was deleted.

3 changes: 1 addition & 2 deletions app/Http/Controllers/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\View\View;
use Spatie\Activitylog\Models\Activity;


class Admin extends Controller
{
public function index(): View
{
$activities = Activity::limit('1');
$activities = '';
return view('admin', ['activities' => $activities]);
}

Expand Down
17 changes: 4 additions & 13 deletions app/Http/Controllers/Admin/AdminDetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ public function show(User $user): View

$rolePermissions = !empty($userCustomPermissions) ? array_merge($rolePermissions, $userCustomPermissions) : $rolePermissions;

$auth_activities = User::select('last_login_at', 'last_login_ip')->where('id', $user->id)->get();

return view('admins.detail', [
'user' => $user,
'basePermissions' => $basePermissions,
'rolePermissions' => $rolePermissions
'rolePermissions' => $rolePermissions,
'auth_activities' => $auth_activities
]);
}

Expand All @@ -61,8 +64,6 @@ public function show(User $user): View
*/
public function status(Request $request, User $user)
{
$ip = request()->ip();
$authuser = auth()->user()->name;

if ($request->ajax() && $request->has('ids')) {
foreach (UserStatus::cases() as $userStatus) {
Expand All @@ -74,8 +75,6 @@ public function status(Request $request, User $user)
$user->status = $status;
$user->save();

$statusname = UserStatus::getTitle($status);

return response()->json(['status' => 'success']);
}

Expand All @@ -90,8 +89,6 @@ public function status(Request $request, User $user)
*/
public function passwordReset(Request $request, User $user)
{
$ip = request()->ip();
$authuser = auth()->user()->name;

if ($request->ajax() && $request->has('user_id')) {
if($user->status == UserStatus::ACTIVE) {
Expand All @@ -118,9 +115,6 @@ public function passwordReset(Request $request, User $user)
public function changeEmail(Request $request, User $user)
{

$ip = request()->ip();
$authuser = auth()->user()->name;

if ($request->email !== $user->email && $user instanceof MustVerifyEmail) {
$user->email = $request->email;
$user->email_verified_at = null;
Expand All @@ -143,9 +137,6 @@ public function changeEmail(Request $request, User $user)
public function verifyEmail(Request $request, User $user)
{

$ip = request()->ip();
$authuser = auth()->user()->name;

if ($request->ajax() && $request->has('user_id')) {

$status = $user->sendEmailVerificationNotification();
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\View\View;
use Spatie\Activitylog\Models\Activity;

class Dashboard extends Controller
{
public function index(): View
{
$activities = Activity::limit('1');
$activities = '';
return view('index', compact('activities'));
}

Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/User/UserDetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
use Spatie\Activitylog\Models\Activity;

class UserDetailController extends Controller
{
Expand All @@ -43,7 +42,7 @@ public function show(User $user): View
$tags = Usertag::where('status', Status::ACTIVE)->get();
$selectedTag = $user->usertags->pluck('id')->toArray();
$userCustomPermissions = $user->getAllPermissions()->pluck('id')->toArray();
$activities = Activity::where('causer_id', $user->id)->get();
$auth_activities = User::select('last_login_at', 'last_login_ip')->where('id', $user->id)->get();

foreach ($user->roles as $key => $role) {
$permissions = Permission::withWhereHas('group', fn ($query) => $query->where('type', $role->type))->get();
Expand All @@ -63,7 +62,7 @@ public function show(User $user): View
'selectedTag' => $selectedTag,
'basePermissions' => $basePermissions,
'rolePermissions' => $rolePermissions,
'activities' => $activities
'auth_activities' => $auth_activities
]);
}

Expand Down
19 changes: 2 additions & 17 deletions app/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\Permission\Models\Permission as PermissionModel;
use App\Models\Permissiongroup;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class Permission extends PermissionModel
{
use HasFactory, LogsActivity;
use HasFactory, Loggable;

protected $table = 'permissions';

Expand All @@ -22,19 +20,6 @@ class Permission extends PermissionModel
'guard_name'
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ?auth()->user()->name : 'Super Admin';
$activity->description = __("permission.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['name', 'group_id', 'text']);
}

public function group()
{
return $this->belongsTo(Permissiongroup::class, 'group_id', 'id');
Expand Down
19 changes: 2 additions & 17 deletions app/Models/Permissiongroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
use Illuminate\Database\Eloquent\Model;
use App\Enums\UserType;
use App\Models\Permission;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class Permissiongroup extends Model
{
use HasFactory, LogsActivity;
use HasFactory, Loggable;

protected $table = 'permissiongroups';

Expand All @@ -26,19 +24,6 @@ class Permissiongroup extends Model
'type' => UserType::class
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ? auth()->user()->name : 'Super Admin';
$activity->description = __("permissiongroup.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['name', 'type', 'desc']);
}

public function permission()
{
return $this->hasMany(Permission::class, 'group_id', 'id');
Expand Down
19 changes: 2 additions & 17 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
use App\Enums\UserType;
use Spatie\Permission\Models\Role as RoleModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class Role extends RoleModel
{
use HasFactory, LogsActivity;
use HasFactory, Loggable;

protected $fillable = [
'name',
Expand All @@ -25,16 +22,4 @@ class Role extends RoleModel
'type' => UserType::class
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ? auth()->user()->name : 'Super Admin';
$activity->description = __("role.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['name', 'type', 'desc']);
}
}
18 changes: 2 additions & 16 deletions app/Models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class Settings extends Model
{
use HasFactory, LogsActivity;
use HasFactory, Loggable;

protected $table = 'settings';

Expand All @@ -24,16 +22,4 @@ class Settings extends Model
'updated_at' => 'datetime'
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ? auth()->user()->name : 'Super Admin';
$activity->description = __("role.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['key', 'value']);
}
}
20 changes: 2 additions & 18 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
use App\Enums\UserStatus;
use App\Enums\UserType;
use App\Models\Usertag;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable, TwoFactorAuthenticatable, HasRoles, LogsActivity;
use HasApiTokens, HasFactory, Notifiable, TwoFactorAuthenticatable, HasRoles;

/**
* The attributes that are mass assignable.
Expand Down Expand Up @@ -68,19 +65,6 @@ class User extends Authenticatable implements MustVerifyEmail
'settings' => 'array',
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ? auth()->user()->name : 'Super Admin';
$activity->description = __("user.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['type', 'status', 'name', 'email', 'email_verified_at', 'password', 'created_by', 'created_by_name', 'terms']);
}

public function usertags()
{
return $this->belongsToMany(Usertag::class)->withTimestamps();
Expand Down
20 changes: 2 additions & 18 deletions app/Models/Usertag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
use App\Enums\Status;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Models\Activity;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class Usertag extends Model
{
use HasFactory, LogsActivity;
use HasFactory, Loggable;

protected $table = 'usertags';

Expand All @@ -32,19 +29,6 @@ class Usertag extends Model
'status' => Status::class,
];

public function tapActivity(Activity $activity, string $eventName)
{
$authuser = !empty(auth()->user()->name) ? auth()->user()->name : 'Super Admin';
$activity->description = __("usertag.activity.message.{$eventName}", ['authuser' => $authuser]);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('admin')
->logOnly(['status', 'name', 'color', 'desc']);
}

public function users()
{
return $this->belongsToMany(User::class)->withTimestamps();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"haruncpi/laravel-user-activity": "^1.0",
"laravel/fortify": "^1.17",
"laravel/framework": "^10.8",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"opcodesio/log-viewer": "^2.4",
"spatie/laravel-activitylog": "^4.7",
"spatie/laravel-permission": "^5.10",
"torann/geoip": "^3.0"
},
Expand Down
Loading

0 comments on commit 5a350b5

Please sign in to comment.